如何使用node.js和fluent-ffmpeg检查损坏的webm视频?

时间:2017-04-11 14:50:37

标签: javascript node.js ffmpeg fluent-ffmpeg

我想检查编码的webm视频是否有错误。 到目前为止,我已经设法使用类似的东西捕获错误:

ffmpeg -v error -i ../broken.webm -f null - 

输出:

[matroska,webm @ 0x7fba5400a200] Read error at pos. 110050 (0x1ade2)

我想使用node.js和fluent-ffmpeg来实现相同的输出,但我无法使用js包装器语法来传递-v error-f null -

我天真的尝试看起来像这样:

// 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 !')
})

但我立刻收到了错误:ffmpeg exited with code 1: Unrecognized option '-f null -'.

关于如何使用fluent-ffmpeg从node.js调用ffmpeg -v error -i ../broken.webm -f null -的任何想法?

1 个答案:

答案 0 :(得分:1)

您正朝着正确的方向前进,但还有一些其他条目要添加到您的ffmpeg行以处理您想要的选项。像下面这样的东西应该做你需要的:

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将命令行选项分隔为addInputOption和outputOptions。如果您有多个输出选项,则可以将它们作为一组设置传递给outputOptions。

请注意,要使用outputOptions,我认为您需要指定输出文件。如果您不需要它,请将其设为临时文件,然后在完成时删除或输出到空设备。请查看https://github.com/fluent-ffmpeg/node-fluent-ffmpeg处的fluent-ffmpeg自述页面。它详细介绍了这些和其他选项。

虽然可能有更好的方法来验证您的文件,但希望这会让您使用fluent-ffmpeg。

相关问题