video - 在视频中的 Ffmpeg 中重新缩放或动态缩放图像

标签 video ffmpeg

我尝试使用 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 高度)和纵横比。您不需要连接。你需要叠加。使用动画scaleoverlay反而。简体 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
  • FFmpeg Expressions
  • How to place overlay
  • 关于video - 在视频中的 Ffmpeg 中重新缩放或动态缩放图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65825692/

    相关文章:

    java - javafx media可以播放mp4格式的视频文件吗?

    php - 如何在视频上传时创建缩略图?

    html - Firefox 和 IE 中的 MP4 视频不考虑旋转

    javascript - AngularJS 在不活动后显示视频,隐藏视频并重置为点击开始

    ios - 由图像组成的AVPlayerItem

    ffmpeg - "does not contain any stream"如果 "EXT-X-MEDIA-SEQUENCE"> 0

    audio - 将各种音频和视频源混合成一个视频

    python - 终止子进程后终端文本变得不可见

    video - 没有扩展名的 FFmpeg 输出文件格式

    video - 在WhatsApp上共享链接时如何更新youtube视频图像和描述?