ffmpeg works fine most of the time in java except for this command (merging), and this command works fine directly in terminal

StackOverflow https://stackoverflow.com/questions/23643440

  •  22-07-2023
  •  | 
  •  

سؤال

When I run this from the command line it works (merges two videos side by side):

/usr/local/bin/ffmpeg -i /Users/ron/Dropbox/JAMR/Technology/workspace/JAMR/sandbox/test.mov -i /Users/ron/Dropbox/JAMR/Technology/workspace/JAMR/sandbox/test1.mov -filter_complex "[0:v:0]pad=iw*2:ih[bg]; [bg][1:v:0]overlay=w" /Users/ron/Dropbox/JAMR/Technology/workspace/JAMR/sandbox/merged.mov

However, when I run it in java, I get this from the console:

[AVFilterGraph @ 0x7fd44ad00440] No such filter: '"'
Error configuring filters.

here is the text I am returning (copied directly) which is what I am sending to be executed. It is exactly the same, except I use the escape character before the quote symbol, so a " becomes \":

"/usr/local/bin/ffmpeg -i /Users/ron/Dropbox/JAMR/Technology/workspace/JAMR/sandbox/test.mov -i /Users/ron/Dropbox/JAMR/Technology/workspace/JAMR/sandbox/test1.mov -filter_complex \"[0:v:0]pad=iw*2:ih[bg]; [bg][1:v:0]overlay=w\" /Users/ron/Dropbox/JAMR/Technology/workspace/JAMR/sandbox/merged.mov";

All other ffmpeg tests have worked except this.... (the only one where I use a " character)

Can anyone figure it out?

هل كانت مفيدة؟

المحلول

you should split your command in Java into a String array and then pass it to getRuntime().exec(String[])

Short example:

String cmd[] = new String[]{
                "ffmpeg",
                "-r", String.valueOf(20/30f), 
                "-i", "assets/IMAG0054_BURST%03d.jpg",
                "-i","assets/logo.png",
                "-i","assets/guitar_tuning.wav","-r", "24", "-codec:a", "mp3",
                "-filter_complex","[0:v][1:v]overlay=main_w-overlay_w-10:main_h-overlay_h-10,"+
                "drawtext=fontfile=assets/OpenSans-Regular.ttf:text=1st scene:x=0:y=0:fontsize=100:fontcolor=white:enable='between(t,0.5,2.5)'," +
                "drawtext=enable='between(t,2.6,5.5)':fontfile=assets/OpenSans-Regular.ttf:text=2nd scene:x=0:y=0:fontsize=100:fontcolor=white," +
                "drawtext=enable='between(t,5.6,8.8)':fontfile=assets/OpenSans-Regular.ttf:text=3rd scene:x=0:y=0:fontsize=100:fontcolor=white," +
                "drawtext=enable='between(t,8.9,30)':fontfile=assets/OpenSans-Regular.ttf:text=4rd scene:x=0:y=0:fontsize=100:fontcolor=white" +
                "[out]",
                "-map", "[out]", "-map", "2:0",
                "-acodec","mp3",
                //"-shortest " +
                "simple_lapse.mp4"};

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

Hope it helps

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top