0

I'm trying to convert an .mp4 to a .opus file using ffmpeg. I have a directory on my desktop called Indexing which has a test file called 40.mp4. I've tried using the command ffmpeg -i 40.mp4 -b:a 320k 40.opus which always works from a terminal set in the Indexing directory, but trying the same thing using Java always fails:

NOTE: I'm running on Kubuntu 17.10

private static final Path INDEXING_PATH = Paths.get("/home/sarah/Desktop/Indexing");

Process proc = new ProcessBuilder("ffmpeg -i 40.mp4 -b:a 320k 40.opus") .directory(INDEXING_PATH.toFile()).inheritIO().start();

Yields:

Exception in thread "main" java.io.IOException: Cannot run program "ffmpeg -i 40.mp4 -b:a 320k 40.opus" (in directory "/home/sarah/Desktop/Indexing"): error=2, No such file or directory at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)

Here's a snapshot of the folder: Snapshot

Sarah Szabo
  • 10,345
  • 9
  • 37
  • 60
  • 1
    Is ffmpeg in your path? (you can check by just running a straight "ffmpeg" that should work...) Possibly your ProcessBuilder constructor needs to be split up like `new ProcessBuilder("myCommand", "myArg1", "myArg2");` – rogerdpack Mar 26 '18 at 16:28

1 Answers1

1

Java is looking for a program called ffmpeg -i 40.mp4 -b:a 320k 40.opus when in reality it should invoke ffmpeg with -i 40.mp4 -b:a 320k 40.opus as arguments

To fix this, change Process proc = new ProcessBuilder("ffmpeg -i 40.mp4 -b:a 320k 40.opus") .directory(INDEXING_PATH.toFile()).inheritIO().start();

to

Process proc = new ProcessBuilder("ffmpeg", "-i", "40.mp4", "-b:a", "320k", "40.opus") .directory(INDEXING_PATH.toFile()).inheritIO().start();

Look at This for more

Also, try adding the full path to ffmpeg in the ffmpeg portion of the command

Srini
  • 1,619
  • 1
  • 19
  • 34