Difference between revisions of "Stream Status"
From Starchive Wiki
(Created page with "= Stream Status = The Stream Status tool is comprised of a command that checks for stream silence and a PHP page that reports this for the uptime monitor. == Command == The c...") |
|||
Line 1: | Line 1: | ||
− | |||
The Stream Status tool is comprised of a command that checks for stream silence and a PHP page that reports this for the uptime monitor. | The Stream Status tool is comprised of a command that checks for stream silence and a PHP page that reports this for the uptime monitor. | ||
Line 5: | Line 4: | ||
The command is as follows: | The command is as follows: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | ffmpeg -i http://garfield.standrewsradio.com:8080/stream/1.mp3 -y -nostats -loglevel 0 -f mp3 -t 00:00. | + | ffmpeg -i http://garfield.standrewsradio.com:8080/stream/1.mp3 -y -nostats -loglevel 0 -f mp3 -t 00:00.5 - | sox -t mp3 - -n stat 2>&1 | grep "Maximum amplitude" | cut -d' ' -f 7 |
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 00:41, 22 February 2020
The Stream Status tool is comprised of a command that checks for stream silence and a PHP page that reports this for the uptime monitor.
Command
The command is as follows:
ffmpeg -i http://garfield.standrewsradio.com:8080/stream/1.mp3 -y -nostats -loglevel 0 -f mp3 -t 00:00.5 - | sox -t mp3 - -n stat 2>&1 | grep "Maximum amplitude" | cut -d' ' -f 7
This is split into four different parts, each operating on the output of the part before:
ffmpeg -i http://garfield.standrewsradio.com:8080/stream/1.mp3 -y -nostats -loglevel 0 -f mp3 -t 00:00.5 -
: silently records half a second of the stream as an mp3.sox -t mp3 - -n stat 2>&1
: using sox, read the MP3 recording and get some statistics on it, piping stderr and stdout into stdout.grep "Maximum amplitude"
: gets the line of the output that contains information about the maximum amplitude.cut -d' ' -f 7
: cuts the input into parts around spaces and returns the 7th part (this is the maximum amplitude in seconds).
PHP
The PHP script is as follows:
<?php
$output = exec("<the command>");
$val = floatval($output);
if ($val === 0.0) {
http_response_code(503);
} else {
echo "all good :)";
http_response_code(200);
}
This script simply gets the output of the command that is run and checks the value. If it is 0, it returns a server error response code for the uptime robot to detect.