Record UDP Stream to Multiple Files with FFmpeg

This article provides a straightforward guide on how to use FFmpeg to capture an incoming UDP network stream and write it to multiple output files simultaneously. You will learn how to duplicate the stream to different formats or locations at the same time, as well as how to split a continuous stream into sequential, time-based file segments.

Method 1: Simultaneous Output Using Multiple Arguments

The simplest way to output a UDP stream to multiple files is by defining multiple output paths at the end of your FFmpeg command. By using -c copy (stream copying), you duplicate the stream without re-encoding, which keeps CPU usage to a absolute minimum.

ffmpeg -i udp://@239.0.0.1:1234 -c copy output1.mp4 -c copy output2.mkv

Method 2: Efficient Duplication Using the Tee Muxer

If you are writing to multiple files of the same or similar container formats, using FFmpeg’s built-in tee muxer is more efficient. It processes the input stream once and writes the resulting packets to multiple outputs simultaneously.

ffmpeg -i udp://@239.0.0.1:1234 -map 0 -c copy -f tee "output1.mp4|output2.ts"

Method 3: Splitting the Stream into Sequential Files (Segmenting)

If your goal is to record a continuous UDP stream and automatically split it into multiple consecutive files based on time (e.g., creating a new file every 10 minutes), you should use the segment muxer.

ffmpeg -i udp://@239.0.0.1:1234 -c copy -f segment -segment_time 600 -reset_timestamps 1 capture_%03d.mp4