Created
September 14, 2017 03:37
-
-
Save whobutsb/ef93c88e77f2e3be891d640123e5f7ba to your computer and use it in GitHub Desktop.
This file contains 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’); | |
} |
@etimoteo It should be :
const Ffmpeg = require('fluent-ffmpeg');
const STREAM_URL = 'http://icecast.radio24.ch/radio24-rc-96-aac';
const VOLUME_THRESHOLD = -50; // volume threshold
function getMeanVolume(streamUrl, callback) {
new Ffmpeg({ source: streamUrl })
.withAudioFilter('volumedetect')
.addOption('-f', 'null')
.addOption('-t', '10') // duration
.noVideo()
.on('start', (ffmpegCommand) => {
console.log('Output the ffmpeg command', ffmpegCommand);
})
.on('end', (stdout, stderr) => {
// find the mean_volume in the output
const meanVolumeRegex = stderr.match(/mean_volume:\s(-?[0–9]\d*(\.\d+)?)/);
// return the mean volume
if (meanVolumeRegex) {
const 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');
}
getMeanVolume(STREAM_URL, (meanVolume) => {
if (meanVolume <= VOLUME_THRESHOLD) {
console.log('WE HAVE A PROBLEM! VOLUME IS TOO LOW!');
} else {
console.log('ALL GOOD!');
}
});
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Help!!!
SyntaxError: Unexpected token ILLEGAL
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3