diff mbox series

[FFmpeg-devel,03/10] lavc/videotoolboxenc: detect alpha more generically

Message ID 20211217001215.75135-4-rcombs@rcombs.me
State Accepted
Commit e55db79612cb39053442b69d911740ed47cb8347
Headers show
Series [FFmpeg-devel,01/10] lavc/videotoolboxenc: use common routine for pixfmt conversion | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

rcombs Dec. 17, 2021, 12:12 a.m. UTC
Fixes support for alpha in hardware input frames
---
 libavcodec/videotoolboxenc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 9857e55fdc..fa8f717a6c 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -406,14 +406,14 @@  static int count_nalus(size_t length_code_size,
     return 0;
 }
 
-static CMVideoCodecType get_cm_codec_type(enum AVCodecID id,
-                                          enum AVPixelFormat fmt,
+static CMVideoCodecType get_cm_codec_type(AVCodecContext *avctx,
                                           double alpha_quality)
 {
-    switch (id) {
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt == AV_PIX_FMT_VIDEOTOOLBOX ? avctx->sw_pix_fmt : avctx->pix_fmt);
+    switch (avctx->codec_id) {
     case AV_CODEC_ID_H264: return kCMVideoCodecType_H264;
     case AV_CODEC_ID_HEVC:
-        if (fmt == AV_PIX_FMT_BGRA && alpha_quality > 0.0) {
+        if (desc && (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpha_quality > 0.0) {
             return kCMVideoCodecType_HEVCWithAlpha;
         }
         return kCMVideoCodecType_HEVC;
@@ -1376,7 +1376,7 @@  static int vtenc_configure_encoder(AVCodecContext *avctx)
     CFNumberRef            gamma_level = NULL;
     int                    status;
 
-    codec_type = get_cm_codec_type(avctx->codec_id, avctx->pix_fmt, vtctx->alpha_quality);
+    codec_type = get_cm_codec_type(avctx, vtctx->alpha_quality);
     if (!codec_type) {
         av_log(avctx, AV_LOG_ERROR, "Error: no mapping for AVCodecID %d\n", avctx->codec_id);
         return AVERROR(EINVAL);