ffmpeglavfilters

Ffmpeg/lavfi Is it possible to fade out an image overlay that was loaded with a movie= filter not a -i parameter


I've tried something like:

movie='overlaylogo.png',fade=out:st=5:d=1[logo],[in][logo]overlay='0:0'[out]

But it seems to stick on 100% opacity, adding in a loop=loop-1 and fps=24 filter after the movie= load seem to have little effect, is there some step required to convert an image into a video for fade to apply over?


Solution

  • The key is to keep your stream alive so the fade filter can do its job. An image input dies immediately after it sends out its frame.

    With -i we'd do

    ffmpeg -i input.mp4 -loop 1 -i logo.png \
           -filter_complex [1:v]fade=out:st=5:d=1:alpha=1,[0:v]overlay=0:0:shortest=1[out] \
           -map [out] -map 0:a output.mp4
    

    The -loop image2 input option keeps the stream alive. The same thing must be done with movie source filter. It has loop option but with a caveat: "Note that when the movie is looped the source timestamps are not changed, so it will generate non monotonically increasing timestamps." So, you need to add setpts filter to establish monotonically increasing timestamps yourself:

    ffmpeg -i input.mp4 \
           -vf movie=logo.png:loop=0,setpts=N/FR/TB,fade=out:st=5:d=1,[in]overlay=0:0:shortest=1[out] \
           output.mp4
    

    P.S., loop=-1 (not 1) should also work (and it likely won't need the setpts filter to fix the timestamp).