1

I wrote a small piece of code that crossfades a video clip - you define how long the video should be and how long the crossfade should be.
It works great with videos with no alpha channel.
The problem starts with videos with alpha channel.

Here is the video showing the problem: https://streamable.com/94fxe
The FIRST video is a video with alpha channel
The SECOND video is a video without alpha channel

And here are pieces of code for crossfading opaque videos:

ffmpeg -y -i "%FilePath%" -filter_complex "[0]pad=ceil(iw/4)*4:ceil(ih/4)*4[o];[o]split[tran][body];[body]trim=0:%LoopDuration%,setpts=PTS-STARTPTS,format=yuva420p,fade=d=%TransitionTime%:alpha=1[jt];[tran]trim=%LoopDuration%:%LoopDurationNTransition%,setpts=PTS-STARTPTS[main];[main][jt]overlay" "%looped%\temp.%ext%"

And here is a piece of code that I use to crossfade videos with alpha channel: (the main difference is only the codec I use to output videos with alpha):

ffmpeg -y -i "%FilePath%" -filter_complex "[0]pad=ceil(iw/4)*4:ceil(ih/4)*4[o];[o]split[tran][body];[body]trim=0:%LoopDuration%,setpts=PTS-STARTPTS,format=yuva420p,fade=d=%TransitionTime%:alpha=1[jt];[tran]trim=%LoopDuration%:%LoopDurationNTransition%,setpts=PTS-STARTPTS[main];[main][jt]overlay" -vcodec prores_ks -pix_fmt yuva444p10le -profile:v 4444 -q:v 10 "%looped%\temp.%ext%"

PS Besides using FFMPEG I use also AHK - this is why there are some variables with % around.

Could somebody please tell me where lies the problem? I tried to rewrite this in every possible way I can imagine but I cannot figure it out...

2
  • What I do in this code is I split video to two parts - main long part and short transition part. I use fade parameter to fade alpha. At the end I blend two videos together. This is the logic that works for opaque videos. Please help me figure out why it does not work for videos with transparency. Commented Feb 13, 2020 at 17:09
  • Not clear to me what the issue is - what's the problem?
    – Gyan
    Commented Feb 13, 2020 at 18:00

1 Answer 1

1

Ok, I found what was my problem - I forgot that I need to fade both layers to make a clean crossfade.

So the code for crossfading videos with alpha channel will be:

ffmpeg -y -i "%FilePath%" -filter_complex "[0]pad=ceil(iw/4)*4:ceil(ih/4)*4[o];[o]split[tran][body];[body]trim=0:%LoopDuration%,setpts=PTS-STARTPTS,format=yuva420p,fade=in:d=%TransitionTime%:alpha=1[jt];[tran]trim=%LoopDuration%:%LoopDurationNTransition%,setpts=PTS-STARTPTS,fade=out:d=%TransitionTime%:alpha=1[main];[main][jt]overlay" -vcodec prores_ks -pix_fmt yuva444p10le -profile:v 4444 -q:v 10 "%TempFolder%\temp.%ext%"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .