[英]How to insert images and text in video with ffmpeg - java
String[] code = new String[]{"ffmpeg", "-i","D:/ffmpeg/20170201_164127.mp4",
"-i","D:/ffmpeg/cc.png", "-filter_complex",
"[0:v][1:v]overlay=main_w-overlay_w-5:main_h-overlay_h-5",
"drawtext=fontfile=/ffmpeg/Arial.ttf:text='TESTING'fontcolor=white@1.0:fontsize=70:x=10:y=H-th-10:box=1:boxcolor=black@0.5:boxborderw=5:x=10:y=H-th-10",
"[out]","-map", "[out]", "-map", "2:0",
"-acodec","mp3", "D:/ffmpeg/test7.mp4"};
Process processDuration = new ProcessBuilder(code).redirectErrorStream(true).start();
StringBuilder strBuild = new StringBuilder();
try (BufferedReader processOutputReader = new BufferedReader(new InputStreamReader(processDuration.getInputStream(), Charset.defaultCharset()));) {
String line;
while ((line = processOutputReader.readLine()) != null) {
strBuild.append(line + System.lineSeparator());
}
processDuration.waitFor();
}
String outputJson = strBuild.toString().trim();
System.out.println(outputJson);
}
When i use only images the code is correctly. 当我仅使用图像时,代码正确。 But when I use all the code this happens:
但是,当我使用所有代码时,就会发生这种情况:
[NULL @ 00000000006abe60] Unable to find a suitable output format for 'drawtext=fontfile=/ffmpeg/Arial.ttf:text='TESTING'fontcolor=white@1.0:fontsize=70:x=10:y=H-th-10:box=1:boxcolor=black@0.5:boxborderw=5:x=10:y=H-th-10' drawtext=fontfile=/ffmpeg/Arial.ttf:text='TESTING'fontcolor=white@1.0:fontsize=70:x=10:y=H-th-10:box=1:boxcolor=black@0.5:boxborderw=5:x=10:y=H-th-10: Invalid argument
[NULL @ 00000000006abe60]无法为'drawtext = fontfile = / ffmpeg / Arial.ttf:text='TESTING'fontcolor=white@1.0:fontsize = 70:x = 10:y = H-th-找到合适的输出格式10:box = 1:boxcolor=black@0.5:boxborderw = 5:x = 10:y = H-th-10'drawtext = fontfile = / ffmpeg / Arial.ttf:text='TESTING'fontcolor=white@1.0: fontsize = 70:x = 10:y = Hthth-10:box = 1:boxcolor=black@0.5:boxborderw = 5:x = 10:y = Hthth-10:无效的参数
If, as it seems, a space is inserted after each argument in the string, then that explains the error. 如果看起来在字符串中的每个参数之后插入一个空格,则说明该错误。 You haven't enclosed the entire filter_complex in quotes, so a space is inserted between the overlay and drawtext.
您没有将整个filter_complex括在引号中,因此在覆盖图和drawtext之间插入了一个空格。 To FFmpeg, it looks like you terminated the filter_complex with the overlay and hence the drawtext string represents the output.
对于FFmpeg来说,好像您终止了带有覆盖层的filter_complex,因此绘制文本字符串表示输出。
So either provide the entire filter_complex argument in one string including upto [out]
with no whitespace in between OR add a opening double quote before [0:v]
and closing quote after [out]
. 因此,要么在一个字符串中提供整个filter_complex参数,包括最多
[out]
且之间没有空格,要么在[0:v]
之前添加一个开头双引号,并在[out]
之后添加结束引号。 You probably have to escape those quotes. 您可能必须转义那些引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.