Java – Should I use the FFMPEG library or the CLI

Should I use the FFMPEG library or the CLI… here is a solution to the problem.

Should I use the FFMPEG library or the CLI

In terms of performance, which is better to use an FFMPEG library (such as https://github.com/kokorin/Jaffree) or the FFMPEG command line interface?

Solution

My initial thought was: this is a “self-righteous” question, hence the digression. However, I think there is a clear technical answer to this

Basically, you want to programmatically use FFMPEG to solve some problems for you from within your Java application. So, the answer is very simple: when you want to do things programmatically, use the interface, which is intended for programmatic purposes.

Meaning: You definitely prefer the API to manually invoking the client with a “raw” system command invocation.

Why:

  • Libraries/APIs provide you with compile-time security. You have type method calls, and so on
  • CLI … You are only allowed to “manually” combine a string and trigger it. If it works: Great, but if it doesn’t work… You can only discover at runtime.

Beyond that: if you’re talking about a “serious” project, sooner or later your code might want to do something different. Then the points above are just “multiplyed”. You know that the string is built dynamically, not a single command-line string that you can prepare.

Long story short: for a simple problem, maybe the CLI is a good solution. But then: why wrap it in Java, then you can also write a small shell or python script as a small wrapper for the calls you need.

Related Problems and Solutions