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-i udp://@239.0.0.1:1234: Specifies the incoming UDP stream address (the@symbol is used for multicast addresses).-c copy: Copies the video and audio payloads directly without re-encoding.output1.mp4andoutput2.mkv: The two distinct output files.
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"-map 0: Selects all streams (video, audio, subtitles) from the input.-f tee: Invokes the tee muxer."output1.mp4|output2.ts": Specifies the output destinations, separated by a pipe (|) character.
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-f segment: Splits the output into multiple sequential files.-segment_time 600: Sets the segment duration in seconds (600 seconds = 10 minutes).-reset_timestamps 1: Resets timestamps at the beginning of each segment so that each individual file starts at 0:00.capture_%03d.mp4: The naming pattern for the output files, which will generatecapture_001.mp4,capture_002.mp4, and so on.