How to record UDP stream with FFMPEG in chunks?

22,008

Solution 1

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"

Solution 2

This is a better way:

ffmpeg -re -i udp://10.1.1.238:1234?fifo_size=1000000 -vcodec libx264 -vb 500000 -g 60 -vprofile main -acodec aac -ab 128000 -ar 48000 -ac 2 -vbsf h264_mp4toannexb -b 1000k -minrate 1000k -maxrate 1000k -strict experimental -f stream_segment -segment_format mpegts -segment_time 5 -segment_atclocktime 1 -reset_timestamps 1 -strftime 1 d:/%H%M%S.mp4

By this code ffmpeg makes series of output files using current system time.

Share:
22,008
user1394281
Author by

user1394281

Updated on January 30, 2020

Comments

  • user1394281
    user1394281 over 4 years

    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