* [FFmpeg-devel] [PR] lavc/prores_raw: add videotoolbox hwaccel (PR #21361)
@ 2026-01-02 18:54 averne via ffmpeg-devel
0 siblings, 0 replies; only message in thread
From: averne via ffmpeg-devel @ 2026-01-02 18:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: averne
PR #21361 opened by averne
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21361
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21361.patch
>From 3f0069bd9b3af1df0096a9bb312f74e69cc276c4 Mon Sep 17 00:00:00 2001
From: averne <averne381@gmail.com>
Date: Fri, 2 Jan 2026 19:38:06 +0100
Subject: [PATCH 1/3] lavu/videotoolbox: add 16-bit bayer format mapping
---
configure | 2 ++
libavutil/hwcontext_videotoolbox.c | 6 ++++++
2 files changed, 8 insertions(+)
diff --git a/configure b/configure
index 301a3e5e3e..6db36a604a 100755
--- a/configure
+++ b/configure
@@ -2537,6 +2537,7 @@ TYPES_LIST="
kCVPixelFormatType_444YpCbCr8BiPlanarVideoRange
kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange
kCVPixelFormatType_444YpCbCr16BiPlanarVideoRange
+ kCVPixelFormatType_16VersatileBayer
kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ
kCVImageBufferTransferFunction_ITU_R_2100_HLG
kCVImageBufferTransferFunction_Linear
@@ -6950,6 +6951,7 @@ enabled videotoolbox && {
check_func_headers CoreVideo/CVPixelBuffer.h kCVPixelFormatType_444YpCbCr8BiPlanarVideoRange "-framework CoreVideo"
check_func_headers CoreVideo/CVPixelBuffer.h kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange "-framework CoreVideo"
check_func_headers CoreVideo/CVPixelBuffer.h kCVPixelFormatType_444YpCbCr16BiPlanarVideoRange "-framework CoreVideo"
+ check_func_headers CoreVideo/CVPixelBuffer.h kCVPixelFormatType_16VersatileBayer "-framework CoreVideo"
check_func_headers CoreVideo/CVImageBuffer.h kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ "-framework CoreVideo"
check_func_headers CoreVideo/CVImageBuffer.h kCVImageBufferTransferFunction_ITU_R_2100_HLG "-framework CoreVideo"
check_func_headers CoreVideo/CVImageBuffer.h kCVImageBufferTransferFunction_Linear "-framework CoreVideo"
diff --git a/libavutil/hwcontext_videotoolbox.c b/libavutil/hwcontext_videotoolbox.c
index 102fa485e5..419dc5b8c0 100644
--- a/libavutil/hwcontext_videotoolbox.c
+++ b/libavutil/hwcontext_videotoolbox.c
@@ -82,6 +82,9 @@ static const struct {
#if HAVE_KCVPIXELFORMATTYPE_444YPCBCR16BIPLANARVIDEORANGE
{ kCVPixelFormatType_444YpCbCr16BiPlanarVideoRange, false, AV_PIX_FMT_P416 },
#endif
+#if HAVE_KCVPIXELFORMATTYPE_16VERSATILEBAYER
+ { kCVPixelFormatType_16VersatileBayer, false, AV_PIX_FMT_BAYER_RGGB16 },
+#endif
};
static const enum AVPixelFormat supported_formats[] = {
@@ -112,6 +115,9 @@ static const enum AVPixelFormat supported_formats[] = {
#endif
#if HAVE_KCVPIXELFORMATTYPE_444YPCBCR16BIPLANARVIDEORANGE
AV_PIX_FMT_P416,
+#endif
+#if HAVE_KCVPIXELFORMATTYPE_16VERSATILEBAYER
+ AV_PIX_FMT_BAYER_RGGB16,
#endif
AV_PIX_FMT_BGRA,
};
--
2.49.1
>From f040dd0ba16edb71d5aba456abfcc06f757161fd Mon Sep 17 00:00:00 2001
From: averne <averne381@gmail.com>
Date: Fri, 2 Jan 2026 19:43:12 +0100
Subject: [PATCH 2/3] lavc/videotoolbox: select 16-bit bayer format when
applicable
---
libavcodec/videotoolbox.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 2cd22cba1a..a4d9cd355b 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -818,9 +818,11 @@ static CFDictionaryRef videotoolbox_buffer_attributes_create(int width,
CFDictionarySetValue(buffer_attributes, kCVPixelBufferWidthKey, w);
CFDictionarySetValue(buffer_attributes, kCVPixelBufferHeightKey, h);
#if TARGET_OS_IPHONE
- CFDictionarySetValue(buffer_attributes, kCVPixelBufferOpenGLESCompatibilityKey, kCFBooleanTrue);
+ CFDictionarySetValue(buffer_attributes, kCVPixelBufferOpenGLESCompatibilityKey,
+ pix_fmt != kCVPixelFormatType_16VersatileBayer ? kCFBooleanTrue : kCFBooleanFalse);
#else
- CFDictionarySetValue(buffer_attributes, kCVPixelBufferIOSurfaceOpenGLTextureCompatibilityKey, kCFBooleanTrue);
+ CFDictionarySetValue(buffer_attributes, kCVPixelBufferIOSurfaceOpenGLTextureCompatibilityKey,
+ pix_fmt != kCVPixelFormatType_16VersatileBayer ? kCFBooleanTrue : kCFBooleanFalse);
#endif
CFRelease(io_surface_properties);
@@ -1200,6 +1202,11 @@ static enum AVPixelFormat videotoolbox_best_pixel_format(AVCodecContext *avctx)
if (descriptor->flags & AV_PIX_FMT_FLAG_ALPHA)
return (depth > 8) ? AV_PIX_FMT_AYUV64 : AV_PIX_FMT_AYUV;
+#if HAVE_KCVPIXELFORMATTYPE_16VERSATILEBAYER
+ if (descriptor->flags & AV_PIX_FMT_FLAG_BAYER)
+ return AV_PIX_FMT_BAYER_RGGB16;
+#endif
+
#if HAVE_KCVPIXELFORMATTYPE_444YPCBCR16BIPLANARVIDEORANGE
if (depth > 10)
return descriptor->log2_chroma_w == 0 ? AV_PIX_FMT_P416 : AV_PIX_FMT_P216;
--
2.49.1
>From 3987f6bbe6b0b07e857a82b75e9d8d12ff3b8c31 Mon Sep 17 00:00:00 2001
From: averne <averne381@gmail.com>
Date: Fri, 2 Jan 2026 19:39:31 +0100
Subject: [PATCH 3/3] lavc: add a ProRes RAW VideoToolboox hwaccel
---
libavcodec/hwaccels.h | 1 +
libavcodec/prores_raw.c | 6 +++++
libavcodec/videotoolbox.c | 54 ++++++++++++++++++++++++++++++++++++++-
3 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/libavcodec/hwaccels.h b/libavcodec/hwaccels.h
index 3de191288a..35c5d57377 100644
--- a/libavcodec/hwaccels.h
+++ b/libavcodec/hwaccels.h
@@ -69,6 +69,7 @@ extern const struct FFHWAccel ff_mpeg4_vdpau_hwaccel;
extern const struct FFHWAccel ff_mpeg4_videotoolbox_hwaccel;
extern const struct FFHWAccel ff_prores_videotoolbox_hwaccel;
extern const struct FFHWAccel ff_prores_vulkan_hwaccel;
+extern const struct FFHWAccel ff_prores_raw_videotoolbox_hwaccel;
extern const struct FFHWAccel ff_prores_raw_vulkan_hwaccel;
extern const struct FFHWAccel ff_vc1_d3d11va_hwaccel;
extern const struct FFHWAccel ff_vc1_d3d11va2_hwaccel;
diff --git a/libavcodec/prores_raw.c b/libavcodec/prores_raw.c
index 8be566ed36..f9a688760c 100644
--- a/libavcodec/prores_raw.c
+++ b/libavcodec/prores_raw.c
@@ -313,6 +313,9 @@ static enum AVPixelFormat get_pixel_format(AVCodecContext *avctx,
enum AVPixelFormat pix_fmt)
{
enum AVPixelFormat pix_fmts[] = {
+#if CONFIG_PRORES_RAW_VIDEOTOOLBOX_HWACCEL
+ AV_PIX_FMT_VIDEOTOOLBOX,
+#endif
#if CONFIG_PRORES_RAW_VULKAN_HWACCEL
AV_PIX_FMT_VULKAN,
#endif
@@ -548,6 +551,9 @@ const FFCodec ff_prores_raw_decoder = {
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
.hw_configs = (const AVCodecHWConfigInternal *const []) {
+#if CONFIG_PRORES_RAW_VIDEOTOOLBOX_HWACCEL
+ HWACCEL_VIDEOTOOLBOX(prores_raw),
+#endif
#if CONFIG_PRORES_RAW_VULKAN_HWACCEL
HWACCEL_VULKAN(prores_raw),
#endif
diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index a4d9cd355b..af7d297b58 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -37,6 +37,7 @@
#include "hwaccel_internal.h"
#include "mpegvideo.h"
#include "proresdec.h"
+#include "prores_raw.h"
#include <Availability.h>
#include <AvailabilityMacros.h>
#include <TargetConditionals.h>
@@ -948,6 +949,17 @@ static int videotoolbox_start(AVCodecContext *avctx)
break;
}
break;
+ case AV_CODEC_ID_PRORES_RAW :
+ switch (avctx->codec_tag) {
+ default:
+ av_log(avctx, AV_LOG_WARNING, "Unknown prores raw profile %d\n", avctx->codec_tag);
+ // fall-through
+ case MKTAG('a', 'p', 'r', 'n'): // kCMVideoCodecType_AppleProResRAW
+ case MKTAG('a', 'p', 'r', 'h'): // kCMVideoCodecType_AppleProResRAWHQ
+ videotoolbox->cm_codec_type = av_bswap32(avctx->codec_tag);
+ break;
+ }
+ break;
case AV_CODEC_ID_VP9 :
videotoolbox->cm_codec_type = kCMVideoCodecType_VP9;
break;
@@ -959,7 +971,7 @@ static int videotoolbox_start(AVCodecContext *avctx)
}
#if defined(MAC_OS_X_VERSION_10_9) && !TARGET_OS_IPHONE && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9) && AV_HAS_BUILTIN(__builtin_available)
- if (avctx->codec_id == AV_CODEC_ID_PRORES) {
+ if (avctx->codec_id == AV_CODEC_ID_PRORES || avctx->codec_id == AV_CODEC_ID_PRORES_RAW) {
if (__builtin_available(macOS 10.9, *)) {
VTRegisterProfessionalVideoWorkflowVideoDecoders();
}
@@ -1191,6 +1203,31 @@ static int videotoolbox_prores_end_frame(AVCodecContext *avctx)
return ff_videotoolbox_common_end_frame(avctx, frame);
}
+static int videotoolbox_prores_raw_start_frame(AVCodecContext *avctx,
+ const AVBufferRef *buffer_ref,
+ const uint8_t *buffer,
+ uint32_t size)
+{
+ VTContext *vtctx = avctx->internal->hwaccel_priv_data;
+
+ return ff_videotoolbox_buffer_copy(vtctx, buffer, size);
+}
+
+static int videotoolbox_prores_raw_decode_slice(AVCodecContext *avctx,
+ const uint8_t *buffer,
+ uint32_t size)
+{
+ return 0;
+}
+
+static int videotoolbox_prores_raw_end_frame(AVCodecContext *avctx)
+{
+ ProResRAWContext *s = avctx->priv_data;
+ AVFrame *frame = s->frame;
+
+ return ff_videotoolbox_common_end_frame(avctx, frame);
+}
+
static enum AVPixelFormat videotoolbox_best_pixel_format(AVCodecContext *avctx) {
int depth;
const AVPixFmtDescriptor *descriptor = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
@@ -1457,4 +1494,19 @@ const FFHWAccel ff_prores_videotoolbox_hwaccel = {
.priv_data_size = sizeof(VTContext),
};
+const FFHWAccel ff_prores_raw_videotoolbox_hwaccel = {
+ .p.name = "prores_raw_videotoolbox",
+ .p.type = AVMEDIA_TYPE_VIDEO,
+ .p.id = AV_CODEC_ID_PRORES_RAW,
+ .p.pix_fmt = AV_PIX_FMT_VIDEOTOOLBOX,
+ .alloc_frame = ff_videotoolbox_alloc_frame,
+ .start_frame = videotoolbox_prores_raw_start_frame,
+ .decode_slice = videotoolbox_prores_raw_decode_slice,
+ .end_frame = videotoolbox_prores_raw_end_frame,
+ .frame_params = ff_videotoolbox_frame_params,
+ .init = ff_videotoolbox_common_init,
+ .uninit = ff_videotoolbox_uninit,
+ .priv_data_size = sizeof(VTContext),
+};
+
#endif /* CONFIG_VIDEOTOOLBOX */
--
2.49.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-01-02 18:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-02 18:54 [FFmpeg-devel] [PR] lavc/prores_raw: add videotoolbox hwaccel (PR #21361) averne via ffmpeg-devel
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git