Search code examples
videoffmpegwebm

Converting transparent PNGs to WEBM with alpha: ffmpeg doesn't clear pixels from previous frames which are transparent in in next frames


When I try to convert a bunch of PNGs with alpha in them, the conversion works but there's this strange behavior where the pixels from previous frames do not get cleared and show up in the next frame where the background should just be fully transparent. It looks exactly the same as if you're drawing frames on top of each other without clearing the whole canvas in-between.

I'm speculating on what happens but I think given a frame N with a pixel RGBA (1, 0, 0, 1) and a frame N+1 with a pixel (0, 0, 0, 0), ffmped produces the second frame as (1, 0, 0, 1) when I want (0, 0, 0, 0).

Any way to force ffmpeg to try and clear all the pixels from the last frame before encoding the new frame?

Command I use:

ffmpeg -vb 20MB -i %04d.png output.webm

ffmpeg version 2.8.4 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 5.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink --enable-zlib
  libavutil      54. 31.100 / 54. 31.100
  libavcodec     56. 60.100 / 56. 60.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 40.101 /  5. 40.101
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
Input #0, image2, from 'mika_%04d.png':
  Duration: 00:00:20.00, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: png, rgba(pc), 1080x1920 [SAR 1:1 DAR 9:16], 25 fps, 25 tbr, 25 tbn, 25 tbc
[libvpx-vp9 @ 04ef83e0] v1.5.0
Output #0, webm, to 'output.webm':
  Metadata:
    encoder         : Lavf56.40.101
    Stream #0:0: Video: vp9 (libvpx-vp9), yuv444p, 1080x1920 [SAR 1:1 DAR 9:16], q=-1--1, 200 kb/s, 25 fps, 1k tbn, 25 tbc
    Metadata:
      encoder         : Lavc56.60.100 libvpx-vp9

Solution

  • I just needed to upgrade to ffmpeg 4.4 and it works fine now.