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

Checking ffmpeg availability and version #94

Open
vicnevicne opened this issue Aug 8, 2020 · 4 comments
Open

Checking ffmpeg availability and version #94

vicnevicne opened this issue Aug 8, 2020 · 4 comments

Comments

@vicnevicne
Copy link
Contributor

Progress with Jaffree goes very well :-) and the first version with video capture should be available soon. I'm now trying to make my software more robust by testing ffmpeg availability at startup.
Instead of browsing the path variable or calling "which ffmpeg" (platform-dependant), plus executable bit etc., I thought it was simpler to just try and execute ffmpeg, and analyse the result to determine if it was available and executable.

The simplest way I can think of is:

FFmpeg.atPath().addArgument("-version").execute();

Plus, parsing the result would allow checking the version is sufficiently recent.

However, executing the above line throws a RuntimeException which says:
"Process execution has ended with null result"

Do I absolutely need to pass fake input and output params to satisfy Jaffree or is there a way to just invoke ffmpeg without any actual work to do ?

(Of course, I could launch my own java.util.Process, but that kind of defeats the idea of a layer between the developer and ffmpeg :-) )

KR. Vicne

@kokorin
Copy link
Owner

kokorin commented Aug 8, 2020 via email

@vicnevicne
Copy link
Contributor Author

vicnevicne commented Aug 8, 2020

Indeed, atPath() falls back to PATH, but then executing a simple ffmpeg -version (with no input and no output involved) causes a

INFO: Process has finished with status: 0
Exception in thread "main" java.lang.RuntimeException: Process execution has ended with null result
	at com.github.kokorin.jaffree.process.ProcessHandler.interactWithProcess(ProcessHandler.java:151)
	at com.github.kokorin.jaffree.process.ProcessHandler.execute(ProcessHandler.java:94)
	at com.github.kokorin.jaffree.ffmpeg.FFmpeg.execute(FFmpeg.java:219)
	at jaffree.JaffreeTest.main(JaffreeTest.java:7)

While if ffmpeg is not found on the path, it causes a

INFO: Starting process: ffmpeg
Exception in thread "main" java.lang.RuntimeException: Failed to start process.
	at com.github.kokorin.jaffree.process.ProcessHandler.execute(ProcessHandler.java:96)
	at com.github.kokorin.jaffree.ffmpeg.FFmpeg.execute(FFmpeg.java:219)
	at jaffree.JaffreeTest.main(JaffreeTest.java:7)

In other words, no matter if ffmpeg is found or not, Jaffree throws a RuntimeException.

Here is a sample test;

import com.github.kokorin.jaffree.ffmpeg.FFmpeg;

public class JaffreeTest {
    public static void main(String[] args) {
        FFmpeg.atPath().addArgument("-version").execute();
    }
}

I also tried making a transcode from a dummy input to NullOutput, but the "testsrc" dummy input filter does not seem to be available, so here is what I ended up with:

public class JaffreeTest {
    public static void main(String[] args) {
        FFmpeg.atPath().addArguments("-f", "lavfi").addArguments("-i", "testsrc=duration=1:size=300x200:rate=10").addOutput(new NullOutput()).execute();
    }
}

I think it's a bit overkill (and ugly) just to check if ffmpeg is available. Can you think of another way ?

@kokorin
Copy link
Owner

kokorin commented Aug 9, 2020 via email

@vicnevicne
Copy link
Contributor Author

In the end, I worked around the issue with a simple "Process" call, so no emergency for me, but I think it would make sense, yes. Or maybe throw a subclass of RuntimeException, like a FFmpegNotFoundException or something, so that it can be caught specifically.
KR Vicne

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants