Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FFmpegInputBuilder to support per input options #318

Closed
Euklios opened this issue Mar 12, 2024 · 8 comments
Closed

Add FFmpegInputBuilder to support per input options #318

Euklios opened this issue Mar 12, 2024 · 8 comments
Assignees

Comments

@Euklios
Copy link
Collaborator

Euklios commented Mar 12, 2024

Is your feature request related to a problem? Please describe.
We currently don't allow per-input options; therefore, commands requiring multiple inputs aren't supported in many cases.
For example the following command can't be constructed using this library:
ffmpeg -f lavfi -i "testsrc=duration=10:size=1280x720:rate=30" -f lavfi -i "sine=frequency=1000:sample_rate=48000:duration=10" -c:a aac -c:v h264 output.mp4.

Describe the solution you'd like
An FFmpegInputBuilder to construct inputs and allow parameters for individual inputs.

Describe alternatives you've considered
The alternative would be to hack around with addExtraArgs. However, that would undermine the purpose of this library.

Related:

@Euklios
Copy link
Collaborator Author

Euklios commented Mar 16, 2024

This is mainly focused towards fixing EncodingOptions and making it easier to update in the future.
But it should also adding new arguments and flags easier.

@AlexanderSchuetz97
Copy link

AlexanderSchuetz97 commented Jul 26, 2024

I am inrested in this too. I currently use addExtraOptions to pass pass input options for decoding rawvideo, like videosize and pixel format.

@Euklios
Copy link
Collaborator Author

Euklios commented Aug 8, 2024

@AlexanderSchuetz97 Thank you for the feedback!
If possible, could you share some example commands I can use for tests?

@Euklios
Copy link
Collaborator Author

Euklios commented Aug 9, 2024

For anyone interested, I created PR #339 for this feature.

@AlexanderSchuetz97
Copy link

i forgot about giving you examples today. Will do so on monday hopefully.

@Euklios
Copy link
Collaborator Author

Euklios commented Aug 10, 2024

No problem, any form of help is appreciated

@AlexanderSchuetz97
Copy link

AlexanderSchuetz97 commented Aug 13, 2024

These are the 2 Main occurrences of "addExtraArgs" for an Input in the code-base of my current Project.
One is the raw video use case, the other is -strict 2 which I also need for ffprobe.
It allows ffmpeg to decode vvc/h266 videos.

Also FYI, add an option to disable B frames please. (-bf 0)
FFmpeg outputs them by default and 99% of devices that must play the output cannot handle them.

FFmpegBuilder builder = new FFmpegBuilder()
        .addExtraArgs("-video_size", size.getWidth() +"x"+size.getHeight())
        .addExtraArgs("-f", "rawvideo")
        .addExtraArgs("-r", Fraction.getFraction(fps).toString())
        .addExtraArgs("-pix_fmt", "bgr24")
        .addInput("unix://" + socketFile.toAbsolutePath())
        .addOutput(output.getAbsolutePath())
        .addExtraArgs("-bf", "0")
        .setVideoCodec(codec)
        .setFormat(format)
        .disableAudio()
        .done();

FFmpegOutputBuilder builder = mpeg.builder()
        .addExtraArgs("-strict", "-2")
        .addInput(input.getAbsolutePath())
        .addOutput(output.getAbsolutePath())
        .setVideoCodec(videoCodec)
        .setAudioCodec(audioCodec)
        .addExtraArgs("-bf", "0")
        .setFormat(format);

Just FYI This is what I had to do to get your FFProbe to recognize vvc/h266 videos

public class FFProbeWrapper extends FFprobe {

    private static final Map<String, String> VERSION_MAP = new ConcurrentHashMap<>();

    public FFProbeWrapper(@Nonnull String path) throws IOException {
        super(path,new RunProcessFunction() {
            @Override
            public Process run(List<String> args) throws IOException {
                if (args.isEmpty()) {
                    return super.run(args);
                }
                List<String> ar = new ArrayList<>();
                ar.add(args.getFirst());
                ar.add("-strict");
                ar.add("-2");
                ar.addAll(args.subList(1, args.size()));
                return super.run(ar);
            }
        });
    }

    @Nonnull
    @Override
    public synchronized String version() throws IOException {
        String s = VERSION_MAP.get(this.getPath());
        if (s != null) {
            return s;
        }

        String v =  super.version();
        VERSION_MAP.put(this.getPath(), v);
        return v;
    }
}

If you need a H266 testfile I can provide one.

@Euklios
Copy link
Collaborator Author

Euklios commented Aug 21, 2024

I've extracted the two issues #345 and #346 based on this.
Strictness -2 matches with experimental, so to my understanding the flag is just not at the right position (on the right builder)

@Euklios Euklios closed this as completed Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants