History

lavc/videotoolboxenc: add ProRes support

rcombs committed 4 years ago

Commit 18192161 parent 88d804b6 files · +120 −7Browse files

Unified · Split

6 files
  1. Changelog +1 −0
  2. configure +2 −0
  3. libavcodec/Makefile +1 −0
  4. libavcodec/allcodecs.c +1 −0
  5. libavcodec/version.h +1 −1
  6. libavcodec/videotoolboxenc.c +114 −6
Changelog+1−0
@@ -42,6 +42,7 @@ version <next>: · 41 unmodified lines
4242 - vflip_vulkan, hflip_vulkan and flip_vulkan filters
4343 - adynamicequalizer audio filter
4444 - yadif_videotoolbox filter
45+- VideoToolbox ProRes encoder
4546
4647
4748 version 4.4:
configure+2−0
@@ -3306,6 +3306,8 @@ h264_videotoolbox_encoder_deps="pthreads" · 3305 unmodified lines
33063306 h264_videotoolbox_encoder_select="atsc_a53 videotoolbox_encoder"
33073307 hevc_videotoolbox_encoder_deps="pthreads"
33083308 hevc_videotoolbox_encoder_select="atsc_a53 videotoolbox_encoder"
3309+prores_videotoolbox_encoder_deps="pthreads"
3310+prores_videotoolbox_encoder_select="videotoolbox_encoder"
33093311 libaom_av1_decoder_deps="libaom"
33103312 libaom_av1_encoder_deps="libaom"
33113313 libaom_av1_encoder_select="extract_extradata_bsf"
libavcodec/Makefile+1−0
@@ -565,6 +565,7 @@ OBJS-$(CONFIG_PRORES_DECODER) += proresdec2.o proresdsp.o proresdata.o · 564 unmodified lines
565565 OBJS-$(CONFIG_PRORES_ENCODER) += proresenc_anatoliy.o proresdata.o
566566 OBJS-$(CONFIG_PRORES_AW_ENCODER) += proresenc_anatoliy.o proresdata.o
567567 OBJS-$(CONFIG_PRORES_KS_ENCODER) += proresenc_kostya.o proresdata.o
568+OBJS-$(CONFIG_PRORES_VIDEOTOOLBOX_ENCODER) += videotoolboxenc.o
568569 OBJS-$(CONFIG_PROSUMER_DECODER) += prosumer.o
569570 OBJS-$(CONFIG_PSD_DECODER) += psd.o
570571 OBJS-$(CONFIG_PTX_DECODER) += ptx.o
libavcodec/allcodecs.c+1−0
@@ -837,6 +837,7 @@ extern const AVCodec ff_mpeg4_cuvid_decoder; · 836 unmodified lines
837837 extern const AVCodec ff_mpeg4_mediacodec_decoder;
838838 extern const AVCodec ff_mpeg4_omx_encoder;
839839 extern const AVCodec ff_mpeg4_v4l2m2m_encoder;
840+extern const AVCodec ff_prores_videotoolbox_encoder;
840841 extern const AVCodec ff_vc1_cuvid_decoder;
841842 extern const AVCodec ff_vp8_cuvid_decoder;
842843 extern const AVCodec ff_vp8_mediacodec_decoder;
libavcodec/version.h+1−1
@@ -28,7 +28,7 @@ · 27 unmodified lines
2828 #include "libavutil/version.h"
2929
3030 #define LIBAVCODEC_VERSION_MAJOR 59
31−#define LIBAVCODEC_VERSION_MINOR 14
31+#define LIBAVCODEC_VERSION_MINOR 15
3232 #define LIBAVCODEC_VERSION_MICRO 100
3333
3434 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
libavcodec/videotoolboxenc.c+114−6
@@ -407,6 +407,7 @@ static int count_nalus(size_t length_code_size, · 406 unmodified lines
407407 }
408408
409409 static CMVideoCodecType get_cm_codec_type(AVCodecContext *avctx,
410+ int64_t profile,
410411 double alpha_quality)
411412 {
412413 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, · 4 unmodified lines
417418 return kCMVideoCodecType_HEVCWithAlpha;
418419 }
419420 return kCMVideoCodecType_HEVC;
421+ case AV_CODEC_ID_PRORES:
422+ switch (profile) {
423+ case FF_PROFILE_PRORES_PROXY:
424+ return MKBETAG('a','p','c','o'); // kCMVideoCodecType_AppleProRes422Proxy
425+ case FF_PROFILE_PRORES_LT:
426+ return MKBETAG('a','p','c','s'); // kCMVideoCodecType_AppleProRes422LT
427+ case FF_PROFILE_PRORES_STANDARD:
428+ return MKBETAG('a','p','c','n'); // kCMVideoCodecType_AppleProRes422
429+ case FF_PROFILE_PRORES_HQ:
430+ return MKBETAG('a','p','c','h'); // kCMVideoCodecType_AppleProRes422HQ
431+ case FF_PROFILE_PRORES_4444:
432+ return MKBETAG('a','p','4','h'); // kCMVideoCodecType_AppleProRes4444
433+ case FF_PROFILE_PRORES_XQ:
434+ return MKBETAG('a','p','4','x'); // kCMVideoCodecType_AppleProRes4444XQ
435+
436+ default:
437+ av_log(avctx, AV_LOG_ERROR, "Unknown profile ID: %"PRId64", using auto\n", profile);
438+ case FF_PROFILE_UNKNOWN:
439+ if (desc &&
440+ ((desc->flags & AV_PIX_FMT_FLAG_ALPHA) ||
441+ desc->log2_chroma_w == 0))
442+ return MKBETAG('a','p','4','h'); // kCMVideoCodecType_AppleProRes4444
443+ else
444+ return MKBETAG('a','p','c','n'); // kCMVideoCodecType_AppleProRes422
445+ }
420446 default: return 0;
421447 }
422448 }
@@ -1102,7 +1128,7 @@ static int vtenc_create_encoder(AVCodecContext *avctx, · 679 unmodified lines
11021128 kVTCompressionPropertyKey_Quality,
11031129 quality_num);
11041130 CFRelease(quality_num);
1105− } else {
1131+ } else if (avctx->codec_id != AV_CODEC_ID_PRORES) {
11061132 bit_rate_num = CFNumberCreate(kCFAllocatorDefault,
11071133 kCFNumberSInt32Type,
11081134 &bit_rate);
@@ -1189,7 +1215,7 @@ static int vtenc_create_encoder(AVCodecContext *avctx, · 80 unmodified lines
11891215 }
11901216 }
11911217
1192− if (avctx->gop_size > 0) {
1218+ if (avctx->gop_size > 0 && avctx->codec_id != AV_CODEC_ID_PRORES) {
11931219 CFNumberRef interval = CFNumberCreate(kCFAllocatorDefault,
11941220 kCFNumberIntType,
11951221 &avctx->gop_size);
@@ -1338,7 +1364,7 @@ static int vtenc_create_encoder(AVCodecContext *avctx, · 142 unmodified lines
13381364 }
13391365 }
13401366
1341− if (!vtctx->has_b_frames) {
1367+ if (!vtctx->has_b_frames && avctx->codec_id != AV_CODEC_ID_PRORES) {
13421368 status = VTSessionSetProperty(vtctx->session,
13431369 kVTCompressionPropertyKey_AllowFrameReordering,
13441370 kCFBooleanFalse);
@@ -1388,16 +1414,24 @@ static int vtenc_configure_encoder(AVCodecContext *avctx) · 43 unmodified lines
13881414 CFMutableDictionaryRef pixel_buffer_info;
13891415 CMVideoCodecType codec_type;
13901416 VTEncContext *vtctx = avctx->priv_data;
1391− CFStringRef profile_level;
1417+ CFStringRef profile_level = NULL;
13921418 CFNumberRef gamma_level = NULL;
13931419 int status;
13941420
1395− codec_type = get_cm_codec_type(avctx, vtctx->alpha_quality);
1421+ codec_type = get_cm_codec_type(avctx, vtctx->profile, vtctx->alpha_quality);
13961422 if (!codec_type) {
13971423 av_log(avctx, AV_LOG_ERROR, "Error: no mapping for AVCodecID %d\n", avctx->codec_id);
13981424 return AVERROR(EINVAL);
13991425 }
14001426
1427+#if defined(MAC_OS_X_VERSION_10_9) && !TARGET_OS_IPHONE && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9)
1428+ if (avctx->codec_id == AV_CODEC_ID_PRORES) {
1429+ if (__builtin_available(macOS 10.10, *)) {
1430+ VTRegisterProfessionalVideoWorkflowVideoEncoders();
1431+ }
1432+ }
1433+#endif
1434+
14011435 vtctx->codec_id = avctx->codec_id;
14021436
14031437 if (vtctx->codec_id == AV_CODEC_ID_H264) {
@@ -1415,12 +1449,14 @@ static int vtenc_configure_encoder(AVCodecContext *avctx) · 11 unmodified lines
14151449 }
14161450
14171451 if (!get_vt_h264_profile_level(avctx, &profile_level)) return AVERROR(EINVAL);
1418− } else {
1452+ } else if (vtctx->codec_id == AV_CODEC_ID_HEVC) {
14191453 vtctx->get_param_set_func = compat_keys.CMVideoFormatDescriptionGetHEVCParameterSetAtIndex;
14201454 if (!vtctx->get_param_set_func) return AVERROR(EINVAL);
14211455 if (!get_vt_hevc_profile_level(avctx, &profile_level)) return AVERROR(EINVAL);
14221456 // HEVC has b-byramid
14231457 vtctx->has_b_frames = avctx->max_b_frames > 0 ? 2 : 0;
1458+ } else if (vtctx->codec_id == AV_CODEC_ID_PRORES) {
1459+ avctx->codec_tag = av_bswap32(codec_type);
14241460 }
14251461
14261462 enc_info = CFDictionaryCreateMutable(
@@ -2601,6 +2637,39 @@ static const enum AVPixelFormat hevc_pix_fmts[] = { · 1174 unmodified lines
26012637 AV_PIX_FMT_NONE
26022638 };
26032639
2640+static const enum AVPixelFormat prores_pix_fmts[] = {
2641+ AV_PIX_FMT_VIDEOTOOLBOX,
2642+ AV_PIX_FMT_YUV420P,
2643+#ifdef kCFCoreFoundationVersionNumber10_7
2644+ AV_PIX_FMT_NV12,
2645+ AV_PIX_FMT_AYUV64,
2646+#endif
2647+ AV_PIX_FMT_UYVY422,
2648+#if HAVE_KCVPIXELFORMATTYPE_420YPCBCR10BIPLANARVIDEORANGE
2649+ AV_PIX_FMT_P010,
2650+#endif
2651+#if HAVE_KCVPIXELFORMATTYPE_422YPCBCR8BIPLANARVIDEORANGE
2652+ AV_PIX_FMT_NV16,
2653+#endif
2654+#if HAVE_KCVPIXELFORMATTYPE_422YPCBCR10BIPLANARVIDEORANGE
2655+ AV_PIX_FMT_P210,
2656+#endif
2657+#if HAVE_KCVPIXELFORMATTYPE_422YPCBCR16BIPLANARVIDEORANGE
2658+ AV_PIX_FMT_P216,
2659+#endif
2660+#if HAVE_KCVPIXELFORMATTYPE_444YPCBCR8BIPLANARVIDEORANGE
2661+ AV_PIX_FMT_NV24,
2662+#endif
2663+#if HAVE_KCVPIXELFORMATTYPE_444YPCBCR10BIPLANARVIDEORANGE
2664+ AV_PIX_FMT_P410,
2665+#endif
2666+#if HAVE_KCVPIXELFORMATTYPE_444YPCBCR16BIPLANARVIDEORANGE
2667+ AV_PIX_FMT_P416,
2668+#endif
2669+ AV_PIX_FMT_BGRA,
2670+ AV_PIX_FMT_NONE
2671+};
2672+
26042673 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
26052674 #define COMMON_OPTIONS \
26062675 { "allow_sw", "Allow software encoding", OFFSET(allow_sw), AV_OPT_TYPE_BOOL, \
@@ -2704,3 +2773,42 @@ const AVCodec ff_hevc_videotoolbox_encoder = { · 97 unmodified lines
27042773 FF_CODEC_CAP_INIT_CLEANUP,
27052774 .wrapper_name = "videotoolbox",
27062775 };
2776+
2777+static const AVOption prores_options[] = {
2778+ { "profile", "Profile", OFFSET(profile), AV_OPT_TYPE_INT64, { .i64 = FF_PROFILE_UNKNOWN }, FF_PROFILE_UNKNOWN, FF_PROFILE_PRORES_XQ, VE, "profile" },
2779+ { "auto", "Automatically determine based on input format", 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_UNKNOWN }, INT_MIN, INT_MAX, VE, "profile" },
2780+ { "proxy", "ProRes 422 Proxy", 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_PRORES_PROXY }, INT_MIN, INT_MAX, VE, "profile" },
2781+ { "lt", "ProRes 422 LT", 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_PRORES_LT }, INT_MIN, INT_MAX, VE, "profile" },
2782+ { "standard", "ProRes 422", 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_PRORES_STANDARD }, INT_MIN, INT_MAX, VE, "profile" },
2783+ { "hq", "ProRes 422 HQ", 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_PRORES_HQ }, INT_MIN, INT_MAX, VE, "profile" },
2784+ { "4444", "ProRes 4444", 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_PRORES_4444 }, INT_MIN, INT_MAX, VE, "profile" },
2785+ { "xq", "ProRes 4444 XQ", 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_PRORES_XQ }, INT_MIN, INT_MAX, VE, "profile" },
2786+
2787+ COMMON_OPTIONS
2788+ { NULL },
2789+};
2790+
2791+static const AVClass prores_videotoolbox_class = {
2792+ .class_name = "prores_videotoolbox",
2793+ .item_name = av_default_item_name,
2794+ .option = prores_options,
2795+ .version = LIBAVUTIL_VERSION_INT,
2796+};
2797+
2798+const AVCodec ff_prores_videotoolbox_encoder = {
2799+ .name = "prores_videotoolbox",
2800+ .long_name = NULL_IF_CONFIG_SMALL("VideoToolbox ProRes Encoder"),
2801+ .type = AVMEDIA_TYPE_VIDEO,
2802+ .id = AV_CODEC_ID_PRORES,
2803+ .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
2804+ AV_CODEC_CAP_HARDWARE,
2805+ .priv_data_size = sizeof(VTEncContext),
2806+ .pix_fmts = prores_pix_fmts,
2807+ .init = vtenc_init,
2808+ .encode2 = vtenc_frame,
2809+ .close = vtenc_close,
2810+ .priv_class = &prores_videotoolbox_class,
2811+ .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
2812+ FF_CODEC_CAP_INIT_CLEANUP,
2813+ .wrapper_name = "videotoolbox",
2814+};

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t