How to Stream UDP with RTP Encapsulation Using FFmpeg

This guide provides a straightforward tutorial on how to stream video and audio over UDP with RTP encapsulation using FFmpeg. You will learn the exact command-line syntax required, how to generate the essential Session Description Protocol (SDP) file needed for receivers to decode the stream, and how to play back the stream using a media player.

The FFmpeg Command for RTP Streaming

To stream a media file over UDP using RTP encapsulation, you must use the FFmpeg rtp muxer. Because RTP requires the receiver to know the stream configuration beforehand, you also need to output an SDP file.

Run the following command in your terminal:

ffmpeg -re -i input.mp4 -an -c:v libx264 -f rtp rtp://127.0.0.1:5004 > stream.sdp

Command Breakdown:


Streaming Video and Audio Together

If you want to stream both video and audio, RTP requires separate ports for each stream. FFmpeg handles this automatically by assigning the audio stream to the next available even port (e.g., if video is on 5004, audio will go to 5006).

Use this command for a combined audio and video stream:

ffmpeg -re -i input.mp4 -c:v libx264 -c:a aac -f rtp rtp://127.0.0.1:5004 > stream.sdp

How to Play the RTP Stream

Because RTP does not have an in-band handshake, the receiving player cannot decode the stream without the stream.sdp file generated by your FFmpeg command.

Option 1: Playing with VLC

  1. Copy the generated stream.sdp file to the receiving computer.
  2. Open VLC Media Player.
  3. Drag and drop the stream.sdp file into VLC, or open it via File > Open File. VLC will read the SDP file, connect to the specified UDP port, and begin playing the stream.

Option 2: Playing with FFplay

If you have FFmpeg installed on the receiving machine, you can play the stream directly from the command line using FFplay:

ffplay -protocol_whitelist file,rtp,udp stream.sdp