Splitting webm video to png with transparency
Asked Answered
S

3

8

I need to split a webm encoded video into png frames, without losing transparency. I use the following ffmpeg command:

ffmpeg -i dancer1.webm -pix_fmt rgba frames/%04d.png

This produces a directory of pngs, but why is each output frame is missing transparency?

I have used this example video, which contains an alpha channel. See it playing over a background here. Here's an example output frame from ffmpeg:

missing transparency?

ffmpeg produces the following output when it runs:

ffmpeg version N-60294-g549f052 Copyright (c) 2000-2014 the FFmpeg developers                                             [1/2471]
  built on Feb  2 2014 05:41:56 with gcc 4.6 (Debian 4.6.3-1)
  configuration: --prefix=/root/ffmpeg-static/64bit --extra-cflags='-I/root/ffmpeg-static/64bit/include -static' --extra-ldflags='-L/root/ffmpeg-static/64bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
  libavutil      52. 63.100 / 52. 63.100
  libavcodec     55. 49.101 / 55. 49.101
  libavformat    55. 28.101 / 55. 28.101
  libavdevice    55.  7.100 / 55.  7.100
  libavfilter     4.  1.101 /  4.  1.101
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, matroska,webm, from 'dancer1.webm':
  Metadata:
    encoder         : libwebm-0.2.1.0
  Duration: 00:01:02.83, start: 0.000000, bitrate: 520 kb/s
    Stream #0:0(eng): Video: vp8, yuv420p, 640x360, SAR 1:1 DAR 16:9, 30 tbr, 1k tbn, 1k tbc (default)
    Metadata:
      alpha_mode      : 1
Output #0, image2, to 'frames/%04d.png':
  Metadata:
    encoder         : Lavf55.28.101
    Stream #0:0(eng): Video: png, rgba, 640x360 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 30 tbc (default)
Metadata:
  alpha_mode      : 1
Stream mapping:
  Stream #0:0 -> #0:0 (vp8 -> png)

Running identify on an output png produces this:

$ identify 0001.png
0001.png PNG 640x360 640x360+0+0 8-bit DirectClass 94.1KB 0.000u 0:00.000

file has this to say about the png:

$ file 0001.png
0001.png: PNG image data, 640 x 360, 8-bit/color RGBA, non-interlaced

Everything looks about right to me, so why don't the output images contain an alpha channel?

Stoffel answered 18/3, 2014 at 16:15 Comment(1)
This post over on ffmpeg-users indicates that ffmpeg probably does support decoding alpha from webm: ffmpeg-users.933282.n4.nabble.com/…Stoffel
P
7

Since 2016-07-20, it's possible to decode properly a webm with alpha channel (VP8a or VP9a) but you need -vcodec libvpx option. You must download an FFmpeg compiled after that date (or compile yourself with up-to-date commits) and, after creating the frames folder, use the following command:

ffmpeg -vcodec libvpx -i dancer1.webm frames/%04d.png

Note that -vcodec libvpx is before the input, not after it.

Pyrethrin answered 23/8, 2016 at 22:26 Comment(2)
Error: Failed to decode frame: Bitstream not supported by this decoder. EDIT: Error was solved by using libvpx-vp9 instead of libvpx. I am using ffmpeg on Windows 11.Medallist
Error: Could not open file. One would think that ffmpeg would create a folder if specified in the path like how most programs do, but this is not the case. If the folder frames does not already exist, it will through a misleading, cryptic error.Medallist
T
1

it does not look like your WebM video actually has the alpha channel:

Stream #0:0(eng): Video: vp8, yuv420p

You would see

Stream #0:0(eng): Video: vp8, yuva420p if it did.

I would be ecstatic if I saw a WebM file WITH alpha - spent the last 24 hrs unsuccessfully trying to make one converting from flv with alpha, using ffmpeg :(

Tammietammuz answered 23/7, 2014 at 15:7 Comment(0)
B
1

I was able to obtain the pngs with transparency from a webm with this command and without errors:

ffmpeg -vcodec libvpx-vp9 -i ejemplo.webm -pix_fmt rgba frames/%04d.png

Barden answered 31/8, 2020 at 2:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.