var restify = require('restify');
var ffmpeg = require('fluent-ffmpeg');
var server = restify.createServer({
name: 'ffmpeg-runner'
});
server.get('/transcode/:filename', transcode);
function transcode(req, res, next) {
_HD_720P = ffmpeg(req.params.filename)
.videoBitrate(3000)
.audioBitrate('96k')
.size('1280x720')
.save('output.mp4')
.on('start', function(commandLine) {
console.log('FFMPEG: ' + commandLine);
})
.on('progress', function(progress) {
console.log('Processing: ' + JSON.stringify(progress));
})
.on('stderr', function(stderrLine) {
console.log('Stderr output: ' + stderrLine);
})
.on('error', function(err, stdout, stderr) {
console.log('Cannot process video: ' + err.message);
})
.on('end', function(stdout, stderr) {
console.log('Transcoding successful.');
});
}
server.listen(8080, function() {
console.log('%s listening at %s', server.name, server.url);
});
Repeated calls to /transcode/:filename should print out the status to the console as specified in the command as events happen. For example, a second call to /transcode/:filename a minute after the first one completes should continue to log events to the console.
Only the .on('end') event is called on subsequent requests to /transcode/:filename. The other events are only called once in the lifetime of the node script.
The issue was partially resolved by downgrading back to 2.0.1. progress events (in addition to the end event) are now being emitted for repeated calls, but the other ones are still not being emitted.
You should register event handlers before calling save(), because the processing methods check for registered event handlers at the beginning. That would probably explain unpredictible results when registering events after having called save().
Thank you, placing save() after registering event handlers solved this issue.
Most helpful comment
You should register event handlers before calling
save(), because the processing methods check for registered event handlers at the beginning. That would probably explain unpredictible results when registering events after having calledsave().