最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Translate Command Line Input to Node Fluent ffmpeg - Stack Overflow

programmeradmin0浏览0评论

I want to run the ffmpeg command line using node-fluent-ffmpeg (compile png images to a video):

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.

How can I format the command line to js code?

Thanks!

I want to run the ffmpeg command line using node-fluent-ffmpeg (compile png images to a video):

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.

How can I format the command line to js code?

Thanks!

Share Improve this question asked Nov 4, 2015 at 10:35 EladAEladA 3775 silver badges10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 19

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.

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. 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).

发布评论

评论列表(0)

  1. 暂无评论