Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to record UDP stream with FFMPEG in chunks?

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

like image 502
user1394281 Avatar asked May 14 '12 17:05

user1394281


2 Answers

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"

like image 116
user1394281 Avatar answered Oct 05 '22 07:10

user1394281


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.

like image 41
alireza akbaribayat Avatar answered Oct 05 '22 06:10

alireza akbaribayat