Capture RTP Live Stream Using Custom SDP in FFmpeg

Capturing a live stream over RTP (Real-time Transport Protocol) using FFmpeg often requires a Session Description Protocol (SDP) file to define the stream’s parameters, such as IP addresses, ports, and payload formats. Because RTP does not multiplex control and media data in the same way as protocols like RTMP or RTSP, FFmpeg needs this external SDP metadata to correctly decode the incoming packets. This guide provides a straightforward, step-by-step process for creating a custom SDP file and using FFmpeg to capture and save your live RTP stream.

Step 1: Create the Custom SDP File

An SDP file is a simple text file with the extension .sdp that describes the multimedia session. You must configure this file to match the properties of your incoming RTP stream.

Create a file named stream.sdp in your working directory and populate it with the following configuration (adjust the values to match your stream):

v=0
o=- 0 0 IN IP4 127.0.0.1
s=RTP Video Stream
c=IN IP4 239.0.0.1
t=0 0
m=video 5004 RTP/AVP 96
a=rtpmap:96 H264/90000

Key Fields Explained:

If your stream also contains audio (for example, AAC audio on port 5006), append the audio details to the same SDP file:

m=audio 5006 RTP/AVP 97
a=rtpmap:97 MPEG4-GENERIC/48000/2
a=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3;config=1190

Step 2: Run the FFmpeg Command

Once your stream.sdp file is configured and the RTP stream is actively broadcasting, run the following FFmpeg command in your terminal to capture and save the stream.

ffmpeg -protocol_whitelist file,udp,rtp -i stream.sdp -c copy output.mp4

Command Breakdown:

Troubleshooting Common Issues