1

I am currently using the command from this question to crossfade two videos:

crossfade between 2 videos using ffmpeg

My command:

ffmpeg -i firstVideo.mp4 -i secondVideo.mp4 -f lavfi -i color=black -    filter_complex \
"[0:v]format=pix_fmts=yuva420p,fade=t=out:st=4:d=1:alpha=1,setpts=PTS-STARTPTS[va0];\
[1:v]format=pix_fmts=yuva420p,fade=t=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS+4/TB[va1];\
[2:v]scale=640x360,trim=duration=9[over];\
[over][va0]overlay[over1];\
[over1][va1]overlay=format=yuv420[outv]" \
 -vcodec libx264 -map [outv] output.mp4

This crossfade animation works fine, except for it shrinks the video to 480x360 instead of the desired 640x360. The meta information will falsely show that the dimensions are 640x360, but I am certain they are not.

I am also certain that both input videos are exactly 640x360.

I am guessing that the shrinking is due to the pixel format yuva420p, but I'm not sure what other options I have. I have tried changing the pixel format but nothing has worked so far.

The command given above runs without any errors.

1

Use

ffmpeg -i firstVideo.mp4 -i secondVideo.mp4 -f lavfi -i "color=black:s=640x360:d=9" 
-filter_complex \
"[0:v]format=pix_fmts=yuva420p,fade=t=out:st=4:d=1:alpha=1,setpts=PTS-STARTPTS[va0];\
[1:v]format=pix_fmts=yuva420p,fade=t=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS+4/TB[va1];\
[2:v][va0]overlay[over1];\
[over1][va1]overlay=format=yuv420[outv]" \
 -vcodec libx264 -map [outv] output.mp4

The color filter outputs a 320x240 video unless specified otherwise. The scale filter seeks to preserve the source aspect ratio - 4:3 in this case, so the video is encoded as 640x360 but with a display aspect ratio of 4:3 so shows as 480x360.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.