Convert PNGs to webm video with transparency

22,099

Solution 1

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

Solution 2

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.

Share:
22,099
sebastian
Author by

sebastian

Updated on July 09, 2022

Comments

  • sebastian
    sebastian almost 2 years

    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
    sebastian over 8 years
    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
  • Gyan
    Gyan over 8 years
    Switch to a recent ffmpeg build and try.
  • sebastian
    sebastian over 8 years
    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
    sebastian over 8 years
    In your answer (updated now) you wrote avconv instead of ffmpeg. So I used avconv, too. Working with ffmpeg, thanks!
  • Jason Pratt
    Jason Pratt about 7 years
    I needed to use '-metadata:s:v:0 alpha_mode="1"' as mentioned here to get alpha to work for VP8.
  • Gyan
    Gyan about 7 years
    Works here, without. Which version of ffmpeg and libvpx?
  • Kagami Sascha Rosylight
    Kagami Sascha Rosylight over 6 years
    For anyone frustrated on Ubuntu LTS: VP9+alpha doesn't work on ffmpeg 2.8.x, you should get ffmpeg 3.x.
  • Alex
    Alex over 6 years
    I added -b:v 800k for an increased video bit rate to get a better image quality. The default wasn't good enough.
  • matteo
    matteo almost 6 years
    Works for me, but produces an output with garbage quality. How do you set a decent quality or configure the bitrate?
  • Gyan
    Gyan almost 6 years
    Set the bitrate e.g. -b:v 2M for 2 mbps.
  • JavaRunner
    JavaRunner about 3 years
    Doesn't work for me. ffmpeg 4.3.2, video doesn't transparent.