除了这个命令(合并)之外,ffmpeg大部分时间在java中工作正常,这个命令在终端中工作正常

时间:2014-05-13 23:51:25

标签: java ffmpeg

当我从命令行运行它时,它可以工作(并排合并两个视频):

/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

但是,当我在java中运行它时,我从控制台得到它:

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

这是我要返回的文本(直接复制),这是我要发送的文件。它完全相同,除了我在引号之前使用转义字符,所以“变成\”:

"/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";

所有其他ffmpeg测试除了这个以外都有用....(我使用“字符”的唯一一个

有人能搞清楚吗?

1 个答案:

答案 0 :(得分:3)

您应该将Java中的命令拆分为String数组,然后将其传递给getRuntime()。exec(String [])

简短的例子:

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);

希望有所帮助