diff mbox series

[FFmpeg-devel,13/15] videotoolbox: add alpha support

Message ID 20211113210916.49167-13-rcombs@rcombs.me
State New
Headers show
Series [FFmpeg-devel,01/15] lavu/pixfmt: add high-bit-depth semi-planar 4:2:2/4:4:4 formats
Related show

Checks

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

Commit Message

rcombs Nov. 13, 2021, 9:09 p.m. UTC
---
 fftools/ffmpeg_videotoolbox.c      | 1 +
 libavcodec/videotoolbox.c          | 3 +++
 libavutil/hwcontext_videotoolbox.c | 2 ++
 3 files changed, 6 insertions(+)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_videotoolbox.c b/fftools/ffmpeg_videotoolbox.c
index 6c89fb48d1..66eaa572c8 100644
--- a/fftools/ffmpeg_videotoolbox.c
+++ b/fftools/ffmpeg_videotoolbox.c
@@ -88,6 +88,7 @@  static int videotoolbox_retrieve_data(AVCodecContext *s, AVFrame *frame)
 #if HAVE_KCVPIXELFORMATTYPE_444YPCBCR16BIPLANARVIDEORANGE
     case kCVPixelFormatType_444YpCbCr16BiPlanarVideoRange: vt->tmp_frame->format = AV_PIX_FMT_P416; break;
 #endif
+    case kCVPixelFormatType_4444AYpCbCr16: vt->tmp_frame->format = AV_PIX_FMT_AYUV64; break;
     default:
         av_log(NULL, AV_LOG_ERROR,
                "%s: Unsupported pixel format: %s\n",
diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 2e9af2ab93..9ca84e873d 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -1072,6 +1072,9 @@  static enum AVPixelFormat videotoolbox_best_pixel_format(AVCodecContext *avctx)
 
     int depth = descriptor->comp[0].depth;
 
+    if (descriptor->flags & AV_PIX_FMT_FLAG_ALPHA)
+        return AV_PIX_FMT_AYUV64;
+
 #if HAVE_KCVPIXELFORMATTYPE_444YPCBCR16BIPLANARVIDEORANGE
     if (depth > 10)
         return descriptor->log2_chroma_w == 0 ? AV_PIX_FMT_P416 : AV_PIX_FMT_P216;
diff --git a/libavutil/hwcontext_videotoolbox.c b/libavutil/hwcontext_videotoolbox.c
index 0a6c9ecfb0..7a9dbba7dd 100644
--- a/libavutil/hwcontext_videotoolbox.c
+++ b/libavutil/hwcontext_videotoolbox.c
@@ -48,6 +48,7 @@  static const struct {
 #ifdef kCFCoreFoundationVersionNumber10_7
     { kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange,  false, AV_PIX_FMT_NV12 },
     { kCVPixelFormatType_420YpCbCr8BiPlanarFullRange,   true,  AV_PIX_FMT_NV12 },
+    { kCVPixelFormatType_4444AYpCbCr16,                 false, AV_PIX_FMT_AYUV64 },
 #endif
 #if HAVE_KCVPIXELFORMATTYPE_420YPCBCR10BIPLANARVIDEORANGE
     { kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange, false, AV_PIX_FMT_P010 },
@@ -80,6 +81,7 @@  static const struct {
 static const enum AVPixelFormat supported_formats[] = {
 #ifdef kCFCoreFoundationVersionNumber10_7
     AV_PIX_FMT_NV12,
+    AV_PIX_FMT_AYUV64,
 #endif
     AV_PIX_FMT_YUV420P,
     AV_PIX_FMT_UYVY422,