简体   繁体   English

将命令行输入转换为Node Fluent ffmpeg

[英]Translate Command Line Input to Node Fluent ffmpeg

I want to run the ffmpeg command line using node-fluent-ffmpeg (compile png images to a video): 我想使用node-fluent-ffmpeg运行ffmpeg命令行(将png图像编译为视频):

ffmpeg -framerate 20 -i static/tmp/img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4  

I was trying the following, but with no luck. 我正在尝试以下,但没有运气。

var ffmpeg = require('fluent-ffmpeg');

var proc = new ffmpeg()
    .addInputOption('-framerate 20')
    .addInputOption('static/tmp/img%03d.png')
    .addInputOption('-c:v libx264')
    .addInputOption('-r 30')
    .addInputOption('-pix_fmt yuv420p out.mp4')
    .output('outputfile.mp4')
    .output(stream);

I looked all over the github repository and all the Q/A on stackoverflow, but with no proper answer. 我查看了github存储库和stackoverflow上的所有Q / A,但没有正确的答案。

How can I format the command line to js code? 如何将命令行格式化为js代码?

Thanks! 谢谢!

You've probably figured this out by now, but I'll answer anyway. 你现在可能已经想到了这一点,但无论如何我都会回答。

Try this: 尝试这个:

var ffmpeg = require('fluent-ffmpeg');

var proc = new ffmpeg();

proc.addInput('static/tmp/img%03d.png')
.on('start', function(ffmpegCommand) {
    /// log something maybe
})
.on('progress', function(data) {
    /// do stuff with progress data if you want
})
.on('end', function() {
    /// encoding is complete, so callback or move on at this point
})
.on('error', function(error) {
    /// error handling
})
.addInputOption('-framerate 20')
.outputOptions(['-c:v libx264', '-r 30', '-pix_fmt yuv420p'])
.output('out.mp4')
.run();

Basically, anything before -i is considered an input option, and anything between the input and output file is considered an output option. 基本上,-i之前的任何内容都被视为输入选项,输入和输出文件之间的任何内容都被视为输出选项。

You can add multiple input or output options in one line using an array of options, the fluent ffmpeg github will also point you to some javascript code that works as shortcuts for some of these commands, although I still find it easier to use command line syntax. 你可以使用一组选项在一行中添加多个输入或输出选项,流畅的ffmpeg github也会指向一些javascript代码,这些代码可以作为其中一些命令的快捷方式,尽管我仍然觉得使用命令行语法更容易。 https://github.com/fluent-ffmpeg/node-fluent-ffmpeg https://github.com/fluent-ffmpeg/node-fluent-ffmpeg

If you want multiple outputs, you can add more .output like in your example (although your command line ffmpeg wasn't doing that). 如果你想要多个输出,你可以像你的例子一样添加更多.output (虽然你的命令行ffmpeg没有这样做)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM