how to run ffmpeg command(windows) in java

Viewed 8903

I executed the below FFMPEG terminal command in command prompt successfully. But I am unable to execute this command in my java program. I can execute all other ffmpeg commands which doesn't have double quotation marks, in my java program. Here I have confusing only with double quotation marks("...").

ffmpeg -i "concat:C:\\journalism\\videos\\vid1.ts|C:\\journalism\\videos\\vid2.ts" -c copy C:\\journalism\\videos\\output.mp4

I can execute above in command prompt successfully. But I tried as below in my java code.

Runtime.getRuntime().exec("C:\\ffmpeg\\bin\\ffmpeg -i 'concat:C:\\journalism\\videos\\vid1.ts|C:\\journalism\\videos\\vid2.ts' -c copy C:\\journalism\\videos\\output.mp4");

Even I tried by replaced the double quotation marks("...") with single quotation marks('...'). But not succeeded.

Can anyone please help me to get out of this issue...

Thanks in advance...

3 Answers

I was trying to do the same, this code did the trick.

String exeLocation = "\"C:\\Program Files\\ffmpeg\\bin\\ffmpeg\"";
String extractFileName = "test.mp4";
String extractFullPath = "C:\\ac3" + "\\" + extractFileName;
String dest = "C:\\\\ac3\\\\output.mp4";

String cmd = exeLocation + " -i " + extractFullPath + " -c copy " + dest ;
Runtime.getRuntime().exec(cmd);
Related