How to check live stream is still alive use "ffprobe" command? - ffmpeg

I want to schedule a job script to check a live stream is still alive use "ffprobe" command. So that I can change database state for those steam already dead.
I tried the command:
ffprobe -v quiet -print_format json -show_streams rtmp://xxxx
but when the stream is not avaiable, the command will hang.
I tried add -timeout argument, but still cannot work properly.

The timeout option seems to be for listen mode. I would try to run ffmpeg using the timeout command or use something similar for the framework/language your using.
So for example:
timeout 10s ffprobe -v quiet ...
And maybe even use --kill-after. And then look at the exit code to determinate what happened.

Related

Am I missing a timeout param in FFMPEG?

I'm running an ffmpeg command like this:
ffmpeg -loglevel quiet -report -timelimit 15 -timeout 10 -protocol_whitelist file,http,https,tcp,tls,crypto -i ${inputFile} -vframes 1 ${outputFile} -y
This is running in an AWS Lambda function. My Lambda timeout is at 30 seconds. For some reason I am getting "Task timed out" messages still. I should note I log before and after the command, so I know it's timing out during this task.
Update
In terms of the entire lambda execution I do the following:
Invoke a lambda to get an access token. This lambda makes on API request. It has a timeout of 5 seconds. The max time was 660MS for one request.
Make another API request to verify data. The max time was 1.6 seconds.
Run FFMPEG
timelimit is supposed to Exit after ffmpeg has been running for duration seconds in CPU user time.. Theoretically this shouldn't run more than 15 seconds then, plus maybe 2-3 more before the other requests.
timeout is probably superfluous here. There were a lot of definitions for it in the manual, but I think that was mainly waiting on input? Either way, I'd think timelimit would cover my bases.
Update 2
I checked my debug log and saw this:
Reading option '-timelimit' ... matched as option 'timelimit' (set max runtime in seconds) with argument '15'.
Reading option '-timeout' ... matched as AVOption 'timeout' with argument '10'.
Seems both options are supported by my build
Update 2
I have updated my code with a lot of logs. I definitively see the FFMPEG command as the last thing that executes, before stalling out for the 30 second timeout
Update 3
I can reproduce the behavior by pointing at a track instead of full manifest. I have set the command to this:
ffmpeg -loglevel debug -timelimit 5 -timeout 5 -i 'https://streamprod-eastus-streamprodeastus-usea.streaming.media.azure.net/0c495135-95fa-48ec-a258-4ba40262e1be/23ab167b-9fec-439e-b447-d355ff5705df.ism/QualityLevels(200000)/Manifest(video,format=m3u8-aapl)' -vframes 1 temp.jpg -y
A few things here:
I typically point at the actual manifest (not the track), and things usually run much faster
I have lowered the timelimit and timeout to 5. Despite this, when i run a timer, the command runs for ~15 seconds every time. It outputs a bunch of errors, likely due to this being track rather than full manifest, and then spits out the desired image.
The full output is at https://gist.github.com/DaveStein/b3803f925d64dd96cd45ae9db5e5a4d0
timelimit is supposed to Exit after FFmpeg has been running for duration seconds in CPU user time.
This is true but you can't use this timing metric to determine when FFmpeg should be forcefully exited during its operation (See here).
Best to watch the process from outside and force kill it by sending a TERM or KILL signal.
I'd recommend the timeout command that's part of the GNU coreutils.
Here's an example
timeout 14s -t 1s <FFMPEG COMMAND LINE>
This would ensure that the FFmpeg command execution runs for as long as 14 seconds and forces it to be killed (SIGKILL) one second after that in case it didn't quit with the SIGTERM signal.
You can check the man pages for the timeout command.
you can try these things:
increase the timeout-limit of your lambda function.
increase the memory allocation to your lambda function. It speeds up your lambda function.
If you still gets timeout than check RequestTimeout and ConnectionTimeout of your lambda function.

Recording from online stream and listening to it at the same time (ffmpeg / ffplay)

