使用Ffmpeg与多个图像进行交叉淡入淡出动画 [英] Crossfade Animation with multiple Images using Ffmpeg

查看:121
本文介绍了使用Ffmpeg与多个图像进行交叉淡入淡出动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ffmpeg创建具有多个图像的视频,并且我引用了给定的链接-

I'm creating video with Multiple images using Ffmpeg and i'm referencing given link -

(请记住,最重要的是所有图像都有不同的大小)

https://superuser.com/a/834035/1243959

现在,我首先要创建带有淡入/淡出动画的视频,为此,我正在使用标题为用于变化大小或任意大小的输入图像的第三代码,并且效果很好-

Now First of all i'm creating video with fade in/out animation and for that i'm using 3rd code with title For input images with varying or arbitrary sizes and it works well -

ffmpeg \
-loop 1 -t 5 -i input0.png \
-loop 1 -t 5 -i input1.png \
-loop 1 -t 5 -i input2.png \
-loop 1 -t 5 -i input3.png \
-loop 1 -t 5 -i input4.png \
-filter_complex \
"[0:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=out:st=4:d=1[v0]; \
 [1:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v1]; \
 [2:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v2]; \
 [3:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v3]; \
 [4:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v4]; \
 [v0][v1][v2][v3][v4]concat=n=5:v=1:a=0,format=yuv420p[v]" -map "[v]" out.mp4

但是当我想使用给定命令在 Cross fade 部分中标题为 MP4 output 的情况下创建Cross Fade动画时,在输出视频中,人像图像适合视频,但是正方形和风景图像正在被裁剪(@llogan已指定,如果图像的大小与我们必须使用与用于淡入/淡出的命令相同的命令不同)-

but when i want to create Cross Fade animation using given command with the title MP4 output in Cross fade section,in output video,portrait images are fits into video,but square and landscape images are getting cropped (@llogan has specified that if images have different sizes than we have to use same command as which is used for fade in/out) -

ffmpeg \
-loop 1 -t 5 -i 1.png \
-loop 1 -t 5 -i 2.png \
-loop 1 -t 5 -i 3.png \
-loop 1 -t 5 -i 4.png \
-loop 1 -t 5 -i 5.png \
-filter_complex \
"[1]format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+4/TB[f0]; \
 [2]format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+8/TB[f1]; \
 [3]format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+12/TB[f2]; \
 [4]format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+16/TB[f3]; \
 [0][f0]overlay[bg1];[bg1][f1]overlay[bg2];[bg2][f2]overlay[bg3]; \
 [bg3][f3]overlay,format=yuv420p[v]" -map "[v]" -movflags +faststart out.mp4

但是我不知道该怎么做,我想我必须首先以一定的比例(例如 1280 * 720 )调整图像的大小,通过这些比例,所有图像的大小和大小都将相同.那么该动画应该应用于这些图像,并且可能会有所不同.该解决方案也可能适用,但是现在我对要做什么感到困惑,因为我尝试了很多解决方案,例如缩放图像和其他一些尝试,而不是一次解决方案有效(也许我什至没有尝试正确)..

But I don't know exactly what to do and I think I have to first fit the images in a certain ratio like 1280 * 720, by which all the images will be the same size and then the animation should be applied to those images and may be different The solution might work too but right now I'm confused as to what to do because I've tried a lot of solutions like scaling images and some other attempts and not a single solution worked (maybe I didn't even try right)..

如果 SAR DAR 不能提供帮助,则如下所示(我不知道这些变量之间的区别):

if SAR and DAR can help than they are as below (I don't know difference between these variables):

SAR 1:1 / DAR 197:295
SAR 1:1 / DAR 2:3
SAR 96:96 / DAR 16:9
SAR 1:1 DAR / 540:961
SAR 1:1 DAR / 2567:3113

任何帮助将不胜感激.谢谢!

Any help will be appreciated..Thank you!

推荐答案

变体2,使用渐变+叠加:

variant 2, using fade+overlay:

#!/bin/bash
ffmpeg \
-loop 1 -t 5 -i 1.png \
-loop 1 -t 5 -i 2.png \
-loop 1 -t 5 -i 3.png \
-loop 1 -t 5 -i 4.png \
-loop 1 -t 5 -i 5.png \-filter_complex "
[0]scale=-2:720,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=d=1:t=in:alpha=1,fade=t=out:st=4:d=1,setpts=PTS-STARTPTS+4/TB[f0];
[1]scale=-2:720,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=d=1:t=in:alpha=1,fade=t=out:st=4:d=1,setpts=PTS-STARTPTS+8/TB[f1];
[2]scale=-2:720,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=d=1:t=in:alpha=1,fade=t=out:st=4:d=1,setpts=PTS-STARTPTS+12/TB[f2];
[3]scale=-2:720,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=d=1:t=in:alpha=1,fade=t=out:st=4:d=1,setpts=PTS-STARTPTS+16/TB[f3];
[4]scale=-2:720,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=d=1:t=in:alpha=1,fade=t=out:st=4:d=1,setpts=PTS-STARTPTS+20/TB[f4];
[f0][f1]overlay[bg1];
[bg1][f2]overlay[bg2];
[bg2][f3]overlay[bg3];
[bg3][f4]overlay,format=yuv420p[v]
" -map [v] -movflags +faststart -y out.mp4

这篇关于使用Ffmpeg与多个图像进行交叉淡入淡出动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