How to record UDP stream with FFMPEG in chunks?

user1394281 picture user1394281 · May 14, 2012 · Viewed 20.3k times · Source

I'm looking for a way to record a video UDP stream using ffmpeg but in 10mn chunks. I currently use the following to get 10mn of video (with h264 transcoding).

"ffmpeg -i udp://239.0.77.15:5000 -map 0:0 -map 0:1 -s 640x360 -vcodec libx264 -g 100 -vb 500000 -r 25 -strict experimental -vf yadif -acodec aac -ab 96000 -ac 2 -t 600 -y /media/test.m4 "

My problem is that using command line ffmpeg needs time to resync with the udp stream loosing 2 seconds of video each time. Is it normal ?

Any idea if there is a way to do it in command line or should I tried to use the ffmpeg API ?

Thanks in advance

Answer

user1394281 picture user1394281 · May 23, 2012

Ok found it.

Recently ffmpeg add a segmenter, here is the syntax:

-f segment: tell ffmpeg to use the segmenter

-segment_time: chunk size in second

You can use autoincrement file name with something like %03d (000,001,002,003...).

Here is my line to transcode a UDP MPEGTS stream, into H264+AAC and save it to file chunk (60 seconds):

ffmpeg -i udp://239.0.77.15:5000 -map 0:0 -map 0:1 -s 640x360 -vcodec libx264 -g 60 -vb 500000 -strict experimental -vf yadif -acodec aac -ab 96000 -ac 2 -y -f segment -segment_time 60 "xxx-%03d.ts"