Sometimes I like to record programmes from online radio channels, live or archived streams too. When there is no interesting actual programmes in the radios, I also would like listening to it at the same time while recording. I am using such command lines, which is called from Ruby script - to help parsing radios' timetables / programme pages and constructing the proper URLs of archived programmes which usually contains some timecode, such as 20160616_083000.mp3, etc.
So my command line to call from Ruby script looks like:
programmes.each{|datepart,programme_length|
cmd=%Q{ffmpeg -y -i http://example.com/stream/#{datepart}.mp3 -t #{programme_length} -c:a libmp3lame -b:a 160k "#{fname}" -c copy -t #{programme_length} -f mp3 -f rtp rtp://127.0.0.1:8888}
system cmd
}
It resides in a loop to record the previously parsed and selected programmes. Of cource the programmes are recorded properly and at the same time ffmpeg streams it as an mp3 rtp stream as well on localhost at the given port. In another terminal window I connect to the streamed data with one-liner as follows:
while true; do ffplay -i rtp://127.0.0.1:8888 -autoexit; done
I am using the -autoexit switch which should be stop playing the stream when it is ended and the "while" loop should be connect again to the new stream which is served by the programme recording "each" loop. Unfortunately it keeps playing after the end, and doesn't initiate a new connection to the newly started stream. How to use ffplay properly to stop playing after rtp stream is ended and let it connect again to the new stream?

Dealing with 302 Redirection in FFMPEG

I am using FFMPEG Library to Stream Audio from RTSP URL. My Sample Streaming URL is:
rtsp://username:password#machine-ip/708314c4eba2a041
And I am using the following command for streaming this RTSP URL:
ffmpeg -i RTSP_URL -f mov C:\FFMPEG_Recordings\bay.mov
So, the above FFMPEG command will capture the media stream from RTSP_URL and will store in bay.mov media file.
Sometimes, I get 302 Redirection Error from the Server which is actually propagating streams. Such as:
[rtsp # 0000000002cc8100] Status 302: Redirecting to rtsp://server-ip:server-port/708314c4eba2a041?token=708114c4e99dbcd1^LA^0^0^0^1427248150^e77149b2a2c209982a74367d0f72c2e11ba6636c
And after this process gets stuck (on Command Prompt) until I press CTRL+C twicely to terminate it in cmd where I run this command.
While It should start streaming from the redirected URL automatically.
I read that It's a FFMPEG's bug on FFMPEG Track and also read about it on FFMPEG Discussion Community but didn't get any solution or workaround for this.
Please guide to overcome this scenario If anyone ever encountered it that what are workarounds for this. Thnaks

Bash writing output to file with using timeout results in error

Im using this script to monitor iBeacon bluetooth devices and it works as expected.
sudo beacon scan -c
However i recently changed it to just run for a few seconds and output the result to a file like so:
sudo timeout 5 beacon scan -c > result.txt
Problem is that this outputs nothing to there is probably an error in the command. Also writing error stream to the file gives me an error.
sudo timeout 5 beacon scan -c &> result.txt
Contents of result.txt:
Set scan parameters failed: Input/output error
It feels like bash is trying to apply &> result.txt as parameters to the beacon scan command. Im not very good at bash so there is probably a simple solution to this problem but i haven't found one!
Some programs designed to be interrupted with ctrl-c don't behave the same when terminated with sigterm, which is what timeout will send by default. Try using the option -s INT to have timeout send sigint instead.

Running mpg123 with FIFO control?

I need to run mpg123 with a single file, such that it will autostart and autoclose, like it normally does, however, I need to be able to override this default behavior with commands sent to a fifo file.
I had been running mpg123 filename.mp3 from a script, and simply waiting for it to finish before moving on. However, I'd like another script to be able to pause playback, control volume, or kill the process early, depending on the user's input.
mpg123 -R --fifo /srv/http/newsctl filename.mp3 seems to start mpg123 and create the pipe, but does not start playback.
How do I make this work?
Unfortunately mpg123 is unable to play a specified file when -R argument is used.
To start the playback you have to load a file using created fifo.
FIFO_MPG='/srv/http/newsctl'
mpg123 -R --fifo "$FIFO_MPG"
echo 'load filename.mp3' >> "$FIFO_MPG"
Also I suggest you to silence verbose output by using
echo 'silence' >> "$FIFO_MPG"
I hope it is not too late. Good luck! ;)

Resources