JavaEar 专注于收集分享传播有价值的技术资料

Convert mp4 to webm with transparency?

I know how to convert mp4 to webm with ffmpeg:

ffmpeg -y -i me939371029.mp4 -r 30  out3.webm

But I'd like to use webm transparency. That guide uses Blender, but Blender's a desktop tool that's not easily automated and only outputs PNGs that must be converted to video. I'd like a command line app that accepts video in, a color, and a video out. E.g.:

some-app -i video.mp4 -transparent ff0000 -o video.webm

I'd be surprised if something like this wasn't already in ffmpeg, but I can't seem to find it.

1个回答

    最佳答案
  1. Assuming the color to be keyed out is 00ff00, use

    ffmpeg -i input.mp4 -c:v libvpx -vf "colorkey=0x00ff00:0.1:0.1,format=yuva420p" out.webm
    

    In colorkey=0x00ff00:0.1:0.1

    the first argument is the key color;

    the 2nd is similarity

    0.01 matches only the exact key color, while 1.0 matches everything.

    and the 3rd is blend percentage

    0.0 makes pixels either fully transparent, or not transparent at all.

    Higher values result in semi-transparent pixels, with a higher transparency the more similar the pixels color is to the key color.

    See the ffmpeg colorkey documentation