Search code examples
ffmpegwebm

Convert one PNG image to webm video with transparency and fade in and out effect


I have an image named c.png First I convert it to webm with transparency, use command:

ffmpeg -framerate 1/9 -i c.png  -i c.mp3 -c:v libvpx-vp9 -pix_fmt yuva420p -lossless 1 out.webm

Then I want add fade in and fade out to out.webm, but I used many command like this still not working:

ffmpeg  -i out.webm -vf "fade=t=in:st=0:d=3:alpha=1" -c:v libvpx-vp9 -pix_fmt yuv420p -c:a copy out_ok.webm
ffmpeg -i out.webm -vf "fade=in:0:3:alpha=1" out3.webm

ffmpeg -c:v libvpx-vp9 -i out.webm -vf "fade=t=in:st=0:d=3:alpha=1" out_ok.webm

ffmpeg -c:v libvpx-vp9 -i out.webm -filter_complex "fade=t=in:st=0:d=3:alpha=1" -map "[v]" -lossless 1  -b 10M -r 30 all.web

How do I fix that?

Thank you.


Solution

  • You can do it with 1 command. In this example audio.mp3 is 10 seconds long.

    ffmpeg -loop 1 -framerate 15 -i input.png -i audio.mp3 -vf "fade=t=in:d=1:alpha=1,fade=t=out:d=1:st=9:alpha=1" -shortest -fflags +shortest -max_interleave_delta 100M output.webm
    
    • Your command made an output with only 1 frame of video. Add the -loop option to loop the image.
    • The -shortest -fflags +shortest -max_interleave_delta 100M options (see more info about these options) make the video match the audio duration.