Splitting webm video to png with transparency

有些话、适合烂在心里 提交于 2021-02-07 08:11:38

问题


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?


回答1:


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.




回答2:


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 :(




回答3:


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



来源:https://stackoverflow.com/questions/22485022/splitting-webm-video-to-png-with-transparency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!