Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: rcombs <rcombs@rcombs.me>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 10/10] lavc/videotoolboxenc: add ProRes support
Date: Thu, 16 Dec 2021 18:12:15 -0600
Message-ID: <20211217001215.75135-11-rcombs@rcombs.me> (raw)
In-Reply-To: <20211217001215.75135-1-rcombs@rcombs.me>

---
 Changelog                    |   1 +
 configure                    |   2 +
 libavcodec/Makefile          |   1 +
 libavcodec/allcodecs.c       |   1 +
 libavcodec/version.h         |   2 +-
 libavcodec/videotoolboxenc.c | 119 +++++++++++++++++++++++++++++++++--
 6 files changed, 119 insertions(+), 7 deletions(-)

diff --git a/Changelog b/Changelog
index 5c6adc0fa7..ebbfed14a0 100644
--- a/Changelog
+++ b/Changelog
@@ -41,6 +41,7 @@ version <next>:
 - libplacebo filter
 - vflip_vulkan, hflip_vulkan and flip_vulkan filters
 - adynamicequalizer audio filter
+- VideoToolbox ProRes encoder
 
 
 version 4.4:
diff --git a/configure b/configure
index 5fffcb8afe..0146b28ff1 100755
--- a/configure
+++ b/configure
@@ -3300,6 +3300,8 @@ h264_videotoolbox_encoder_deps="pthreads"
 h264_videotoolbox_encoder_select="atsc_a53 videotoolbox_encoder"
 hevc_videotoolbox_encoder_deps="pthreads"
 hevc_videotoolbox_encoder_select="atsc_a53 videotoolbox_encoder"
+prores_videotoolbox_encoder_deps="pthreads"
+prores_videotoolbox_encoder_select="videotoolbox_encoder"
 libaom_av1_decoder_deps="libaom"
 libaom_av1_encoder_deps="libaom"
 libaom_av1_encoder_select="extract_extradata_bsf"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index beb91e8c12..f15a56eabd 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -565,6 +565,7 @@ OBJS-$(CONFIG_PRORES_DECODER)          += proresdec2.o proresdsp.o proresdata.o
 OBJS-$(CONFIG_PRORES_ENCODER)          += proresenc_anatoliy.o proresdata.o
 OBJS-$(CONFIG_PRORES_AW_ENCODER)       += proresenc_anatoliy.o proresdata.o
 OBJS-$(CONFIG_PRORES_KS_ENCODER)       += proresenc_kostya.o proresdata.o
+OBJS-$(CONFIG_PRORES_VIDEOTOOLBOX_ENCODER) += videotoolboxenc.o
 OBJS-$(CONFIG_PROSUMER_DECODER)        += prosumer.o
 OBJS-$(CONFIG_PSD_DECODER)             += psd.o
 OBJS-$(CONFIG_PTX_DECODER)             += ptx.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 89d65266c8..d1e10197de 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -837,6 +837,7 @@ extern const AVCodec ff_mpeg4_cuvid_decoder;
 extern const AVCodec ff_mpeg4_mediacodec_decoder;
 extern const AVCodec ff_mpeg4_omx_encoder;
 extern const AVCodec ff_mpeg4_v4l2m2m_encoder;
+extern const AVCodec ff_prores_videotoolbox_encoder;
 extern const AVCodec ff_vc1_cuvid_decoder;
 extern const AVCodec ff_vp8_cuvid_decoder;
 extern const AVCodec ff_vp8_mediacodec_decoder;
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 8a0b94f5aa..db71fb1130 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  59
-#define LIBAVCODEC_VERSION_MINOR  14
+#define LIBAVCODEC_VERSION_MINOR  15
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 67bb563639..8453da7bc4 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -407,6 +407,7 @@ static int count_nalus(size_t length_code_size,
 }
 
 static CMVideoCodecType get_cm_codec_type(AVCodecContext *avctx,
+                                          int64_t profile,
                                           double alpha_quality)
 {
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt == AV_PIX_FMT_VIDEOTOOLBOX ? avctx->sw_pix_fmt : avctx->pix_fmt);
@@ -417,6 +418,31 @@ static CMVideoCodecType get_cm_codec_type(AVCodecContext *avctx,
             return kCMVideoCodecType_HEVCWithAlpha;
         }
         return kCMVideoCodecType_HEVC;
