ffmpegvideo-encoding

Convert WEBM to HEVC with alpha


I'm trying to convert a simple WEBM video with transparency to HEVC with alpha. I couldn't find any resources about how to convert without losing the alpha channel.

I don't know if it's possible with FFMPEG:

encoding requests cannot be made here as FFmpeg does not contain a native hevc encoder.

cf. https://trac.ffmpeg.org/ticket/7965


Solution

  • VideoToolbox supports alpha / transparency

    FFmpeg does not have its own HEVC/H.265 encoder. It supports 7 HEVC/H.265 external encoders (most are hardware based) including libx265 which does not currently support alpha.

    As of now only the VideoToolbox HEVC Encoder (-c:v hevc_videotoolbox) supports alpha. This is a hardware accelerated encoder for Apple hardware. This has been updated after FFmpeg 4.3 was released, so you'll have to use a build from the current git branch, or wait for 4.4.

    Example command adapted from the relevant commit:

    ffmpeg -i input%03d.png -c:v hevc_videotoolbox -allow_sw 1 -alpha_quality 0.75 -vtag hvc1 output.mov
    

    The "HEVC Video with Alpha" profile will only be used when the -alpha_quality value is not 0 (default is 0, range 0-1.). See ffmpeg -h encoder=hevc_videotoolbox for more info.

    This answer may become outdated due to continuous developments, so make sure to research the current situation.

    Checking if an encoder supports alpha / transparency

    $ ffmpeg -h encoder=libx265
    Supported pixel formats: yuv420p yuvj420p yuv422p yuvj422p yuv444p yuvj444p gbrp yuv420p10le yuv422p10le yuv444p10le gbrp10le yuv420p12le yuv422p12le yuv444p12le gbrp12le gray gray10le gray12le
    

    If it supported alpha it would have pixel format with an a in the name, such as yuva420p or rgba. As you can see libx265 does not yet support alpha.

    Related bug reports to watch