c-an
c-an

Reputation: 4090

How can I convert WebM file to WebP file with transparency?

I tried it with ffmpeg.

ffmpeg input.webm output.webp

input.webm contains transparent background and But the alpha channel becomes white in webp. I think that means alpha channel doesn't come together.

I extracted frames with this command:

ffmpeg -i input.xxx -c:v libwebp output_%03d.webp

And it also gives me webp files with white background.

How can I convert it properly with alpha channel? OR should I convert it from other format(extension)?

Upvotes: 3

Views: 7566

Answers (1)

Hernán Alarcón
Hernán Alarcón

Reputation: 4109

Use the -c:v libvpx option before the input to change the decoder like in this example for the first frame (-frames:v 1):

ffmpeg -c:v libvpx -i input.webm -frames:v 1 -c:v libwebp -y output.webp

This comment says that:

FFmpeg's native VPx decoders don't decode alpha. You have to use the libvpx decoder

You can check your decoders using ffmpeg -decoders | grep libvpx and you should see an output like this:

 V....D libvpx               libvpx VP8 (codec vp8)
 V....D libvpx-vp9           libvpx VP9 (codec vp9)

According to that output, libvpx would be the decoder for VP8 and libvpx-vp9 for VP9.

You can check the codec of your video using ffprobe input.webm. You should see an output like this:

    Stream #0:0(eng): Video: vp8, yuv420p(progressive), 640x360, SAR 1:1 DAR 16:9, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
    Metadata:
      alpha_mode      : 1

For converting a whole webm (VP8) to an animated webp use:

ffmpeg -c:v libvpx -i input.webm output.webp

For converting a whole webm (VP9) to an animated webp use:

ffmpeg -c:v libvpx-vp9 -i input.webm output.webp

Upvotes: 8

Related Questions