Node-fluent-ffmpeg: Events never called again after first call until app restart (Restify)

Created on 8 Mar 2017  路  3Comments  路  Source: fluent-ffmpeg/node-fluent-ffmpeg

Version information

  • fluent-ffmpeg version: 2.1.0
  • ffmpeg version: N-83701-g70ebc05-tessus
  • OS: Mac OSX 10.11.6 El Capitan

Code to reproduce

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);
});

Expected results

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.

Observed results

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.

Needs info

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 called save().

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

epdev picture epdev  路  3Comments

danielbanfield picture danielbanfield  路  5Comments

mStirner picture mStirner  路  4Comments

jsamos picture jsamos  路  6Comments

elartix picture elartix  路  5Comments