+    case AV_CODEC_ID_PRORES:
+        switch (profile) {
+        case FF_PROFILE_PRORES_PROXY:
+            return MKBETAG('a','p','c','o'); // kCMVideoCodecType_AppleProRes422Proxy
+        case FF_PROFILE_PRORES_LT:
+            return MKBETAG('a','p','c','s'); // kCMVideoCodecType_AppleProRes422LT
+        case FF_PROFILE_PRORES_STANDARD:
+            return MKBETAG('a','p','c','n'); // kCMVideoCodecType_AppleProRes422
+        case FF_PROFILE_PRORES_HQ:
+            return MKBETAG('a','p','c','h'); // kCMVideoCodecType_AppleProRes422HQ
+        case FF_PROFILE_PRORES_4444:
+            return MKBETAG('a','p','4','h'); // kCMVideoCodecType_AppleProRes4444
+        case FF_PROFILE_PRORES_XQ:
+            return MKBETAG('a','p','4','x'); // kCMVideoCodecType_AppleProRes4444XQ
+
+        default:
+            av_log(avctx, AV_LOG_ERROR, "Unknown profile ID: %"PRId64", using auto\n", profile);
+        case FF_PROFILE_UNKNOWN:
+            if (desc &&
+                ((desc->flags & AV_PIX_FMT_FLAG_ALPHA) ||
+                  desc->log2_chroma_w == 0))
+                return MKBETAG('a','p','4','h'); // kCMVideoCodecType_AppleProRes4444
+            else
+                return MKBETAG('a','p','c','n'); // kCMVideoCodecType_AppleProRes422
+        }
     default:               return 0;
     }
 }
@@ -1104,7 +1130,7 @@ static int vtenc_create_encoder(AVCodecContext   *avctx,
                                       kVTCompressionPropertyKey_Quality,
                                       quality_num);
         CFRelease(quality_num);
-    } else {
+    } else if (avctx->codec_id != AV_CODEC_ID_PRORES) {
         bit_rate_num = CFNumberCreate(kCFAllocatorDefault,
                                       kCFNumberSInt32Type,
                                       &bit_rate);
@@ -1191,7 +1217,7 @@ static int vtenc_create_encoder(AVCodecContext   *avctx,
         }
     }
 
