Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#8468 closed defect (worksforme)

VP9 will not encode in yuva420p

Reported by: David Oard Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

I need to convert prores yuva videos to VP9 webm and preserve the alpha channel. The encoder (libvpx-vp9) says it supports yuva420p but the output video is yuv420p.

Show that my build supports yuva420p encoding

% ffmpeg.exe -help encoder=libvpx-vp9
ffmpeg version n4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.0 (Rev2, Built by MSYS2 project)
  configuration: --arch=x86_64 --target-os=mingw32 --enable-runtime-cpudetect --enable-pthreads --enable-nonfree --disable-w32threads --disable-debug --disable-gpl --enable-version3 --disable-doc --enable-libopenh264 --enable-libvpx --enable-libmp3lame --enable-openssl --enable-iconv --enable-libxml2 --enable-libvorbis --enable-libaom --enable-libass --enable-gmp --enable-ffnvcodec --enable-libmfx --enable-nvdec --enable-cuvid --enable-dxva2 --enable-libsrt --enable-d3d11va --enable-shared --enable-static --enable-decklink --extra-cflags='-O3 -w -ftree-vectorize -DLIBXML_STATIC -DWINVER=0x0A00 -D_WIN32_WINNT=0x0A00 -I../Blackmagic_DeckLink_SDK_10.11.4/Win/include' --extra-ldflags='-static-libgcc -static-libstdc++ -L../Blackmagic_DeckLink_SDK_10.11.4/Win/include' --prefix=../../../Build/ffmpeg_4.2.2/x64
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
Encoder libvpx-vp9 [libvpx VP9]:
    General capabilities: delay threads
    Threading capabilities: auto
    Supported pixel formats: yuv420p yuva420p yuv422p yuv440p yuv444p yuv420p10le yuv422p10le yuv440p10le yuv444p10le yuv420p12le yuv422p12le yuv440p12le yuv444p12le gbrp gbrp10le gbrp12le

Command to encode

% ffmpeg -i "D:\Videos\str_0010_introTransition_prores4444_v001.mov" -y -an -vcodec libvpx-vp9 -b:v 0 -tile-columns 6 -crf 18 -pix_fmt yuva420p "D:\Videos\str_0010_introTransition_test.webm"

Output from ffmpeg: Note that it says it's encoding with pixel format yuva420p

[libvpx-vp9 @ 000001be1f1f2900] v1.8.1-133-g802569640
Output #0, webm, to 'D:\Videos\str_0010_introTransition_test.webm':
  Metadata:
    major_brand     : qt
    minor_version   : 512
    compatible_brands: qt
    uk.co.thefoundry.Application: Nuke
    uk.co.thefoundry.ApplicationVersion: 9.0v7
    uk.co.thefoundry.YCbCrMatrix: Rec 709
    uk.co.thefoundry.Colorspace: sRGB
    uk.co.thefoundry.Writer: mov64
    encoder         : Lavf58.29.100
    Stream #0:0(eng): Video: vp9 (libvpx-vp9), yuva420p, 12544x1792 [SAR 1:1 DAR 7:1], q=-1--1, 24 fps, 1k tbn, 24 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.54.100 libvpx-vp9
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame=   44 fps=1.4 q=0.0 size=       1kB time=00:00:00.79 bitrate=  10.0kbits/s speed=0.0249x

Verify pixel format encoded in output video

% ffmpeg -i "D:\Videos\str_0010_introTransition_test.webm"

Output: Note that pixel format is now yuv420p, no alpha

ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.1.1 (GCC) 20190807
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, matroska,webm, from 'D:\Videos\str_0010_introTransition_test.webm':
  Metadata:
    UK.CO.THEFOUNDRY.WRITER: mov64
    MAJOR_BRAND     : qt
    MINOR_VERSION   : 512
    COMPATIBLE_BRANDS: qt
    UK.CO.THEFOUNDRY.APPLICATION: Nuke
    UK.CO.THEFOUNDRY.APPLICATIONVERSION: 9.0v7
    UK.CO.THEFOUNDRY.YCBCRMATRIX: Rec 709
    UK.CO.THEFOUNDRY.COLORSPACE: sRGB
    ENCODER         : Lavf58.29.100
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv), 12544x1792, SAR 1:1 DAR 7:1, 24 fps, 24 tbr, 1k tbn, 1k tbc (default)
    Metadata:
      alpha_mode      : 1
      HANDLER_NAME    : VideoHandler
      ENCODER         : Lavc58.54.100 libvpx-vp9
At least one output file must be specified

Change History (3)

comment:1 by David Oard, 4 years ago

Looking at the output I noticed metadata contains "alpha_mode : 1" which tells me that there maybe alpha data encoded in the video but not used by default. My question would be how do I tell the decoder in C code to add the alpha information into AVFrame? I'd be happy with command line as well.

comment:2 by Carl Eugen Hoyos, 4 years ago

Component: ffmpegundetermined
Resolution: worksforme
Status: newclosed
Version: 4.2unspecified

For future tickets: Please remember that only current FFmpeg git head is supported on this bug tracker.

I am sure your output file does contain transparency information but the native vp9 decoder does not support decoding it, see ticket #8344.

comment:3 by David Oard, 4 years ago

Thank you! That gave me enough clues to move forward. I changed my code from native decoder to libvpx decoder which provides alpha.

AVCodec* pCodec = avcodec_find_decoder_by_name("libvpx-vp9");


Note: See TracTickets for help on using tickets.