Convert mp4 to webm with transparency?

2019-03-30 20:35发布

问题:

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:

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

Parts are seperated by :. The first part is the key color. The color

0x00ff00

is green.

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