-    if (avctx->gop_size > 0) {
+    if (avctx->gop_size > 0 && avctx->codec_id != AV_CODEC_ID_PRORES) {
         CFNumberRef interval = CFNumberCreate(kCFAllocatorDefault,
                                               kCFNumberIntType,
                                               &avctx->gop_size);
@@ -1340,7 +1366,7 @@ static int vtenc_create_encoder(AVCodecContext   *avctx,
         }
     }
 
-    if (!vtctx->has_b_frames) {
+    if (!vtctx->has_b_frames && avctx->codec_id != AV_CODEC_ID_PRORES) {
         status = VTSessionSetProperty(vtctx->session,
                                       kVTCompressionPropertyKey_AllowFrameReordering,
                                       kCFBooleanFalse);
@@ -1390,16 +1416,24 @@ static int vtenc_configure_encoder(AVCodecContext *avctx)
     CFMutableDictionaryRef pixel_buffer_info;
     CMVideoCodecType       codec_type;
     VTEncContext           *vtctx = avctx->priv_data;
-    CFStringRef            profile_level;
+    CFStringRef            profile_level = NULL;
     CFNumberRef            gamma_level = NULL;
     int                    status;
 
-    codec_type = get_cm_codec_type(avctx, vtctx->alpha_quality);
+    codec_type = get_cm_codec_type(avctx, vtctx->profile, 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);
     }
 
+#if defined(MAC_OS_X_VERSION_10_9) && !TARGET_OS_IPHONE && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9)
+    if (avctx->codec_id == AV_CODEC_ID_PRORES) {
+        if (__builtin_available(macOS 10.9, *)) {
+            VTRegisterProfessionalVideoWorkflowVideoEncoders();
+        }
+    }
+#endif
+
     vtctx->codec_id = avctx->codec_id;
 
     if (vtctx->codec_id == AV_CODEC_ID_H264) {
@@ -1417,12 +1451,14 @@ static int vtenc_configure_encoder(AVCodecContext *avctx)
         }
 
         if (!get_vt_h264_profile_level(avctx, &profile_level)) return AVERROR(EINVAL);
-    } else {
+    } else if (vtctx->codec_id == AV_CODEC_ID_HEVC) {
         vtctx->get_param_set_func = compat_keys.CMVideoFormatDescriptionGetHEVCParameterSetAtIndex;
         if (!vtctx->get_param_set_func) return AVERROR(EINVAL);
         if (!get_vt_hevc_profile_level(avctx, &profile_level)) return AVERROR(EINVAL);
         // HEVC has b-byramid
         vtctx->has_b_frames = avctx->max_b_frames > 0 ? 2 : 0;
+    } else if (vtctx->codec_id == AV_CODEC_ID_PRORES) {
+        avctx->codec_tag = av_bswap32(codec_type);
     }
 
     enc_info = CFDictionaryCreateMutable(
@@ -2600,6 +2636,38 @@ static const enum AVPixelFormat hevc_pix_fmts[] = {
     AV_PIX_FMT_NONE
 };
 
+static const enum AVPixelFormat prores_pix_fmts[] = {
+    AV_PIX_FMT_YUV420P,
+#ifdef kCFCoreFoundationVersionNumber10_7
+    AV_PIX_FMT_NV12,
+    AV_PIX_FMT_AYUV64,
+#endif
+    AV_PIX_FMT_UYVY422,
+#if HAVE_KCVPIXELFORMATTYPE_420YPCBCR10BIPLANARVIDEORANGE
+    AV_PIX_FMT_P010,
+#endif
+#if HAVE_KCVPIXELFORMATTYPE_422YPCBCR8BIPLANARVIDEORANGE
+    AV_PIX_FMT_NV16,
+#endif
+#if HAVE_KCVPIXELFORMATTYPE_422YPCBCR10BIPLANARVIDEORANGE
+    AV_PIX_FMT_P210,
+#endif
+#if HAVE_KCVPIXELFORMATTYPE_422YPCBCR16BIPLANARVIDEORANGE
+    AV_PIX_FMT_P216,
+#endif
+#if HAVE_KCVPIXELFORMATTYPE_444YPCBCR8BIPLANARVIDEORANGE
+    AV_PIX_FMT_NV24,
+#endif
+#if HAVE_KCVPIXELFORMATTYPE_444YPCBCR10BIPLANARVIDEORANGE
+    AV_PIX_FMT_P410,
+#endif
+#if HAVE_KCVPIXELFORMATTYPE_444YPCBCR16BIPLANARVIDEORANGE
+    AV_PIX_FMT_P416,
+#endif
+    AV_PIX_FMT_BGRA,
+    AV_PIX_FMT_NONE
+};
+
 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 #define COMMON_OPTIONS \
     { "allow_sw", "Allow software encoding", OFFSET(allow_sw), AV_OPT_TYPE_BOOL, \
@@ -2703,3 +2771,42 @@ const AVCodec ff_hevc_videotoolbox_encoder = {
                         FF_CODEC_CAP_INIT_CLEANUP,
     .wrapper_name     = "videotoolbox",
 };
+
+static const AVOption prores_options[] = {
+    { "profile", "Profile", OFFSET(profile), AV_OPT_TYPE_INT64, { .i64 = FF_PROFILE_UNKNOWN }, FF_PROFILE_UNKNOWN, FF_PROFILE_PRORES_XQ, VE, "profile" },
+    { "auto",     "Automatically determine based on input format", 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_UNKNOWN },            INT_MIN, INT_MAX, VE, "profile" },
+    { "proxy",    "ProRes 422 Proxy",                              0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_PRORES_PROXY },       INT_MIN, INT_MAX, VE, "profile" },
+    { "lt",       "ProRes 422 LT",                                 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_PRORES_LT },          INT_MIN, INT_MAX, VE, "profile" },
+    { "standard", "ProRes 422",                                    0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_PRORES_STANDARD },    INT_MIN, INT_MAX, VE, "profile" },
+    { "hq",       "ProRes 422 HQ",                                 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_PRORES_HQ },          INT_MIN, INT_MAX, VE, "profile" },
+    { "4444",     "ProRes 4444",                                   0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_PRORES_4444 },        INT_MIN, INT_MAX, VE, "profile" },
+    { "xq",       "ProRes 4444 XQ",                                0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_PRORES_XQ },          INT_MIN, INT_MAX, VE, "profile" },
+
+    COMMON_OPTIONS
+    { NULL },
+};
+
+static const AVClass prores_videotoolbox_class = {
+    .class_name = "prores_videotoolbox",
+    .item_name  = av_default_item_name,
+    .option     = prores_options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
+const AVCodec ff_prores_videotoolbox_encoder = {
+    .name             = "prores_videotoolbox",
+    .long_name        = NULL_IF_CONFIG_SMALL("VideoToolbox ProRes Encoder"),
+    .type             = AVMEDIA_TYPE_VIDEO,
+    .id               = AV_CODEC_ID_PRORES,
+    .capabilities     = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
+                        AV_CODEC_CAP_HARDWARE,
+    .priv_data_size   = sizeof(VTEncContext),
+    .pix_fmts         = prores_pix_fmts,
+    .init             = vtenc_init,
+    .encode2          = vtenc_frame,
+    .close            = vtenc_close,
+    .priv_class       = &prores_videotoolbox_class,
+    .caps_internal    = FF_CODEC_CAP_INIT_THREADSAFE |
+                        FF_CODEC_CAP_INIT_CLEANUP,
+    .wrapper_name     = "videotoolbox",
+};
-- 
2.33.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2021-12-17  0:14 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-17  0:12 [FFmpeg-devel] " rcombs
2021-12-17  0:12 ` [FFmpeg-devel] [PATCH 01/10] lavc/videotoolboxenc: use common routine for pixfmt conversion rcombs
2021-12-17  0:12 ` [FFmpeg-devel] [PATCH 02/10] lavc/videotoolboxenc: don't access int64_t member as int rcombs
2021-12-17  0:12 ` [FFmpeg-devel] [PATCH 03/10] lavc/videotoolboxenc: detect alpha more generically rcombs
2021-12-17  0:12 ` [FFmpeg-devel] [PATCH 04/10] lavc/videotoolboxenc: fix RGB support rcombs
2021-12-19 16:18   ` Rick Kern
2021-12-17  0:12 ` [FFmpeg-devel] [PATCH 05/10] lavc/videotoolboxenc: config-gate ATSC CC support rcombs
2021-12-17  0:12 ` [FFmpeg-devel] [PATCH 06/10] lavc/videotoolboxenc: vastly simplify get_cv_pixel_info rcombs
2021-12-19 16:25   ` Rick Kern
2021-12-17  0:12 ` [FFmpeg-devel] [PATCH 07/10] lavc/videotoolboxenc: add handling for non-NAL-based codecs rcombs
2021-12-19 16:40   ` Rick Kern
2021-12-17  0:12 ` [FFmpeg-devel] [PATCH 08/10] lavc/Makefile: fix missing hevc_videotoolbox case rcombs
2021-12-17  0:12 ` [FFmpeg-devel] [PATCH 09/10] swscale: add P210/P410/P216/P416 output rcombs
2021-12-23 11:00   ` Michael Niedermayer
2021-12-17  0:12 ` rcombs [this message]
2021-12-19 17:30 ` [FFmpeg-devel] lavc/videotoolboxenc: add ProRes support Rick Kern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211217001215.75135-11-rcombs@rcombs.me \
    --to=rcombs@rcombs.me \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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