1

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.

lasgun
  • 13
  • 1
  • 5
  • Your question is not very clear. Do you want to ffprobe a RTMP stream, a file or open a file? Maybe you can rephrase it a bit. – aergistal Mar 18 '15 at 09:59
  • Hi! It is a live stream I'd like to monitor. If I understand correctly, the script would check at given intervals if the stream is available or not. The stream is in the following format: _rtmp://123.123.123.123:1935/live/xyz.stream and _http://123.123.123.123:1935/live/xyz.stream/playlist.m3u8 If the stream becomes unavailable, an audio file should start playing. That's what I was trying to say. – lasgun Mar 18 '15 at 10:04

1 Answers1

0

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

Community
  • 1
  • 1
aergistal
  • 29,947
  • 5
  • 70
  • 92
  • I've already looked at rtmpdump, but since I am very inexperienced, I can't do much with it, I don't know how to write anything to alert me if the stream goes down. That's why I thought of modifying the script in my original post. I just need it to play an alert if the stream goes offline. Even if I delete the "from boto import boto" and add the soundfile opening command after the else in the cycle, it doesn't work. – lasgun Mar 18 '15 at 11:30
  • I am using Windows 7 64 bit version. I ran the command in a blank .py file, and it worked fine. However, if I just add it to the else branch of the cycle, I am getting errors. http://pastebin.com/eQXe2N12 Thanks for your help by the way, I feel like I'm getting closer, but I can't write a whole new thing, I only know some very-very basic things in C++. – lasgun Mar 18 '15 at 12:30
  • The error is not related to your code. Chances are that you're using Python 3.x to execute your script and the file was written for Python 2.x. See [this post](http://stackoverflow.com/questions/5471158/typeerror-str-does-not-support-the-buffer-interface) for the related error. Or try with Python 2.x. – aergistal Mar 18 '15 at 12:50
  • 1
    Thank You very much for you help, and your patience! It seems to be doing it's job, if I set only the http://....m3u8 stream for monitoring. If I set the rtmp one, It often gets some header error, and triggers the alarm, even if the stream is seemingly fine. I tested with disabling the wifi connection, so it obviously lost the stream. I will keep it running, and see if it works when there is a real outage. Thanks again! – lasgun Mar 18 '15 at 13:34
  • You're welcome! You could try to add `-analyzeduration n`, where **n** is a value in seconds to your `ffprobe` command. – aergistal Mar 18 '15 at 14:39
  • I'll give it a try tomorrow. Do you think it would solve the problem of some of these errors? 2015-03-18 15:39:09,486 [h264 @ 0000000002c4b2c0] non-existing PPS 0 referenced2015-03-18 15:39:09,490 Last message repeated 1 times 2015-03-18 15:39:09,496 [h264 @ 0000000002c4b2c0] decode_slice_header error One of these, and the alert goes off, even though the stream is coming through. (It only happened once yet.) I was thinking of counting consecutive errors, and modify the cycle so it only alerts me if the counter variable reaches ~5. – lasgun Mar 18 '15 at 16:38
  • If you start the stream and no keyframe was sent yet `ffprobe` will complain like you noticed. Once a keyframe is received the stream will stabilize. You need to tweak a bit the script taking that into account as it's pretty basic. – aergistal Mar 19 '15 at 08:59
  • 1
    I see. Hopefully I solved it by deleting the part of code that triggered the alert if "error" was in the text. If the stream is lost, it logs something different, and it still triggers the alert, so all is good now, it seems to work fine without errors and false alarms. – lasgun Mar 20 '15 at 11:32