[Libav-user] Question regarding VP9 (AV_CODEC_ID_VP9) - forcing alpha

David Rappo davidr at lens-immersive.com
Wed Mar 17 08:08:21 EET 2021


Hi,

I wrote a small program based on the FFMPEG example
doc/examples/demuxing_decoding.c to extract the frames from an input video
and save them out as PNG files. This works but the output frames are
missing alpha information.

In this case the input file is WebM and the decoder used is VP9
(AV_CODEC_ID_VP9) so I expect (know) that the input file stores alpha. I
tested this with FFMPEG itself. I have pasted the output at the end of this
email. The key point is that FFMPEG identified the format as yuva420p.

When debugging my program I observed that pCodecContext->pix_fmt was
AV_PIX_FMT_YUV420P - not AV_PIX_FMT_YUVA420P

// Error handling omitted
av_find_best_stream(...)
auto stream = formatContext->streams[streamIndex];
const auto codecIdentifier{ AV_CODEC_ID_VP9 };
auto decoder = avcodec_find_decoder(codecIdentifier);
*codecContext = avcodec_alloc_context3(decoder);
avcodec_parameters_to_context(...);
avcodec_open2(*codecContext, decoder, &options);

// ...

// AV_PIX_FMT_YUV420P - no alpha
const auto pixelFormat = pCodecContext->pix_fmt;

Does anybody know how to force FFMPEG to open the input video such that
alpha is preserved?

Thanks,

FFMPEG output
--- snip ---
 ffmpeg -c:v libvpx-vp9 -i temp/anim.webm temp/output-%3d.png
ffmpeg version N-101533-g637a2ba03d Copyright (c) 2000-2021 the FFmpeg
developers
  built with gcc 10.2.0 (Rev9, Built by MSYS2 project)
  configuration:  --disable-static --enable-shared --pkg-config=pkgconf
--cc='ccache gcc' --cxx='ccache g++' --ld='ccache g++' --disable-autodetect
--enable-amf --enable-bzlib --enable-cuda --enable-cuvid --enable-d3d11va --
enable-dxva2 --enable-iconv --enable-lzma --enable-nvenc --enable-schannel
--enable-zlib --enable-sdl2 --enable-ffnvcodec --enable-nvdec
--enable-cuda-llvm --enable-gmp --enable-libmp3lame --enable-libopus
--enable-libvorbis
 --enable-libvpx --enable-libdav1d --enable-libaom --disable-debug
--enable-libfdk-aac --extra-libs=-liconv --enable-gpl --enable-version3
--enable-nonfree --shlibdir=/local64/bin-video
  libavutil      56. 68.100 / 56. 68.100
  libavcodec     58.131.100 / 58.131.100
  libavformat    58. 74.100 / 58. 74.100
  libavdevice    58. 12.100 / 58. 12.100
  libavfilter     7.109.100 /  7.109.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
[libvpx-vp9 @ 0000024732b106c0] v1.10.0-rc1-11-gcb0d8ce31
    Last message repeated 1 times
Input #0, matroska,webm, from 'temp/anim.webm':
  Metadata:
    ENCODER         : Lavf58.45.100
  Duration: 00:00:04.04, start: 0.000000, bitrate: 112 kb/s
  Stream #0:0: Video: vp9 (Profile 0), yuva420p(tv), 640x480, SAR 1:1 DAR
4:3, 25 fps, 25 tbr, 1k tbn, 1k tbc (default)
    Metadata:
      alpha_mode      : 1
      ENCODER         : Lavc58.91.100 libvpx-vp9
      DURATION        : 00:00:04.040000000
[libvpx-vp9 @ 0000024732b11140] v1.10.0-rc1-11-gcb0d8ce31
Stream mapping:
  Stream #0:0 -> #0:0 (vp9 (libvpx-vp9) -> png (native))
Press [q] to stop, [?] for help
[libvpx-vp9 @ 0000024732b11140] v1.10.0-rc1-11-gcb0d8ce31
Output #0, image2, to 'temp/output-%3d.png':
  Metadata:
    encoder         : Lavf58.74.100
  Stream #0:0: Video: png, rgba(pc, progressive), 640x480 [SAR 1:1 DAR
4:3], q=2-31, 200 kb/s, 25 fps, 25 tbn (default)
    Metadata:
      alpha_mode      : 1
      DURATION        : 00:00:04.040000000
      encoder         : Lavc58.131.100 png
frame=  101 fps=0.0 q=-0.0 Lsize=N/A time=00:00:04.04 bitrate=N/A
speed=7.73x

--- snip ---
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20210317/3865f258/attachment.html>


More information about the Libav-user mailing list