16

I would like to use avconv to convert a series of PNG images to a WebM video, preserving transparency.

I understand that the pixel format used in the output video must support transparency. So I tried:

$ avconv -framerate 25 -f image2 -i frames/%03d.png -pix_fmt yuva420p output.webm

Unfortunately, avconv complains:

Incompatible pixel format 'yuva420p' for codec 'libvpx-vp9', auto-selecting format 'yuv420p'

I am using ffmpeg version 2.8.4-1+b1 Copyright (c) 2000-2015 the FFmpeg developers.

1

3 Answers 3

24

With VP8:

ffmpeg -framerate 25 -f image2 -i frames/%03d.png -c:v libvpx -pix_fmt yuva420p output.webm

Edit: Now, with VP9

ffmpeg -framerate 25 -f image2 -i frames/%03d.png -c:v libvpx-vp9 -pix_fmt yuva420p output.webm
9
  • Thanks for the insight. Can't get it to work though, if I run your command, avconv complains that Specified pix_fmt is not supported. I am using avconv version 9.18-6:9.18-0ubuntu0.14.04.1, Copyright (c) 2000-2014
    – sebastian
    Commented Jan 25, 2016 at 12:15
  • Switch to a recent ffmpeg build and try.
    – Gyan
    Commented Jan 25, 2016 at 12:17
  • Still no luck. I am using avconv version 11.3-6:11.3-1~trusty now and still get Specified pix_fmt is not supported.
    – sebastian
    Commented Jan 25, 2016 at 12:32
  • In your answer (updated now) you wrote avconv instead of ffmpeg. So I used avconv, too. Working with ffmpeg, thanks!
    – sebastian
    Commented Jan 25, 2016 at 14:13
  • 3
    For anyone frustrated on Ubuntu LTS: VP9+alpha doesn't work on ffmpeg 2.8.x, you should get ffmpeg 3.x. Commented Sep 1, 2017 at 5:14
15

Since 2016-07-13, it's possible to encode VP9/webm videos with alpha channel (VP9a).

You only need a copy of ffmpeg compiled after that date. By the way, all you need to write is:

ffmpeg -i frames/%03d.png output.webm

FFmpeg understands png format and will set a default framerate of 25 fps and a yuva420p pixel format to the output.

2
  • 4
    I added -b:v 800k for an increased video bit rate to get a better image quality. The default wasn't good enough.
    – Alex
    Commented Jan 28, 2018 at 21:55
  • Doesn't work for me. ffmpeg 4.3.2, video doesn't transparent.
    – JavaRunner
    Commented Mar 27, 2021 at 3:44
1

You can also convert a video wich allready contains an alpha channel to a webm video with transparency with this command:

ffmpeg -i myVideoWithAlphaChannel.mov -c:v libvpx -vf format=rgba myVideoWithAlphaChannel.mov.webm

The format of myVideoWithAlphaChannel.mov (generated with Blender3D) is:

  • "Quicktime" format
  • "PNG" Codec

With as Ouputs:

  • H.264
  • RGBA

Here Blender 3D rendering configuration

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