Working with FFmpeg and transparency feels simple—until the output is wrong. Whether you are processing PNG sequences, WebM videos, or alpha-enabled MP4 alternatives, handling transparent backgrounds demands precision in both codec choice and command structure. Mistakes here cause flattened visuals, bad colors, or unexpected black fills where transparency should live.
Transparency in FFmpeg depends on proper pixel format control. Formats like yuva420p preserve the alpha channel, while defaults like yuv420p strip it away. Choosing the right codec is equally vital: WebM with VP8/VP9 or ProRes 4444 handles transparency, while most common MP4/H.264 settings do not. You control this with clear, explicit flags:
ffmpeg -i input.mov -c:v libvpx-vp9 -pix_fmt yuva420p output.webm
Here, the -pix_fmt yuva420p ensures the alpha channel survives. Without it, transparency is lost, even if the codec supports it.
For image sequences, FFmpeg can assemble frames with alpha while preserving sharp edges. PNG still stands strong for lossless alpha, but WebP offers efficiency for web use: