3

I'm trying to convert a webm file that has a transparent background to an mp4 file. Mp4 doesn't have transparency so I'm trying to using this color: #D9DADB. How can I make this conversion happen with a single command in ffmpeg?

I've tried the following command and I seem to get a black background instead of a gray one:

ffmpeg -f lavfi -i color=c=0xD9DADB -i 123.webm 123.mp4

1 Answer 1

4

The native VP8/9 decoders don't support transparency, so a) you'll have to force a decoder, b) the way to change transparent pixels is to overlay the video onto the color.

ffmpeg -c:v libvpx -i 123.webm -f lavfi -i color=c=0xD9DADB,format=rgb24
       -filter_complex "[1][0]scale2ref[bg][vid];[bg][vid]overlay=format=rgb:shortest=1,setsar=1"
       -pix_fmt yuv420p -c:a copy 123.mp4
3
  • this is great - just 2 problems though. 1) the rendering doesn't stop - it can go well past the final frame. 2) the resolution is different than the original. I'm guessing its because of the pix_fmt argument? How can i set specific dimensions for the final image?
    – Parris
    Jan 29, 2019 at 20:58
  • 1
    1) corrected, 2) not because of that, also corrected
    – Gyan
    Jan 29, 2019 at 21:03
  • If your WebM isn't using VP8 but instead VP9, you need to replace -c:v libvpx with -c:v libvpx-vp9. Mar 14, 2022 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.