Stream Media Over RTP with FFmpeg

This guide provides a straightforward tutorial on how to stream audio and video media over the Real-time Transport Protocol (RTP) using FFmpeg. You will learn the essential command-line configurations, how to stream video and audio components, and how to generate the required Session Description Protocol (SDP) file so that media players can successfully receive and decode your stream.

Basic RTP Video Streaming

To stream a video file over RTP, you must instruct FFmpeg to read the input file in real-time and output it to a specific destination IP address and port using the RTP format.

Run the following command to stream only the video portion of a file:

ffmpeg -re -i input.mp4 -an -vcodec libx264 -f rtp rtp://127.0.0.1:5004

Streaming Audio and Video Together

RTP requires separate ports for audio and video streams. When you stream both, FFmpeg will output the configuration details needed by the receiver.

To stream both audio and video, use this command:

ffmpeg -re -i input.mp4 -vcodec libx264 -acodec aac -f rtp rtp://127.0.0.1:5004 > stream.sdp

By redirecting the output to stream.sdp, FFmpeg automatically writes the session details to a file named stream.sdp. The receiver needs this file to understand how to bind the separate audio and video tracks.

How to Receive and Play the RTP Stream

Because RTP does not contain metadata describing the stream contents, the receiving player (such as VLC Media Player) cannot play the stream using the URL alone. It requires the SDP file generated by FFmpeg.

  1. Locate the stream.sdp file generated by your FFmpeg command.
  2. Transfer this file to the receiving machine if it is different from the streaming source.
  3. Open the stream.sdp file with a compatible media player like VLC:
vlc stream.sdp

The player will read the parameters inside the SDP file, connect to the specified ports, and begin playing the live stream.