Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to run ffmpeg command(windows) in java

Tags:

java

ffmpeg

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...

like image 889
SAI GIRI CHARY AOUSULA Avatar asked May 29 '17 09:05

SAI GIRI CHARY AOUSULA


2 Answers

I found answer for myself. Instead of using String object, I used String array as below, then the command executed successfully.

String[] cmd={"C:\\ffmpeg\\bin\\ffmpeg","-i", "concat:C:\\journalism\\videos\\vid1.ts|C:\\journalism\\videos\\vid2.ts", "-c", "copy", "C:\\journalism\\videos\\output.mp4"};
Runtime.getRuntime().exec(cmd);
like image 108
SAI GIRI CHARY AOUSULA Avatar answered Oct 04 '22 23:10

SAI GIRI CHARY AOUSULA


My program is running, i just use as below. Hope it help you :

String cmd = "ffmpeg -i http://117.103.224.78/videoinput/Video1.mp4 -s 1920x1080 -c:a copy D:\\tmp\\Video2.mp4";

Process p = Runtime.getRuntime().exec(cmd);

like image 36
HND Avatar answered Oct 04 '22 22:10

HND