如何检查RTMP Live流是打开还是关闭

ITi*_*wer 5 php ffmpeg rtmp

我希望tocheck RTMP直播开启或关闭麦克风.

我使用过RTMP DUMP

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

我从http://blog.svnlabs.com/how-to-check-rtmp-source-stream-is-live-or-not/找到了这个技巧.

但我不满足于结果,因为有些时候它不起作用并产生随机字符串作为结果.

所以有一段时间我面临这种类型的错误. 任何完美的解决方案.? 如果您有任何其他解决方案使用FFMPEG或OTHER,那么非常欢迎您.

aer*_*tal 9

你可以使用ffprobe:

ffprobe -v quiet -print_format json -show_streams rtmp://example.com/stream
Run Code Online (Sandbox Code Playgroud)

1如果命令失败,您将获得返回码,或者0在成功时获得包含检测到的流的JSON字符串:

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

这是一个基本测试,如果你想要进一步下载,你可以下载几秒的流,验证它ffprobe,运行silencedetect它等.