[FFmpeg-user] Continuous live stream capture

adam smith adamsmith79 at icloud.com
Mon Mar 22 15:03:01 EET 2021


Hi group, hope everyone is good,

I am trying to capture an srt stream using ffmpeg as a caller and everything is going well, just a couple of edge cases I would like to resolve that I think are related.

I would like the capture to continue even if the source stream is unavailable for a time. I don’t mean just keep the connection open and reconnect. I need the timing to remain constant, so the output should have gaps in it where the source was unavailable.

I have tried using lavfi -i color=color=blue:size=1920x1080 as an input and then overlaying the SRT stream. But ffmpeg will wait for the stream data to arrive before starting and will pause if the stream becomes unavailable, continuing when the SRT is available again. Basically the same behaviour as without the colour input.

The other issue (which will probably go away if the first issue is resolved, is stopping it :)
I was setting a record duration using the -t option, but removed it as with current behaviour the duration may never be reached and it will hang around forever waiting for the stream to come back and finish.
The new plan was to use a terminator script outside of ffmpeg that waits until a set time and then sends the pid.kill.

The terminator works great when the source stream is still active so I can dynamically update the end time; but if the source stream has already stopped, ffmpeg will continue to hang as it needs another pid.kill to stop, which in turn stops it from muxing the mp4 output.
I have a sort of workaround for this where the mp4 is written as a fragmented mp4 and so doesn’t need the mux stage, but I would prefer to stop it nicely so that I can use other output formats if I want.

Latest command used is below.
It includes the colour input and overlay which is not acting in the way that I wanted.
It includes the fragmented mp4 flags which are showing me love but I would prefer not to need.
I can include a console output if helps but there is no actual error, its just me not knowing how to achieve what I want ;)
Please ignore the audio filter, I know it could be simpler but this is automated and is set up to cope with random inputs so follows a pattern.
Please ignore the Tee Muxer, again that is automated and is used because there can be more than one output destination for each.
 
ffmpeg -y -f lavfi -i color=color=blue:size=1920x1080 -i "srt://xx.xxx.xxx.xx:xxxx?pkt_size=1316&mode=caller&latency=2000000"  -filter_complex "[0:0][1:0]overlay[vout],[vout]split=3[vout1][vout2][image];\
[1:1]channelsplit=channel_layout=stereo:channels=FL|FR[01_channelsplit][02_channelsplit];\
[01_channelsplit]asplit=4[01_asplit][03_asplit][05_asplit][07_asplit];\
[02_channelsplit]asplit=4[02_asplit][04_asplit][06_asplit][08_asplit];\
[01_asplit][02_asplit]amerge=inputs=2[01_merger];[03_asplit][04_asplit]amerge=inputs=2[02_merger];\
[05_asplit][06_asplit]amerge=inputs=2[03_merger];[07_asplit][08_asplit]amerge=inputs=2[04_merger];\
[01_merger]asplit=2[01_merger_aout1][01_merger_aout2];\
[02_merger]asplit=2[02_merger_aout1][02_merger_aout2];\
[03_merger]asplit=2[03_merger_aout1][03_merger_aout2];\
[04_merger]asplit=2[04_merger_aout1][04_merger_aout2]" -map "[vout1]"  -map "[01_merger_aout1]" -map "[02_merger_aout1]" -map "[03_merger_aout1]" -map "[04_merger_aout1]" -pix_fmt yuv420p -c:v libx264 -s 1920x1080 -preset ultrafast -b:v 15000k -r 25.0 -ac 2 -bsf:a aac_adtstoasc -c:a libfdk_aac -ar 48000 -b:a 192k -flags +global_header -f tee "[f=mp4:movflags=+frag_keyframe+separate_moof+omit_tfhd_offset+empty_moov]/data/disposable/inx_dou_ch01a_2021-03-20T0355_2021-03-20T0655_hires.mp4" -map "[vout2]"  -map "[01_merger_aout2]" -map "[02_merger_aout2]" -map "[03_merger_aout2]" -map "[04_merger_aout2]" -pix_fmt yuv420p -c:v libx264 -s 640x360 -preset ultrafast -b:v 2272k -r 25.0 -ac 2 -bsf:a aac_adtstoasc -c:a libfdk_aac -ar 44100 -b:a 64k -flags +global_header -f tee "[f=mp4:movflags=+frag_keyframe+separate_moof+omit_tfhd_offset+empty_moov]/data/disposable/inx_dou_ch01a_2021-03-20T0355_2021-03-20T0655_proxy.mp4" \
-map "[image]" -r 0.5 -s 283x159 -pix_fmt yuvj420p -c:v mjpeg -update 1 /data/disposable/a255ab2e-75db-50c1-a3d7-e9ed2727ecfa.jpeg



Thanks in advance for any advice.

Adam




More information about the ffmpeg-user mailing list