You are currently here!
  • Home
  • Zond 265Checking HEVC with Alpha Channel Support
image

Checking HEVC with Alpha Channel Support

24.10.2024 Alexander Bogomolov 72 Comments Off

High-Efficiency Video Coding (HEVC), also known as H.265, offers advanced compression capabilities, but incorporating transparency (alpha channel) within an HEVC stream is a technical challenge. This article explores how to encode HEVC with alpha channels using the x265 encoder, extract YUVA (YUV + alpha) data with FFmpeg, and verify transparency in different formats, such as VP9. We’ll also review the limitations of current tools in handling alpha channels, particularly in FFmpeg and Zond 265.

Encoding HEVC with Alpha Channel using x265

X265 encoder will be used to test a compression of the video with transparency to HEVC. It can be downloaded from VideoLAN. The encoder version used for this test was from the commit 26d2bab00 (dated 2024-10-04), built with the ENABLE_ALPHA option under Windows. Prepared raw YUVA420p data where alpha channel values varied across the frame. Encoding this into an HEVC stream with alpha is performed with the following command:

x265.exe --input-res 1920x1080 --fps 30 --input input.yuva --alpha --output output.h265

x265_log

This produces a 1920×1080 H.265 elementary stream with an alpha channel. You can download it here.

Extracting YUVA data via FFmpeg

Extracting YUVA420p data from the encoded HEVC stream is performed with an FFmpeg. The version of FFmpeg used for this test was built from the master branch (2024-10-21-git-baa23e40c1 on Windows). FFmpeg generates the following errors during the extraction process:

ffmpeg -i output.h265 -pix_fmt yuva420p output_yuva.yuv -loglevel verbose -hide_banner

ffmpeg_log

For the decoded 1920×1080 stream, the expected transparency data should start at offset 0x2F7600 (calculated as 1920*1080*3/2 = 3110400 bytes). The alpha channel in the YUVA420p file is inspected with a hex editor and it shows that the alpha channel contains only 0xFF values (indicating full opacity) instead of the expected varied transparency mask.

ffmpeg_yuva

In addition, when trying to multiplex the compressed stream into MP4, FFmpeg generates the same errors as during the extraction process:

ffmpeg -i output.h265 -c:v copy output.mp4 -loglevel verbose

Working with VP9 and Transparency

Transparency can also be encoded in VP9, another codec widely used for web video. Let’s test extracting YUVA420p data from a VP9 file with transparency using FFmpeg:

ffmpeg -vcodec libvpx-vp9 -i "input.webm" -pix_fmt yuva420p output_vp9.yuv

You can download encoded VP9 file here.

Hex editor now shows the correct transparency data when examining the extracted YUV.

ffmpeg_yuva_vp9

The transparency can also be checked by playing the VP9 video in Chrome (version 130.0.6723.58) on Windows.

vp9_chrome

HEVC with Alpha on macOS

To create an HEVC file with an alpha channel, you can start by exporting your video as ProRes 4444 in applications like Final Cut Pro or Adobe Premiere Pro. ProRes 4444 preserves the alpha channel, ensuring that transparency is maintained throughout the editing and export process.

“Encode Selected Video Files” is a Finder service available on macOS. It allows users to quickly convert videos to different formats, including HEVC (H.265), H.264, and ProRes, directly from the Finder without needing to open a video editing application. This service includes an option to preserve transparency (alpha channel) when converting ProRes 4444 videos to HEVC. This service was first introduced with macOS High Sierra (10.13). High Sierra was the first macOS version to include native support for HEVC encoding. Works on any Mac with HEVC encoding hardware support, typically Macs released from 2016 onwards with an Intel processor (Skylake or newer) or Apple Silicon chips (e.g., M1, M2).

Once you have a ProRes 4444 file, macOS provides a method to encode it into HEVC while maintaining transparency.

1. Right-click (or Control-click) the ProRes 4444 file in Finder.

encode_selected_video_context

2. From the context menu, select Encode Selected Video Files. In the window that opens, choose HEVC 1080p as the target format and check the “Preserve Transparency” box.

