How to Check RTMP Live stream is on or off

ITit superpower picture ITit superpower · Jul 16, 2015 · Viewed 10.6k times · Source

I want tocheck RTMP live stream is on or off for mic.

I have used RTMP DUMP

exec("/usr/bin/rtmpdump -V -v -r rtmp://www.exapmle.com/etc./13/mic1 -o /tmp/rtmp-checker.log 2>&1", $pp);

I have found this trick from http://blog.svnlabs.com/how-to-check-rtmp-source-stream-is-live-or-not/

But i am not Satisfy with result because some time its not working and generates random string as result.

So some time i am facing this type of error. any perfect solution for this.? IF YOU have any other solution Using FFMPEG OR OTHER then you are most welcome.

Answer

aergistal picture aergistal · Jul 16, 2015

You can use ffprobe:

ffprobe -v quiet -print_format json -show_streams rtmp://example.com/stream

You'll get a return code 1 if the command failed or 0 and a JSON string containing the detected streams on success:

{
    "index": 1,
    "codec_name": "aac",
    "codec_long_name": "AAC (Advanced Audio Coding)",
    "profile": "LC",
    "codec_type": "audio",
    ...
}

This is a basic test, if you want to go further than that you could download a few seconds of the stream, validate it with ffprobe, run silencedetect on it etc.