我尝试使用 Mobile-FFmpeg
使用具有不同比例或大小或(高度*宽度)的多个图像创建视频#
我正在使用此代码脚本来获得所需的结果:
val filterStringBuilder1 = StringBuilder()<br />
filterStringBuilder1.append(listOfImages)<br />
filterStringBuilder1.append("-filter_complex ")<br />
filterStringBuilder1.append(<br />
"[0:v]scale=100:140:force_original_aspect_ratio=decrease,pad=100:140:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=out:st=4:d=1[v0];" +<br />
"[1:v]scale=180:120:force_original_aspect_ratio=decrease,pad=180:120:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v1];" +<br />
"[2:v]scale=120:180:force_original_aspect_ratio=decrease,pad=120:180:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v2];" +<br />
"[v0][v1][v2]concat=n=3:v=1:a=0,format=yuv420p[v]")<br />
filterStringBuilder1.append(" -map")<br />
filterStringBuilder1.append(" [v] ")<br />
filterStringBuilder1.append("-aspect 16:9 ")<br />
filterStringBuilder1.append(finalVideo.absolutePath)<br />
FFmpeg.execute(filterStringBuilder1.toString())<br />
但发现以下 logcat 错误:
E/mobile-ffmpeg: [Parsed_concat_14 @ 0x748fc98bc0] <br />
E/mobile-ffmpeg: Input link in1:v0 parameters (size 180x120, SAR 1:1) do not match the corresponding <br />output link in0:v0 parameters (100x140, SAR 1:1)<br />
E/mobile-ffmpeg: [Parsed_concat_14 @ 0x748fc98bc0] <br />
E/mobile-ffmpeg: Failed to configure output pad on Parsed_concat_14<br />
E/mobile-ffmpeg: Error reinitializing filters!<br />
E/mobile-ffmpeg: Failed to inject frame into filter network: Invalid argument<br />
E/mobile-ffmpeg: Error while processing the decoded data for stream #2:0<br />
最佳答案
concat 过滤器的所有输入必须具有相同的大小(宽度 x 高度)和纵横比。您不需要连接。你需要叠加。使用动画scale与 overlay反而。简体 ffmpeg
3 个图像的命令行示例,从 0 缩放到 100%,覆盖在背景图像上。
ffmpeg -loop 1 -t 10 -i background.jpg -loop 1 -i img1.png -loop 1 -i img2.jpg -loop 1 -i img3.jpg -filter_complex "[1]scale=eval=frame:w='min(iw*t,iw)':h=-1[img1];[2]scale=eval=frame:w='min(iw*t,iw)':h=-1[img2];[3]scale=eval=frame:w='min(iw*t,iw)':h=-1[img3];[0][img1]overlay=(W-w)/2:(H-h)/2:shortest=1:format=auto[bg];[bg][img2]overlay=shortest=1:format=auto[bg2];[bg2][img3]overlay=W-w:H-h:shortest=1:format=auto,format=yuv420p" output.mp4
关于video - 在视频中的 Ffmpeg 中重新缩放或动态缩放图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65825692/