Can I set a "wait-timeout" for ffmpeg to not abort a stream download?
Some live streams I download from are sometimes interrupted for a short time of 1-2 minutes and when I use ffmpeg for download it quits at these occurrences. Is there some way to enforce the "-t 3800 " argument so it really waits all that time if the video stops before aborting the download? Or else some other argument that can set an idle-timeout value to say 300 s or so, such that the video download is not aborted but instead just paused until the stream returns or when the -t argument has been reached? -- Bo Berglund Developer in Sweden
Some live streams I download from are sometimes interrupted for a short time of 1-2 minutes and when I use ffmpeg for download it quits at these occurrences.
Is there some way to enforce the "-t 3800 " argument so it really waits all that time if the video stops before aborting the download?
Or else some other argument that can set an idle-timeout value to say 300 s or so, such that the video download is not aborted but instead just paused until the stream returns or when the -t argument has been reached?
What protocol/URL are the streams you're using? I have the opposite problem, where data stops arriving and ffmpeg will sit there for hours doing nothing, when I want it to exit so I can detect the interruption in a script and restart it. I'm wondering whether you're using a TCP connection and it's the TCP connection that drops out. In my case it's both UDP and a local V4L2 device, and both those will sit there forever and then resume immediately if new data eventually arrives. Cheers, Adam.
On 11/14/2021 8:27 PM, Adam Nielsen via ffmpeg-user wrote:
What protocol/URL are the streams you're using?
That would be answered if the original post contained the complete command output... z!
On Mon, 15 Nov 2021 04:35:50 +0000, Carl Zwanzig <cpz@tuunq.com> wrote:
On 11/14/2021 8:27 PM, Adam Nielsen via ffmpeg-user wrote:
What protocol/URL are the streams you're using?
That would be answered if the original post contained the complete command output...
Here you go (even though I was asking for the existence of an ffmpeg argument to tell it to wait out the set -t time rather than aborting if there is a pause in the stream). Actual URL domains obfuscated. ffmpeg -hide_banner -referer "https://wwwwwwwww.com/yyyy.html" -i "https://xxxxxxxx.org/2fwljiCVp2jdxA63hnS-ng==,1636958338/LS-ATL-54548-10/ind..." -vf scale=w=-4:h=480 -c:v libx264 -preset fast -crf 26 -c:a copy -t 7680 input22.mp4 The referer and i arguments have been dug out of the webpage using another script (based on earlier advice here) and it works fine normally, but for the aborts that do not happen on every download. Only about every 3rd is affected. So the referer and i arguments are in essence OK. -- Bo Berglund Developer in Sweden
Here you go (even though I was asking for the existence of an ffmpeg argument to tell it to wait out the set -t time rather than aborting if there is a pause in the stream). Actual URL domains obfuscated.
ffmpeg -hide_banner -referer "https://wwwwwwwww.com/yyyy.html" -i "https://xxxxxxxx.org/2fwljiCVp2jdxA63hnS-ng==,1636958338/LS-ATL-54548-10/ind..."
Assuming the issue is that the TCP connection is terminated (due to a timeout, server disconnect, etc.) there won't be an ffmpeg option for this. Having ffmpeg wait until more data arrives is not applicable to a disconnected TCP connection, because it's like calling someone on the phone and they hang up. No matter how long you wait with the phone against your ear they will never just start speaking again, one of you has to make another call to get reconnected. Same thing here - ffmpeg exits when the "call" hangs up, because waiting would serve no point - the TCP connection has already been terminated, so no data will ever pass again across that connection, so there's nothing to wait for. Your best bet is probably going to be scripting it, so that when it terminates, the script runs ffmpeg again to re-establish a new connection to the server. You may also want to investigate why the connections are getting dropped, however depending on how important the streaming is, even a perfect system will occasionally drop TCP connections so being able to handle that happening will make your set up much more robust. Cheers, Adam.
On Mon, 15 Nov 2021 20:18:53 +1000, Adam Nielsen via ffmpeg-user <ffmpeg-user@ffmpeg.org> wrote:
Your best bet is probably going to be scripting it, so that when it terminates, the script runs ffmpeg again to re-establish a new connection to the server.
OK, I can then probably run the script that extracts the m3u8 URL repeatedly until it succeeds and then run the original command again with the possibly modified m3u8 URL (it is read from file). One way the problem may occur is that the m3u8 URL becomes invalid, and then I need a new one obviously. On a new invocation I will have to adjust the -t argument to handle the time until the original stop was supposed to be done of course. Maybe I should modify my script to use the end time in hh:mm:ss notation rather than the number of seconds of video length as the time parameter... Then convert internally to the duration. I need something that can convert back and forth between time in seconds and time as hh:mm:ss too. Is there a readymade function that can add/subtract time in hh:mm:ss format and return the same format? I think ffmpeg can actually handle -t hh:mm:ss in addition to -t sss Question: --------- Can I somehow specify to ffmpeg that it should *append* the new data to the already downloaded first part? Or do I have to get this new bit separately and then paste them together?
You may also want to investigate why the connections are getting dropped, however depending on how important the streaming is, even a perfect system will occasionally drop TCP connections so being able to handle that happening will make your set up much more robust.
I have seen while watching live on the source webpage that it sometimes towards the top of the hour seems to black out the player for a while and then resume. It could take anywhere from 10 seconds to a couple of minutes when it happens. The aborted recording does not have any of that it just suddenly ends. Don't know what this is all about, but I don't think it is some network problem at least not here (I am on a rock solid 250/100 Mbps fiber connection). Possibly the streaming site has some such problem.... -- Bo Berglund Developer in Sweden
On a new invocation I will have to adjust the -t argument to handle the time until the original stop was supposed to be done of course.
If you're using "at" as you have suggested in your other message, possibly you could just write the FFmpeg PID to a file and have "at" send a TERM signal at the specified time. That way you'd only need one calculation, or possibly none if you can specify the duration as a start and end time. Just be careful of the edge case where it's in the process of restarting right when the end time arrives, so there's nothing to terminate and then the stream resumes.
Is there a readymade function that can add/subtract time in hh:mm:ss format and return the same format? I think ffmpeg can actually handle -t hh:mm:ss in addition to -t sss
"date" can do a limited bit of maths but not sure if it will cover your use case: date -d "now + 30 mins"
Can I somehow specify to ffmpeg that it should *append* the new data to the already downloaded first part? Or do I have to get this new bit separately and then paste them together?
ffmpeg doesn't append, it takes in whole files and writes whole files. You'd have to merge them after the fact. You could possibly work around the issue but I'm not sure it's worth it. One workaround would be to have your ffmpeg instance stream the transcoded data to a localhost UDP socket instead of a file ("-f rtp_mpegts udp://localhost:1234"). Then you could run a second ffmpeg instance that reads data from the UDP socket and writes it to your file. Since this second instance is listening on UDP, it won't terminate when the first ffmpeg gets cut off, so when the first one restarts and resumes sending the UDP data, the second one will keep going, effectively "appending" the data. But now you have to deal with two ffmpeg instances per recording, one of which may randomly restart, and you might have to mess around with which of the two instances does the actual encoding depending on what codecs rtp_mpegts is able to send over the UDP socket.
I have seen while watching live on the source webpage that it sometimes towards the top of the hour seems to black out the player for a while and then resume. It could take anywhere from 10 seconds to a couple of minutes when it happens.
The aborted recording does not have any of that it just suddenly ends.
You'll probably find the web player just blanks out the video while it's trying to reconnect. You might be able to get ffmpeg to do the same with one of the -vsync options, but then having minute long black sections in the output video might not be great for playback.
I don't really understand why I would need to collect the "complete output" since I am not asking about *how or why* ffmpeg failed, what I asked is if there is an argument to ffmpeg, which will force the -t video time to be observed intstead of ffmpeg aborting when the stream pauses its streaming.
To understand why this was asked, have a read of "Pounding A Nail: Old Shoe or Glass Bottle": https://weblogs.asp.net/alex_papadimoulis/408925 I know sometimes you just want an answer to your immediate problem, but so often the issues people have would be better solved by tackling it a different way. Not having all the information about the problem means often time gets wasted trying to solve the wrong issue. In your case we could've spent ages trying to investigate ways to keep ffmpeg alive, when it turned out that the lost TCP connection meant keeping ffmpeg alive would not have helped solve the problem, and any attempts to try to do so would have been wasted effort. This is why everyone is eager to fully understand what you are trying to achieve, so they can offer the best solution. Yes, the information might seem irrelevant to you, but many a time someone will spot something you weren't even aware of so it's always worth giving the whole story when asking for help. And yes, speaking from experience sometimes this results in solutions you don't want, but that's better than an answer that does exactly what you asked for but still doesn't fix the problem!
I cannot dig out such information anyway since it is hidden below several levels of at command handling and scripts calling other scripts. It all happens in an at job container...
Sounds like you need to improve your logging :-P Cheers, Adam.
On Tue, 16 Nov 2021 13:51:58 +1000, Adam Nielsen via ffmpeg-user <ffmpeg-user@ffmpeg.org> wrote:
Sounds like you need to improve your logging :-P
Well, when the download script runs in a user terminal there is constant output to stdout from *ffmpeg*. But that is not visible when I run it in an at job since it has no terminal (at least not visible). And I have no say over what ffmpeg is logging or where, right? So where do I find the output of the at job which ran a few hours back? I have tried (after googling) the following locations but no dice: /var/spool/cron/atspool/ /var/spool/cron/atjobs/ Since the output is a *lot* when run in a terminal I assume Ubuntu will not keep all of it, at least not for very long, even if it is saved somewhere... -- Bo Berglund Developer in Sweden
On Tue, 16 Nov 2021 at 09:52, Bo Berglund <bo.berglund@gmail.com> wrote:
On Tue, 16 Nov 2021 13:51:58 +1000, Adam Nielsen via ffmpeg-user <ffmpeg-user@ffmpeg.org> wrote:
Sounds like you need to improve your logging :-P And I have no say over what ffmpeg is logging or where, right?
You do. You can use `-report'; see http://ffmpeg.org/ffmpeg.html#toc-Generic-options under '-report':
Dump full command line and log output to a file named program-YYYYMMDD-HHMMSS.log in the current directory. This file can be useful for bug reports. It also implies -loglevel debug.
You can also use output redirection. Since you're using Ubuntu, there's a very nice summary over at AskUbuntu: https://askubuntu.com/a/731237 Either of these -- -report or output redirection -- can be used as part of your ffmpeg invocation with `at'. As a side note, task schedulers like cron/at/etc can and sometimes do try to handle output- on some systems, cron used to generate an email to the user if there was output on stderr. Nowadays in a systemd context, it might be captured and available as part of the journal via `journalctl'. But if you're interested in ffmpeg's information output -- and you should be! -- then explicitly choosing where to save it is a good idea. Cheers, Rob
On Mon, 15 Nov 2021 04:35:50 +0000, Carl Zwanzig <cpz@tuunq.com> wrote:
On 11/14/2021 10:56 PM, Bo Berglund wrote:
That would be answered if the original post contained the complete command output...
Here you go (even though I was asking for the existence of an ffmpeg argument to tell it to wait out the set -t time rather than aborting if there is a pause in the stream).
ffmpeg -hide_banner -referer"https://wwwwwwwww.com/yyyy.html" -i "https://xxxxxxxx.org/2fwljiCVp2jdxA63hnS-ng==,1636958338/LS-ATL-54548-10/ind..." -vf scale=w=-4:h=480 -c:v libx264 -preset fast -crf 26 -c:a copy -t 7680 input22.mp4
Although it answers the tcp/udp question, that's the -command-, not the complete output. Please read the list FAQ- https://ffmpeg.org/mailing-list-faq.html
I don't really understand why I would need to collect the "complete output" since I am not asking about *how or why* ffmpeg failed, what I asked is if there is an argument to ffmpeg, which will force the -t video time to be observed intstead of ffmpeg aborting when the stream pauses its streaming. I cannot dig out such information anyway since it is hidden below several levels of at command handling and scripts calling other scripts. It all happens in an at job container... But I think I have received a valid answer, which was "no". <== Good enough! So ffmpeg cannot do it. I will now have to go from there and tighten up the core script so it will itself check what is the cause of the ffmpeg stop if it stops too early. And then relaunch itself with a different -t value and possibly also a new m3u8 URL, when such reappears. In fact I do have this in some scripts, but it is a 1-level thing only and it works only if the stream is back in 60 seconds using the same URL. Just a delay and a re-launch of ffmpeg. Now I need to do a while loop waiting for the stream to re-appear and check the URL too. -- Bo Berglund Developer in Sweden
participants (4)
-
Adam Nielsen -
Bo Berglund -
Carl Zwanzig -
Rob Hallam