我正在使用fluent-ffmpeg节点模块从文件中获取编解码器数据。 它可以工作,如果我给出一个输出,但我想知道是否有任何选项运行fluent-ffmpeg而不给它输出。 这就是我在做的事情:
readStream.end(new Buffer(file.buffer));
var process = new ffmpeg(readStream);
process.on('start', function() {
console.log('Spawned ffmpeg');
}).on('codecData', function(data) {
//get recording duration
const duration = data.duration;
console.log(duration)
}).save('temp.flac');
正如您所看到的,我将文件保存到temp.flac
,因此我可以获得该文件的秒持续时间。
答案 0 :(得分:0)
如果您不想将 ffmpeg 处理结果保存到文件中,可以想到的一件事是将命令输出重定向到/dev/null
。
事实上,正如 fluent-ffmpeg 存储库的所有者在一个comment中说的那样,使用{{1}时无需为目标指定真实文件名格式。
因此,例如,类似的东西将起作用:
null
它仍然有点hacky,但我们必须设置输出以避免"没有指定输出"错误。
答案 1 :(得分:0)
当不存在任何流参数时,pipe()方法将返回PassThrough流,您可以将该流通过管道传递到其他地方(或仅监听事件)。
var command = ffmpeg('/path/to/file.avi')
.videoCodec('libx264')
.audioCodec('libmp3lame')
.size('320x240')
.on('error', function(err) {
console.log('An error occurred: ' + err.message);
})
.on('end', function() {
console.log('Processing finished !');
});
var ffstream = command.pipe();
ffstream.on('data', function(chunk) {
console.log('ffmpeg just wrote ' + chunk.length + ' bytes');
});