Created
September 14, 2017 03:37
-
-
Save whobutsb/ef93c88e77f2e3be891d640123e5f7ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Ffmpeg = require(‘fluent-ffmpeg’); | |
const STREAM_URL = ‘http://icecast.radio24.ch/radio24-rc-96-aac'; | |
const VOLUME_THRESHOLD = -50; // volume threshold | |
getMeanVolume(STREAM_URL, function(meanVolume){ | |
if(meanVolume <= VOLUME_THRESHOLD){ | |
console.log(“WE HAVE A PROBLEM! VOLUME IS TOO LOW!”); | |
}else{ | |
console.log(‘ALL GOOD!’); | |
} | |
}); | |
function getMeanVolume(streamUrl, callback){ | |
new Ffmpeg({ source: streamUrl }) | |
.withAudioFilter(‘volumedetect’) | |
.addOption(‘-f’, ‘null’) | |
.addOption(‘-t’, ‘10’) // duration | |
.noVideo() | |
.on(‘start’, function(ffmpegCommand){ | |
console.log(‘Output the ffmpeg command’, ffmpegCommand); | |
}) | |
.on(‘end’, function(stdout, stderr){ | |
// find the mean_volume in the output | |
let meanVolumeRegex = stderr.match(/mean_volume:\s(-?[0–9]\d*(\.\d+)?)/); | |
// return the mean volume | |
if(meanVolumeRegex){ | |
let meanVolume = parseFloat(meanVolumeRegex[1]); | |
return callback(meanVolume); | |
} | |
// if the stream is not available | |
if(stderr.match(/Server returned 404 Not Found/)){ | |
return callback(false); | |
} | |
}) | |
.saveToFile(‘/dev/null’); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Help!
I don't received an output. Just the first information:
node silent.js
Output the ffmpeg command ffmpeg -i http://192.168.188.59:8443/rapi.mp3 -y -filter:a volumedetect -vn -f null -t 2 /dev/null