encode_media

3. macOS will then generate an HEVC file that maintains the transparency from the original ProRes 4444 source.

To verify that the transparency has been preserved, you can open the HEVC file in QuickTime Player ( the application installed  on macOS version 14.7 (23H124) is used for tests).

Quicktime

QuickTime supports the playback of HEVC files with transparency, so you should be able to notice the alpha channel on a player’s preview area.

However, if you attempt to decode this file with FFmpeg, the resulting YUVA buffer will contain only 0xFF values in the alpha channel, similar to what we observed with x265. This indicates that FFmpeg still lacks support for properly decoding alpha channels from HEVC streams.

View alpha_channel_info SEI  message in Zond 265

HEVC streams containing alpha channel information include a Supplemental Enhancement Information (SEI) message with payloadType=165. This SEI message, called alpha_channel_info, indicates the presence of an alpha channel in the stream. In Zond 265, a tool for analyzing HEVC bitstreams, you can check for alpha_channel_info by navigating to the “Bitstream” tab and clicking on a Prefix SEI header. There, you’ll find detailed information about the alpha channel in the stream. While Zond 265 does not currently support viewing alpha channels in decoded YUVA buffers, future updates may allow transparency visualization.

zond_sei_alpha_channel_info

FAQ

Q: What is the YUVA 420 format?

A: YUVA420p is a pixel format that includes Y (luma), U, V (chroma), and A (alpha) components. It is a common format for representing video with transparency. YUVA420p uses 4:2:0 chroma subsampling, which means the chroma channels (U and V) are sampled at half the horizontal and vertical resolution compared to the luma (Y) channel, with an additional alpha channel for transparency information.

Q: How can I check for transparency in a YUVA 420 video file?

A: You can use specialized video tools or online applications that let you upload and preview YUVA 420 videos. These tools help you verify if the video contains an alpha channel by checking the transparency mask. Some tools also let you inspect the video frame by frame to ensure the transparency information is correct.

Q: Can YUVA 420 be encoded while maintaining transparency?

A: Yes, there are video codecs that can handle videos in YUVA 420 format. For example, you can encode your video with transparency into HEVC or VP9 and store it in MP4 or WebM files accordingly. The conversion can be done using tools like FFmpeg or specific macOS applications that support transparent video. The alpha channel is preserved during the conversion process, allowing the video to maintain its transparency when played back.

Q: Is there a way to inspect YUVA 420 data manually?

A: Yes, you can use video analysis tools such as a hex editor or YUV viewers to inspect the raw YUVA 420 data. By examining the alpha channel values, you can verify whether transparency information is correctly embedded in the file. This is useful for debugging or ensuring correct encoding when working with YUVA 420 videos.

Q:  What is HEVC with Alpha?

HEVC (High Efficiency Video Coding) with alpha refers to video files encoded in the HEVC format that also contain an alpha channel, which is used to store transparency information. The alpha channel allows for parts of the video to be transparent, which is useful for overlays, special effects, or compositing.

Q: How can I quickly check if a video file has transparency?

A: You can use Zond 265 to check the alpha channel information in the SEI message with payloadType=165, which signals the presence of an alpha channel in the stream.

You can also use other online tools that let you upload a video file and preview its transparency directly in your web browser. Simply select your file, and the tool will show if it contains an alpha channel (transparency).

Q: Is there a tool that allows converting videos with transparency?

A: On macOS, you can encode HEVC with alpha using ProRes 4444 as a source by using the Finder’s built-in service “Encode Selected Video Files”, which supports HEVC with Alpha.

On Windows platform, you can encode video with transparency to WebM format using VP9 codec with FFmpeg.

Conclusion

Encoding and extracting transparency in HEVC remains a challenge, particularly due to the current limitations of the popular tools like FFmpeg. While VP9 provides better transparency support, HEVC with alpha is still in development and requires specific decoding tools. macOS offers native HEVC encoding with transparency using ProRes 4444,as well as the decoding – the QuickTime player is fully compatible and allows to correctly preview video with transparency.

Rate this post