bramp / ffmpeg-cli-wrapper

Java wrapper around the FFmpeg command line tool
BSD 2-Clause "Simplified" License
1.72k stars 413 forks source link

Why does `.addExtraArgs` call have to be added after `.addOutput` call? #325

Closed Paper-Folding closed 7 months ago

Paper-Folding commented 7 months ago

The question I found that .addExtraArgs call have to be added after .addOutput call, I'm unsure if it is a bug or intentional, so I submit the question.

Example ffmpeg command

ffmpeg -i sample.webm -vf "select=gte(n\,100)" -vframes 1 out.jpg

What you have tried This works:

new FFmpegBuilder()
    .setInput("sample.webm")
    .setVideoFilter("select=gte(n\\,100)")
    .addOutput("out.jpg")
    .addExtraArgs("-vframes", "1")
    .done();

While this does not work (swapped .addExtraArgs and .addOutput call):

new FFmpegBuilder()
    .setInput("sample.webm")
    .setVideoFilter("select=gte(n\\,100)")
    .addExtraArgs("-vframes", "1")
    .addOutput("out.jpg")
    .done();
bramp commented 7 months ago

It is if you want to add a extra output argument, or extra input argument. The position of the arguments matter to ffmpeg.

addOutput returns a FFmpegOutputBuilder instead of a FFmpegBuilder, which is how the arguments get attached to that specific output, instead of to the input.

If you look at the generated command for both, you'll see where vframes ends up.