I'd like to check if an encoded webm video has errors. So far I've managed to catch an error using something like this:
ffmpeg -v error -i ../broken.webm -f null -
which outputs:
[matroska,webm @ 0x7fba5400a200] Read error at pos. 110050 (0x1ade2)
I would like to achieve the same output using node.js and fluent-ffmpeg, but I couldn't figure out to to pass -v error
and -f null -
using the js wrapper syntax.
My naive attempt looks like this:
// ffmpeg -v error -i ../broken.webm -f null -
ffmpeg("../broken.webm")
.on('error', function(err) {
console.error('An error occurred: ',err.message)
})
.save('-f null -')
.on('end', function() {
console.log('done !')
})
but I got an error straight away: ffmpeg exited with code 1: Unrecognized option '-f null -'.
Any ideas on how I could call ffmpeg -v error -i ../broken.webm -f null -
from node.js using fluent-ffmpeg ?
You're headed in the right direction, but there are a couple other entries to add to your ffmpeg line to handle the options you want. Something like the following should do what you need:
var ffmpeg = require('fluent-ffmpeg');
var ff = new ffmpeg();
ff.on('start', function(commandLine) {
// on start, you can verify the command line to be used
console.log('The ffmpeg command line is: ' + commandLine);
})
.on('progress', function(data) {
// do something with progress data if you like
})
.on('end', function() {
// do something when complete
})
.on('error', function(err) {
// handle error conditions
if (err) {
console.log('Error transcoding file');
}
})
.addInput('../broken.webm')
.addInputOption('-v error')
.output('outfile')
.outputOptions('-f null -')
.run();
Fluent-ffmpeg separates command line options into addInputOption and outputOptions. If you have multiple output options, you can pass them to outputOptions as an array of settings.
Note that to use the outputOptions, I think you are required to specify an output file. If you don't need it, make it a temp file and then delete on completion or maybe output to a null device. Take a look at the fluent-ffmpeg readme page at https://github.com/fluent-ffmpeg/node-fluent-ffmpeg. It details these and other options in good detail.
Though there might be better ways to validate your files, hopefully this will get you going with fluent-ffmpeg.