use java-ffmpeg wrapper, or simply use java runtime to execute ffmpeg?

JavaFfmpegruntime.exec

Java Problem Overview


I'm pretty new to Java, need to write a program that listen to video conversion instructions and convert the video once an new instruction arrives (instructions is stored in Amazon SQS, but it's irrelevant to my question)

I'm facing a choice, either use Java RunTime to exec 'ffmpeg' conversion (like from command line), or I can use a ffmpeg wrapper written inJava http://fmj-sf.net/ffmpeg-java/getting_started.php

I'd much prefer using Java Runtime to exec ffmpeg directly, and avoid using java-ffmpeg wrapper as I have to learn the library. so my question is are there any benefits using java-ffmpeg wrapper over exec ffmpeg directly using Runtime? I don't need ffmpeg to play videos, just convert videos

Thanks

Java Solutions


Solution 1 - Java

If I'm not mistaken, the "ffmpeg wrapper" project you linked to is out of date and not maintained. ffmpeg is a very active project, lot's of changes and releases all the time.

You should look at the Xuggler project, this provides a Java API for what you want to do, and they have tight integration with ffmpeg.

http://www.xuggle.com/xuggler/

Should you choose to go down the Runtime.exec() path, this Red5 thread should be useful:

http://www.nabble.com/java-call-ffmpeg-ts15886850.html

Solution 2 - Java

I too am looking for something to wrap FFMPEG in Java. While searching, I found this: https://github.com/bramp/ffmpeg-cli-wrapper.

As of today, it seems to have been modified a month ago. So, hopefully it will stick around for a while.

A sample from their docs:

FFmpeg ffmpeg = new FFmpeg("/path/to/ffmpeg");
FFprobe ffprobe = new FFprobe("/path/to/ffprobe");

FFmpegBuilder builder = new FFmpegBuilder()
    .setInput(in)
    .overrideOutputFiles(true)
    .addOutput("output.mp4")
        .setFormat("mp4")
        .setTargetSize(250000)

        .disableSubtitle()

        .setAudioChannels(1)
        .setAudioCodec("libfdk_aac")
        .setAudioRate(48000)
        .setAudioBitrate(32768)

        .setVideoCodec("libx264")
        .setVideoFramerate(Fraction.getFraction(24, 1))
        .setVideoResolution(640, 480)

        .setStrict(FFmpegBuilder.Strict.EXPERIMENTAL)
        .done();

FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
executor.createTwoPassJob(builder).run();

Solution 3 - Java

There are a lot of Java libraries providing FFMPEG wrappers. However, most of these libraries are unfortunately outdated and use old FFMPEG versions which lack some important codecs (e.g. Xuggler, humble video, JavaAV, JavaAVC, and jave). So be careful when using those projects!

However, there is one FFMPEG wrapper that is still actively developed and supports FFMPEG 4:

Alternatively you can use a wrapper for the command line interface of FFMPEG, such as ffmpeg-cli-wrapper. Then it's in your hand to update ffmpeg manually without having to wait for a new release of the wrapper library.

Solution 4 - Java

I wrote my own Java ffmpeg command line wrapper: Jaffree. It works with both ffprobe and ffmpeg and supports programmatic video production and consumption. Also it has in my opinion more convenient fluid API.

Here is an ffprobe usage example:

FFprobeResult result = FFprobe.atPath(BIN)
        .setInputPath(VIDEO_MP4)
        .setShowStreams(true)
        .setShowError(true)
        .execute();

if (result.getError() != null) {
    //TODO handle ffprobe error message
    return;
}

for (Stream stream : probe.getStreams().getStream()) {
    //TODO analyze stream data
}

ProgressListener listener = new ProgressListener() {
	@Override
	public void onProgress(FFmpegProgress progress) {
		//TODO handle progress data
	}
};

And this is for ffmpeg:

FFmpegResult result = FFmpeg.atPath(BIN)
		.addInput(Input.fromPath(VIDEO_MP4))
		.addOutput(Output.toPath(outputPath)
				.addCodec(null, "copy")
		)
		.setProgressListener(listener)
		.execute();

Solution 5 - Java

Also, as of Xuggler 3.3, Xuggler is LGPL meaning you don't need a commercial license.

Solution 6 - Java

Solution 7 - Java

The benefits of using the wrapper would be mainly that it offers more and fine-grained functionality not accessible via the command line (not relevant to you) and makes error handling and status control easier - you'll have to parse the command line tool's standard output and error streams.

Solution 8 - Java

i try several ways, the most simple for me is ffmpeg-cli-wrapper, because it use default ffmpeg or specific one, moreover you can configure lot of configuration like scale, bitrate... get duration... JAVE from sauronsoftware make lot of error, XUGGLE and other i found it too complicated

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBeierView Question on Stackoverflow
Solution 1 - JavaPeter ThomasView Answer on Stackoverflow
Solution 2 - JavamateuscbView Answer on Stackoverflow
Solution 3 - JavaStefan EndrullisView Answer on Stackoverflow
Solution 4 - JavaDenis KokorinView Answer on Stackoverflow
Solution 5 - JavaArt ClarkeView Answer on Stackoverflow
Solution 6 - JavasohilvView Answer on Stackoverflow
Solution 7 - JavaMichael BorgwardtView Answer on Stackoverflow
Solution 8 - JavacyrilView Answer on Stackoverflow