'Should I use FFMPEG library vs CLI

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



Solution 1:[1]

My initial thought was: this is an "opinionated" question, thus off topic. But then, I think there is a clear technical answer for this

Basically you want to programmatically use FFMPEG to solve some problem for you, from within your Java application. Therefore the answer is pretty much straight forward: when you want to things programmatically, then use that interface, that is intended for programmatic usage.

Meaning: you definitely prefer the API over using "raw" system command calls to invoke the client manually.

Why:

  • A library/API gives you compile time safety. You have method calls with types, and whatnot
  • The CLI ... only allows you to pull together a string "manually", and to fire that. If it works: great, but if not ... you only find out at runtime.

Beyond that: if you are talking about a "serious" project, then sooner or later, your code might want to do different things. And then the points from above just "multiply". Instead of one single command line string you can prepare for, you know build that string dynamically.

Long story short: for a simple problem, maybe the CLI is a good solution. But then: why wrap that in java, then you could as well write a small shell or python script as a small wrapper around the call you need.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1