Following the documentation exactly, I'm attempting to use a stream to write a video conversion to file.
var FFmpeg = require('fluent-ffmpeg');
var fs = require('fs');
var outStream = fs.createWriteStream('C:/Users/Jack/Videos/test.mp4');
new FFmpeg({ source: 'C:/Users/Jack/Videos/video.mp4' })
.withVideoCodec('libx264')
.withAudioCodec('libmp3lame')
.withSize('320x240')
.on('error', function(err) {
console.log('An error occurred: ' + err.message);
})
.on('end', function() {
console.log('Processing finished !');
})
.writeToStream(outStream, { end: true });
This conversion works perfectly when I use .saveToFile(), but returns
An error occurred: ffmpeg exited with code 1
When I run this code. I'm on Windows 8.1 64 bit using a 64 bit ffmpeg build from here .
I had the same problem today (and on the same platform too)
It's like when you stream you have to specify a format but you cannot specify mp4 because it's not valid
I ended up with this, I think it's a good workaround and I hope it helps:
var input_file = fs.createReadStream(path);
input_file.on('error', function(err) {
console.log(err);
});
var output_path = 'tmp/output.mp4';
var output_stream = fs.createWriteStream('tmp/output.mp4');
var ffmpeg = child_process.spawn('ffmpeg', ['-i', 'pipe:0', '-f', 'mp4', '-movflags', 'frag_keyframe', 'pipe:1']);
input_file.pipe(ffmpeg.stdin);
ffmpeg.stdout.pipe(output_stream);
ffmpeg.stderr.on('data', function (data) {
console.log(data.toString());
});
ffmpeg.stderr.on('end', function () {
console.log('file has been converted succesfully');
});
ffmpeg.stderr.on('exit', function () {
console.log('child process exited');
});
ffmpeg.stderr.on('close', function() {
console.log('...closing time! bye');
});
I had same problem on Debian. Problem was, that there was only avconv with ffmpeg fallback, but the library fluent-ffmpeg called ffmpeg -encoders , which ended with " Missing argument for option '-encoders' ". Avconv has avconv -codecs only.
So installing proper ffmpeg package should help.
(or change flunt-ffmpeg library code to call not -encoders but -codecs, output format is slightly different)
PS.: same script was doing great job on windows
Try updating ffmpeg on your machine. I had 2.8 and I got the same error. It works fine after updating to 3.0.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.