1

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)?

c-an
  • 2,036
  • 1
  • 17
  • 46

1 Answers1

3

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
Hernán Alarcón
  • 1,336
  • 8
  • 10
  • Is there a simple way to convert all the files to webmp in the folder? I tried `ffmpeg -i *.png *.webp` It doesn't work. – c-an Aug 24 '20 at 08:24
  • 1
    @c-an probably using the `find` command with the `-exec` option. You could take a look at [this answer](https://superuser.com/a/566200) or [this guide](https://www.oracle.com/technical-resources/articles/calish-find.html). – Hernán Alarcón Aug 24 '20 at 13:35
  • 2
    @c-an See [How do you convert an entire directory with ffmpeg?](https://stackoverflow.com/a/33766147/) – llogan Aug 24 '20 at 18:05