Sending to ffmpeg-devel because I do not know if my workaround makes any sense?

For some reason hevc alpha decoding was not working for us.

I picked up 
https://source.ffmpeg.org/gitweb/ffmpeg.git/commit/eedf8f0165fe6523be692c5a91ebf6744808335d

avcodec/hevc: workaround hevc-alpha videos generated by VideoToolbox

but videos were still not showing their alpha channel.

So I added this to libavcodec/hevc/hevcdec.c:

--- ./libavcodec/hevc/hevcdec.c 2026-03-16 18:13:04.000000000 +0000
+++ ./libavcodec/hevc/hevcdec.c.new     2026-05-09 05:22:45.098799320 +0000
@@ -712,9 +712,11 @@
         break;
     }

+
     if (alpha_fmt != AV_PIX_FMT_NONE)
         *fmt++ = alpha_fmt;
-    *fmt++ = sps->pix_fmt;
+    if(alpha_fmt == AV_PIX_FMT_NONE)
+        *fmt++ = sps->pix_fmt;
     *fmt = AV_PIX_FMT_NONE;

     // export multilayer information from active VPS to the caller,

====

basically only adding main layer (?) formats if there was no alpha)

It seems to work with two hevc-alpha files and one normal hevc file

May be this is only cingg specific problem - due to way we pick pixel
formats on decoding?

ffmpeg itself works ok without this workaround

Even with this patch ffmpeg cli still picks correct format, on encoding to png:

thirdparty/ffmpeg-8.1/ffmpeg -i /dev/shm/av1--test.mp4  -vframes 1 1.png

1.png contain transparency

test files from
https://developer.apple.com/documentation/avfoundation/using-hevc-video-with-alpha

more test files:
https://lf-tk-sg.ibytedtos.com/obj/tcs-client-sg/resources/video_demo_hevc.html

possibly related

https://trac.ffmpeg.org/ticket/10901

HEVC with alpha to PNG does not maintain alpha
From bd697b268ec02b9a097997a4f1060969feffe53d Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Sat, 9 May 2026 05:36:13 +0000
Subject: [PATCH 4/4] Add two patches for decoding hevc-alpha

---
 .../thirdparty/src/ffmpeg-8.1.patch11         | 15 +++++
 .../thirdparty/src/ffmpeg-8.1.patch12         | 55 +++++++++++++++++++
 2 files changed, 70 insertions(+)
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-8.1.patch11
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-8.1.patch12

diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-8.1.patch11 b/cinelerra-5.1/thirdparty/src/ffmpeg-8.1.patch11
new file mode 100644
index 00000000..1d44fb35
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-8.1.patch11
@@ -0,0 +1,15 @@
+--- ./libavcodec/hevc/hevcdec.c	2026-03-16 18:13:04.000000000 +0000
++++ ./libavcodec/hevc/hevcdec.c.new	2026-05-09 05:22:45.098799320 +0000
+@@ -712,9 +712,11 @@
+         break;
+     }
+ 
++        
+     if (alpha_fmt != AV_PIX_FMT_NONE)
+         *fmt++ = alpha_fmt;
+-    *fmt++ = sps->pix_fmt;
++    if(alpha_fmt == AV_PIX_FMT_NONE)
++        *fmt++ = sps->pix_fmt;
+     *fmt = AV_PIX_FMT_NONE;
+ 
+     // export multilayer information from active VPS to the caller,
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-8.1.patch12 b/cinelerra-5.1/thirdparty/src/ffmpeg-8.1.patch12
new file mode 100644
index 00000000..a504e140
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-8.1.patch12
@@ -0,0 +1,55 @@
+X-Git-Url: http://source.ffmpeg.org/gitweb/ffmpeg.git/blobdiff_plain/28ab24b71717027ab67e6220bd0dad82a90f22c1..eedf8f0165fe6523be692c5a91ebf6744808335d:/libavcodec/hevc/ps.c
+
+diff --git a/libavcodec/hevc/ps.c b/libavcodec/hevc/ps.c
+index 46b38564d5..10c9a36102 100644
+--- a/libavcodec/hevc/ps.c
++++ b/libavcodec/hevc/ps.c
+@@ -610,8 +610,11 @@ static int decode_vps_ext(GetBitContext *gb, AVCodecContext *avctx, HEVCVPS *vps
+         }
+     }
+     vps->num_output_layer_sets = vps->vps_num_layer_sets + vps->num_add_layer_sets;
+-    if (vps->num_output_layer_sets != 2)
+-        return AVERROR_INVALIDDATA;
++    if (vps->num_output_layer_sets != 2) {
++        av_log(avctx, AV_LOG_WARNING,
++               "Unsupported num_output_layer_sets: %d\n", vps->num_output_layer_sets);
++        return AVERROR_PATCHWELCOME;
++    }
+ 
+     sub_layers_max_present = get_bits1(gb); // vps_sub_layers_max_minus1_present_flag
+     if (sub_layers_max_present) {
+@@ -677,7 +680,7 @@ static int decode_vps_ext(GetBitContext *gb, AVCodecContext *avctx, HEVCVPS *vps
+ 
+     if (get_ue_golomb_31(gb) != 0 /* vps_num_rep_formats_minus1 */) {
+         av_log(avctx, AV_LOG_ERROR, "Unexpected extra rep formats\n");
+-        return AVERROR_INVALIDDATA;
++        return AVERROR_PATCHWELCOME;
+     }
+ 
+     vps->rep_format.pic_width_in_luma_samples  = get_bits(gb, 16);
+@@ -895,8 +898,23 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
+     if (vps->vps_max_layers > 1 && get_bits1(gb)) { /* vps_extension_flag */
+         int ret = decode_vps_ext(gb, avctx, vps, layer1_id_included);
+         if (ret == AVERROR_PATCHWELCOME) {
+-            vps->nb_layers = 1;
+-            av_log(avctx, AV_LOG_WARNING, "Ignoring unsupported VPS extension\n");
++            /* If alpha layer info was already parsed, preserve it for alpha decoding */
++            if (!(avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_COMPLIANT)) &&
++                vps->nb_layers == 2 &&
++                vps->layer_id_in_nuh[1] &&
++                (vps->scalability_mask_flag & HEVC_SCALABILITY_AUXILIARY)) {
++                av_log(avctx, AV_LOG_WARNING,
++                       "Broken VPS extension, treating as alpha video\n");
++                /* If alpha layer has no direct dependency on base layer,
++                 * assume poc_lsb_not_present for the alpha layer, so that
++                 * IDR slices on that layer won't read pic_order_cnt_lsb.
++                 * This matches the behavior of Apple VideoToolbox encoders. */
++                if (!vps->num_direct_ref_layers[1])
++                    vps->poc_lsb_not_present |= 1 << 1;
++            } else {
++                vps->nb_layers = 1;
++                av_log(avctx, AV_LOG_WARNING, "Ignoring unsupported VPS extension\n");
++            }
+             ret = 0;
+         } else if (ret < 0)
+             goto err;
-- 
2.29.0

From f6beba6c0cb9f3ad6abd424f61bfc02f2d6f1d74 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Sat, 9 May 2026 04:33:46 +0000
Subject: [PATCH 3/4] Fix h265_alpha profile

---
 cinelerra-5.1/ffmpeg/video/h265_alpha.mp4 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cinelerra-5.1/ffmpeg/video/h265_alpha.mp4 b/cinelerra-5.1/ffmpeg/video/h265_alpha.mp4
index 3e6336f7..272a4d30 100644
--- a/cinelerra-5.1/ffmpeg/video/h265_alpha.mp4
+++ b/cinelerra-5.1/ffmpeg/video/h265_alpha.mp4
@@ -1,6 +1,6 @@
 mp4 libx265
 cin_quality=-1
-cin_pix_fmt=yuva420
+cin_pix_fmt=yuva420p
 codec_tag=0x31637668
 # use framerate for 1 keyframe/sec, needed for seeks
 keyint_min=30
-- 
2.29.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to