14

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.

sebastian
  • 1,438
  • 1
  • 15
  • 23

3 Answers3

22

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
Gyan
  • 85,394
  • 9
  • 169
  • 201
  • 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 Jan 25 '16 at 12:15
  • Switch to a recent ffmpeg build and try. – Gyan Jan 25 '16 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 Jan 25 '16 at 12:32
  • In your answer (updated now) you wrote `avconv` instead of `ffmpeg`. So I used `avconv`, too. Working with ffmpeg, thanks! – sebastian Jan 25 '16 at 14:13
  • I needed to use '-metadata:s:v:0 alpha_mode="1"' as mentioned [here](https://trac.ffmpeg.org/wiki/Encode/VP8) to get alpha to work for VP8. – Jason Pratt May 17 '17 at 13:16
  • Works here, without. Which version of ffmpeg and libvpx? – Gyan May 17 '17 at 13:52
  • 3
    For anyone frustrated on Ubuntu LTS: VP9+alpha doesn't work on ffmpeg 2.8.x, you should get ffmpeg 3.x. – Kagami Sascha Rosylight Sep 01 '17 at 05:14
  • Works for me, but produces an output with garbage quality. How do you set a decent quality or configure the bitrate? – matteo Jul 11 '18 at 09:20
  • Set the bitrate e.g. `-b:v 2M` for 2 mbps. – Gyan Jul 11 '18 at 10:07
14

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.

cdlvcdlv
  • 952
  • 1
  • 9
  • 22
0

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

mosis
  • 31
  • 7