aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrcombs <rcombs@rcombs.me>2021-12-16 17:33:46 -0600
committerrcombs <rcombs@rcombs.me>2021-12-22 18:38:40 -0600
commit18192166e79134ec5fda1ea26d4fcf7b24345b33 (patch)
tree674ab4b3e3890ff581e7312ede3015e9b3bc6af8
parent88d804b7ffa20caab2e8e2809da974c41f7fd8fc (diff)
downloadffmpeg-18192166e79134ec5fda1ea26d4fcf7b24345b33.tar.gz
lavc/videotoolboxenc: add ProRes support
-rw-r--r--Changelog1
-rwxr-xr-xconfigure2
-rw-r--r--libavcodec/Makefile1
-rw-r--r--libavcodec/allcodecs.c1
-rw-r--r--libavcodec/version.h2
-rw-r--r--libavcodec/videotoolboxenc.c120
6 files changed, 120 insertions, 7 deletions
diff --git a/Changelog b/Changelog
index 11f5d358c0..a613e2c5a6 100644
--- a/Changelog
+++ b/Changelog
@@ -42,6 +42,7 @@ version <next>:
- vflip_vulkan, hflip_vulkan and flip_vulkan filters
- adynamicequalizer audio filter
- yadif_videotoolbox filter
+- VideoToolbox ProRes encoder
version 4.4:
diff --git a/configure b/configure
index 0ccd3bda11..41912abeb4 100755
--- a/configure
+++ b/configure
@@ -3306,6 +3306,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 0250f6cea9..9577062eec 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 0588e593ad..e33a16fab1 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;
}
}
@@ -1102,7 +1128,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);
@@ -1189,7 +1215,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);
@@ -1338,7 +1364,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);
@@ -1388,16 +1414,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.10, *)) {
+ VTRegisterProfessionalVideoWorkflowVideoEncoders();
+ }
+ }
+#endif
+
vtctx->codec_id = avctx->codec_id;
if (vtctx->codec_id == AV_CODEC_ID_H264) {
@@ -1415,12 +1449,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(
@@ -2601,6 +2637,39 @@ static const enum AVPixelFormat hevc_pix_fmts[] = {
AV_PIX_FMT_NONE
};
+static const enum AVPixelFormat prores_pix_fmts[] = {
+ AV_PIX_FMT_VIDEOTOOLBOX,
+ 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, \
@@ -2704,3 +2773,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",
+};