FFmpeg: Video with crossfade slides and Move up / Move Down effect doesn't work correctly

3

I'm creating video from the images which have different sizes and orientations. Actually, I need to do video slides' animations based on the image orientation (aspect ratio). So, let's say I have 4 images with the following sizes:

1.jpg 1280x1600 ( Top to bottom )
2.jpg 1280x1600 ( Bottom to Top )
3.jpg 1280x1600 ( Top to bottom )
4.jpg 1280x1280 ( No effect )

Here is the FFmpeg command which I'm running

ffmpeg -y -r 25 \ 
-loop 1 -t 5 -i 1.jpg \
-loop 1 -t 5 -i 2.jpg \
-loop 1 -t 5 -i 3.jpg \
-loop 1 -t 5 -i 4.jpg \
-i audio.mp3 \
-filter_complex " \
[0]crop=1280:1280:ow:((ih-oh)/5)*t,format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+0/TB[f0];
[1]crop=1280:1280:ow:(ih-oh)-((ih-oh)*t/5),format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+4/TB[f1];
[2]crop=1280:1280:ow:((ih-oh)/5)*t,format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+8/TB[f2];
[3]fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+12/TB[f3];
[0][f0]overlay[bg1];[bg1][f1]overlay[bg2];[bg2][f2]overlay[bg3];[bg3][f3]overlay,format=yuv420p[v]" -map "[v]" -map 4:a -b:v 4000k -movflags +faststart -t 20 -s 1280x1280 out.mp4

Please have a look at the first seconds of the video

enter image description here

So, the crossfade, crop and the effect are working but as you can see, it keeps an unnecessary section at the bottom of the video. All other animations are shown in the above section

enter image description here

Not sure, but seems it's keeping the first image height (1600)? Looking forward to any suggestion to fix this issue

ArmKh

Posted 2020-02-01T08:04:03.843

Reputation: 99

Answers

2

Use the xfade filter:

enter image description here

ffmpeg \
-loop 1 -t 5 -i cyan.jpg \
-loop 1 -t 5 -i magenta.jpg \
-loop 1 -t 5 -i yellow.jpg \
-loop 1 -t 5 -i black.jpg \
-i audio.mp4
-filter_complex \
"[0]crop=1280:1280[v1]; \
 [1]crop=1280:1280[v2]; \
 [2]crop=1280:1280[v3]; \
 [3]crop=1280:1280[v4]; \
 [v1][v2]xfade=wipedown:duration=1:offset=4[x1]; \
 [x1][v3]xfade=wipeup:duration=1:offset=8[x2]; \
 [x2][v4]xfade=wipedown:duration=1:offset=12,format=yuv420p[v]" \
-map "[v]" -map 4:a -movflags +faststart -shortest output.mp4

You can see a gallery of all transitions at FFmpeg Wiki: xfade.

llogan

Posted 2020-02-01T08:04:03.843

Reputation: 31 929

Seems that xfade is a new filter? I was needed to update the ffmpeg and it works perfectly. The animations up / down via crop and about 20 fade options. Saved my day. Thank you! – ArmKh – 2020-02-04T05:46:07.770

2@ArmKh Yes, it is less than a week old. – llogan – 2020-02-04T18:22:42.710