Search code examples
ffmpegvideo-processingtransparentalpha-transparency

Convert Transparent PNGs to a Transparent Video


I have a set of transparent PNG pictures, and I want to convert them into a video with transparent background (play the PNGs continuously).

First, I used ffmpeg with the terminal command:

ffmpeg -framerate 30 -pattern_type glob -i '*.png' \-c:v libx264 -pix_fmt yuva420p out.mp4

And I learnt that the codec libx264 does not compatible with the alpha channel. Then, I changed to another codec and used the following command:

ffmpeg -framerate 30 -pattern_type glob -i '*.png' \-c:v libvpx-vp9 -pix_fmt yuva420p out.mp4

However, QuickTime Player cannot play the resulting out.mp4. I don't know if it was because the video conversion failed or it was the fault of QuickTime Player. The terminal didn't show any error message, though.

Therefore, I would like to ask:

  1. Which codec I should use to create a transparent video that a normal video player can play?

  2. Can the output MP4 video format support transparent videos?

  3. If there is another tool that is far more superior than ffmpeg for my purpose, I am willing to give it a try.

Thank you for any advice.

All the best,

Aurora


Solution

  • few formats and video encoders support transparency:

    -c:v prores -pix_fmt yuva444p10le logo.mov
    -c:v ffv1 -pix_fmt yuva420p logo.mkv
    

    and, with bad compatibility

    -c:v libvpx-vp9 -pix_fmt yuva420p logo.webm
    -c:v apng -pix_fmt rgba logo.apng