[FFmpeg-devel] [PATCH WIP 0/5] avcodec/hevc: Add alpha video decoding support

Zhao Zhili quinkblack at foxmail.com
Wed Dec 11 06:23:20 EET 2024


From: Zhao Zhili <zhilizhao at tencent.com>

What works:

1. Create a sample with macOS videotoolbox
ffmpeg -i base.mp4 -i alpha.mp4 \
	-c:v hevc_videotoolbox -alpha_quality 0.5 -b:v 2M \
	 -filter_complex '[0:v]scale,format=bgra[v0];[1:v]scale=640x480,format=gray[v1];[v0][v1]alphamerge[v2]' \
	-map '[v2]' -y hevc-alpha.ts

Then you can remux it to mp4 if you prefer.

2. Decoding test

a. Check alpha plane
./ffmpeg -i hevc-alpha.ts -an -vf extractplanes=planes=a -f nut - |ffplay -

b. Check Y plane
./ffmpeg -i hevc-alpha.ts -an -vf extractplanes=planes=y -f nut - |ffplay -

What doesn't work:

1. Encoding with videotoolbox and output as mp4 directly, due to missing PS.
Can be fixed by

https://patchwork.ffmpeg.org/project/ffmpeg/patch/20241210191641.676-1-timo@rothenpieler.org/

2. vps_extension is over-engineering and decode_vps_ext() is far from complete.
A complete implementation might take a week, and I don't have enough spare time.
I would greatly appreciate it if someone could help implement it.

Branch on github:

https://github.com/quink-black/FFmpeg/tree/hevc-alpha-3

Zhao Zhili (5):
  avcodec/hevc: Move ScalabilityMask to hevc header file
  avcodec/hevc: Rewrite scalability_mask_flag parse in decode_vps_ext
  avcodec/hevc/ps: Add basic HEVC_SCALABILITY_AUXILIARY support
  avcodec/hevc/sei: Add support for alpha channel information
  avcodec/hevc: Add alpha layer support

 libavcodec/hevc/hevc.h    |  7 +++
 libavcodec/hevc/hevcdec.c | 75 ++++++++++++++++++++++++++++++-
 libavcodec/hevc/hevcdec.h |  2 +
 libavcodec/hevc/ps.c      | 95 +++++++++++++++++++++++----------------
 libavcodec/hevc/ps.h      |  3 ++
 libavcodec/hevc/refs.c    | 10 ++++-
 libavcodec/hevc/sei.c     | 30 +++++++++++++
 libavcodec/hevc/sei.h     | 14 ++++++
 8 files changed, 195 insertions(+), 41 deletions(-)

-- 
2.46.0



More information about the ffmpeg-devel mailing list