Continuous live stream capture

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Continuous live stream capture

FFmpeg-users mailing list
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


_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Continuous live stream capture

Bo Berglund
On Mon, 22 Mar 2021 13:03:01 +0000, adam smith via ffmpeg-user
<[hidden email]> wrote:

>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.
>
> <strip command lines>
>
>Thanks in advance for any advice.

Maybe not exactly what you need but...

I have a script that downloads the streaming video starting immediately and
running for a specific duration.
It is executed in an at job on Ubuntu and the at command looks like this:

timeout --signal=2 66m getmsnbcstreamyt 2021-03-25_input13.mp4
The job is created using this:

echo "timeout --signal=2 66m getmsnbcstreamyt 2021-03-25_input13.mp4" | at 17:59


So this process starts at the time set for the at command and ends after 66
minutes in this case.

The script getmsnbcstreamyt uses youtube-dl, which in turn uses ffmpeg.

If I start the script interactively I see lots of féedback from the download
progress and can break it using either Ctrl-C or q from the keyboard, in both
cases youtube-dl exits after finishing the output file by adding the moov atom
and changing the name by removing the .part ending.

Obviously I cannot send q to the process from within the at job so I use the
timeout function with the signal argument --signal=2
And this works just fine.

You could possibly run your script as is but package it inside a timeout call
such that ffmpeg is at least exiting after the timeout has expired?


--
Bo Berglund
Developer in Sweden

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Continuous live stream capture

FFmpeg-users mailing list


> On 25 Mar 2021, at 14:40, Bo Berglund <[hidden email]> wrote:
>
> So this process starts at the time set for the at command and ends after 66
> minutes in this case.

Thanks for the advice Bo.
I think is pretty much what I am doing, so its nice to have some confirmation that I am not alone in using a timed signal process.
The real win for me would be to allow continuous recording (using some kind of image as the base layer would be totally fine) even when the source stream is no longer sending data.

I will continue my searching :)

Thanks
Adam

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".