将webm视频分割为具有透明度的png

时间:2014-03-18 16:15:29

标签: video ffmpeg png alpha-transparency webm

我需要将webm个编码视频拆分为png帧,而不会失去透明度。我使用以下ffmpeg命令:

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

这会生成一个png目录,但为什么每个输出帧都缺少透明度?

我使用了this示例视频,其中包含一个Alpha通道。看到它在后台播放here。这是ffmpeg的示例输出框架:

missing transparency?

ffmpeg在运行时会产生以下输出:

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)

在输出png上运行identify会产生以下结果:

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

file有关png的说法:

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

一切看起来都对我而言,为什么输出图像不包含alpha通道?

3 个答案:

答案 0 :(得分:3)

自2016-07-20以来,可以使用alpha通道(VP8a或VP9a)正确解码webm,但需要-vcodec libvpx选项。您必须下载在该日期之后编译的 FFmpeg (或使用最新的提交进行编译),并在创建frames文件夹后,使用以下命令:

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

请注意,-vcodec libvpx 之前是,而不是之后。

答案 1 :(得分:1)

使用此命令,我可以从webm获得透明的png,并且没有错误:

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

答案 2 :(得分:0)

看起来你的WebM视频实际上没有alpha通道:

Stream#0:0(eng):视频:vp8, yuv420p

你会看到

Stream#0:0(eng):视频:vp8, yuva420p 如果有的话。

如果我看到一个带有alpha的WebM文件,我会欣喜若狂 - 花了最后24小时尝试使用ffmpeg从alpha转换为flv失败: