ffmpegfluent-ffmpeg

FFmpeg: Change the timing/easing of an XFade transition in FFmpeg


Given an xfade transition filter such as this:

ffmpeg -loop 1 -t 5 -i 1.png -loop 1 -t 5 -i 2.png -filter_complex "[0][1]xfade=transition=slideleft:duration=1:offset=4,format=yuv420p" output.mp4

Is it possible to alter the timing/easing of the xfade transition? For instance, the above slideleft transition seems to be linear in the output video. How could one achieve a non-linear easing such as a cubic ease in for the transition between the two clips?


Solution

  • xfade custom transition, slideleft with easing

    ffmpeg \
    -loop 1 -t 1.1 -i in1.png \
    -loop 1 -t 1.1 -i in2.png \
    -filter_complex "
    [0]scale=-2:720,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1[v0];
    [1]scale=-2:720,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1[v1];
    [v0][v1]xfade=duration=1:offset=0.1:transition=custom:
    expr='
    if(lt(X+W*pow(1-P,3),W),
     if(eq(PLANE,0),a0(X+W*pow(1-P,3),Y),0)
    +if(eq(PLANE,1),a1(X+W*pow(1-P,3),Y),0)
    +if(eq(PLANE,2),a2(X+W*pow(1-P,3),Y),0)
    +if(eq(PLANE,3),a3(X+W*pow(1-P,3),Y),0)
    ,if(eq(PLANE,0),b0(X-W+W*pow(1-P,3),Y),0)
    +if(eq(PLANE,1),b1(X-W+W*pow(1-P,3),Y),0)
    +if(eq(PLANE,2),b2(X-W+W*pow(1-P,3),Y),0)
    +if(eq(PLANE,3),b3(X-W+W*pow(1-P,3),Y),0)
    )'
    " -y /tmp/output.mp4
    ffplay -loop 0 /tmp/output.mp4