Search code examples
python-3.xffmpegstreamrtmpffprobe

RTMP stream monitoring in python


I don't have experience with python, but I found this online:
https://gist.github.com/sinkers/d647a80fdb180b4cc3a6
Assuming it works with the current version of ffmpeg (ffprobe), I tried to just modify the code a bit, so it doesn't log in to Amazon SNS to send a message. Just simply opening an audio file when the stream goes down, with the following command (I found it on this site) would do just fine:

os.system("start /sound/xyz.mp3")

I tried to do this-and-that, but I can't seem to succeed. I have 3.x installed.

I know it's probably silly, but do I need to enter the relative, or absolute file locations? For ffprobe and the sound file, is it C:\... or what's the correct format and path?

Any help to solve this would be greatly appreciated.


Solution

  • Update for the edited question:

    If you are on Windows you can do:

    import os
    os.startfile('C:/folder/sound.mp3')
    

    If you're not using Windows then take a look at this and this.

    Original answer

    To launch ffprobe you can do:

    retcode = os.system("/usr/local/bin/ffprobe rtmp://...") or

    retcode = os.system("/usr/local/bin/ffprobe /path/to/file")

    However, using os.system() won't help you capture the actual output of your command since it will fetch you only the return code (Eg: 0 if successfull).

    That's why the example script uses run() instead.

    If you want to validate RTMP streams you can also take a look at rtmpdump