2

I am writing a Java Swing application in Java that serves as a frontend for the ffmpeg command. It inputs the folder and the file name from the user and adds many more parameters that are constantly displayed in JTextField. User can edit the final command in the text field that it about to be called.

This works in both Windows and Linux:

Process ffmpeg = Runtime.getRuntime().exec(command, null, new File(current_working_folder));

command is a string. It is formatted depending from the OS, so that the path is always given in full (absolute path) and the slashes are appropriate for the given OS.

In Windows and Linux, it is possible to execute ffmpeg command by enclosing the folder and file names in "....". In Windows, this formatting ultimately works through Runtime.getRunTime.exec().

However, in Linux, this does not work through Runtime.getRunTime.exec(). The quotation marks are perhaps misunderstood "....".

Any advice on this?

1
  • Are you getting any exception ? Commented Dec 20, 2012 at 17:31

1 Answer 1

2

Try passing your command as an array, rather than a string using this method: Runtime.exec(String[] cmdarray, String[] envp, File dir).

For example, instead of :

Runtime.getRuntime().exec("ffmpeg -i video_origine.avi video_finale.mpg", null, new File(current_working_folder));

use:

Runtime.getRuntime().exec(new String[]{"ffmpeg", "-i", "video_origine.avi", "video_finale.mpg"}, null, new File(current_working_folder));
Sign up to request clarification or add additional context in comments.

5 Comments

I want to use just a string, because I am trying to accomplish the functionality in the most general case and on all operating systems.
Here is a test. ffmpeg -f image2 -r 16 -i "/home/neuron/IdeaProjects/Perceptron/animations/New Folder 666 from HeLL. folder/frame%d.tga" "/home/neuron/IdeaProjects/Perceptron/movies/ jk 904. 0. 02.1lk .folder/my mkvmovie.mkv" Notice how we can include the spaces in path/file names and fit it all together in the quotation marks. This works in windows and linux console, but not in linux by using java Runtime.getRuntime().exec(). It would be difficult to make a string array, I think, in general case if the path/file names are as complicated as I tried to make them.
[Stderr] [image2 @ 0xa2c99a0] Could find no file with with path '"/home/neuron/IdeaProjects/Perceptron/animations/New' and index in the range 0-4 [Stderr] "/home/neuron/IdeaProjects/Perceptron/animations/New: No such file or directory
this also does not work in linux via java frontend ffmpeg -f image2 -r 16 -i /home/neuron/IdeaProjects/Perceptron/animations/New Folder 666 from HeLL.\ folder/frame%d.tga /home/neuron/IdeaProjects/Perceptron/movies/\ jk 904.\ 0.\ 02.1lk .folder/mkv mov22.mkv
{"ffmpeg", "-f", "image2", "-r", "16", "-i", "/home/neuron/IdeaProjects/Perceptron/animations/New Folder 666 from HeLL. folder/frame%d.tga", "/home/neuron/IdeaProjects/Perceptron/movies/ jk 904. 0. 02.1lk .folder/mymkvmovie.mkv"}; [Stderr] /home/neuron/IdeaProjects/Perceptron/movies/ jk 904. 0. 02.1lk .folder/mymkvmovie.mkv: No such file or directory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.