21#include <Availability.h>
22#include <CoreMedia/CoreMedia.h>
23#include <CoreVideo/CoreVideo.h>
26#include <TargetConditionals.h>
27#include <VideoToolbox/VideoToolbox.h>
45#if !HAVE_KCMVIDEOCODECTYPE_HEVC
49#if !HAVE_KCMVIDEOCODECTYPE_HEVCWITHALPHA
53#if !HAVE_KCVPIXELFORMATTYPE_420YPCBCR10BIPLANARVIDEORANGE
58#if !HAVE_KVTQPMODULATIONLEVEL_DEFAULT
63#ifndef TARGET_CPU_ARM64
64# define TARGET_CPU_ARM64 0
82#define REORDER_DELAY 2
85 size_t parameterSetIndex,
86 const uint8_t **parameterSetPointerOut,
87 size_t *parameterSetSizeOut,
88 size_t *parameterSetCountOut,
89 int *NALUnitHeaderLengthOut);
162#define GET_SYM(symbol, defaultVal) \
164 CFStringRef* handle = (CFStringRef*)dlsym(RTLD_DEFAULT, #symbol); \
166 compat_keys.symbol = CFSTR(defaultVal); \
168 compat_keys.symbol = *handle; \
174 compat_keys.CMVideoFormatDescriptionGetHEVCParameterSetAtIndex =
177 "CMVideoFormatDescriptionGetHEVCParameterSetAtIndex"
218 "TargetQualityForAlpha");
220 "PrioritizeEncodingSpeedOverQuality");
225 "EnableHardwareAcceleratedVideoEncoder");
227 "RequireHardwareAcceleratedVideoEncoder");
229 "EnableLowLatencyRateControl");
232 "MaximizePowerEfficiency");
234 "ReferenceBufferCount");
240#define H264_PROFILE_CONSTRAINED_HIGH (AV_PROFILE_H264_HIGH | AV_PROFILE_H264_CONSTRAINED)
330 CFStringRef encoder_id =
NULL;
332 CFIndex length, max_size;
335 status = VTSessionCopyProperty(vtctx->
session,
343 length = CFStringGetLength(encoder_id);
344 max_size = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
347 CFRelease(encoder_id);
351 CFStringGetCString(encoder_id,
354 kCFStringEncodingUTF8);
357 CFRelease(encoder_id);
364 CFStringRef profile_level,
365 CFNumberRef gamma_level,
366 CFDictionaryRef enc_info,
367 CFDictionaryRef pixel_buffer_info);
427 VTCompressionSessionInvalidate(vtctx->
session);
531 while (*link && *link != refcon)
532 link = &(*link)->
next;
545 CMSampleBufferRef sample_buffer,
552 size_t src_size = CMSampleBufferGetTotalSampleSize(sample_buffer);
553 CMBlockBufferRef
block = CMSampleBufferGetDataBuffer(sample_buffer);
555 if (length_code_size > 4)
558 while (
offset < src_size) {
563 status = CMBlockBufferCopyDataBytes(
block,
568 if (status != kCMBlockBufferNoErr) {
572 for (
i = 0;
i < length_code_size;
i++) {
574 box_len |= size_buf[
i];
577 curr_src_len = box_len + length_code_size;
589 double alpha_quality)
604 return MKBETAG(
'a',
'p',
'c',
'o');
606 return MKBETAG(
'a',
'p',
'c',
's');
608 return MKBETAG(
'a',
'p',
'c',
'n');
610 return MKBETAG(
'a',
'p',
'c',
'h');
612 return MKBETAG(
'a',
'p',
'4',
'h');
614 return MKBETAG(
'a',
'p',
'4',
'x');
622 desc->log2_chroma_w == 0))
623 return MKBETAG(
'a',
'p',
'4',
'h');
625 return MKBETAG(
'a',
'p',
'c',
'n');
641 CMVideoFormatDescriptionRef vid_fmt,
645 size_t total_size = 0;
647 int is_count_bad = 0;
662 for (
i = 0;
i < ps_count || is_count_bad;
i++) {
676 if (
i > 0 && is_count_bad) status = 0;
695 CMVideoFormatDescriptionRef vid_fmt,
701 int is_count_bad = 0;
719 for (
i = 0;
i < ps_count || is_count_bad;
i++) {
731 if (
i > 0 && is_count_bad) status = 0;
737 if (dst_size < next_offset) {
760 CMVideoFormatDescriptionRef vid_fmt;
764 vid_fmt = CMSampleBufferGetFormatDescription(sample_buffer);
790 CFDataRef
data = CMFormatDescriptionGetExtension(vid_fmt, kCMFormatDescriptionExtension_VerbatimSampleDescription);
791 if (
data && CFGetTypeID(
data) == CFDataGetTypeID()) {
792 CFIndex
size = CFDataGetLength(
data);
808 void *sourceFrameCtx,
810 VTEncodeInfoFlags
flags,
811 CMSampleBufferRef sample_buffer)
835 if (!sample_buffer) {
840 CFRetain(sample_buffer);
857 CMSampleBufferRef sample_buffer,
861 CMVideoFormatDescriptionRef vid_fmt;
865 vid_fmt = CMSampleBufferGetFormatDescription(sample_buffer);
893 CFStringRef *profile_level_val)
903 *profile_level_val =
NULL;
910 switch (vtctx->
level) {
911 case 0: *profile_level_val =
912 compat_keys.kVTProfileLevel_H264_Baseline_AutoLevel;
break;
913 case 13: *profile_level_val = kVTProfileLevel_H264_Baseline_1_3;
break;
914 case 30: *profile_level_val = kVTProfileLevel_H264_Baseline_3_0;
break;
915 case 31: *profile_level_val = kVTProfileLevel_H264_Baseline_3_1;
break;
916 case 32: *profile_level_val = kVTProfileLevel_H264_Baseline_3_2;
break;
917 case 40: *profile_level_val =
918 compat_keys.kVTProfileLevel_H264_Baseline_4_0;
break;
919 case 41: *profile_level_val = kVTProfileLevel_H264_Baseline_4_1;
break;
920 case 42: *profile_level_val =
921 compat_keys.kVTProfileLevel_H264_Baseline_4_2;
break;
922 case 50: *profile_level_val =
923 compat_keys.kVTProfileLevel_H264_Baseline_5_0;
break;
924 case 51: *profile_level_val =
925 compat_keys.kVTProfileLevel_H264_Baseline_5_1;
break;
926 case 52: *profile_level_val =
927 compat_keys.kVTProfileLevel_H264_Baseline_5_2;
break;
932 *profile_level_val =
compat_keys.kVTProfileLevel_H264_ConstrainedBaseline_AutoLevel;
934 if (vtctx->
level != 0) {
937 "Level is auto-selected when constrained-baseline "
938 "profile is used. The output may be encoded with a "
939 "different level.\n");
944 switch (vtctx->
level) {
945 case 0: *profile_level_val =
946 compat_keys.kVTProfileLevel_H264_Main_AutoLevel;
break;
947 case 30: *profile_level_val = kVTProfileLevel_H264_Main_3_0;
break;
948 case 31: *profile_level_val = kVTProfileLevel_H264_Main_3_1;
break;
949 case 32: *profile_level_val = kVTProfileLevel_H264_Main_3_2;
break;
950 case 40: *profile_level_val = kVTProfileLevel_H264_Main_4_0;
break;
951 case 41: *profile_level_val = kVTProfileLevel_H264_Main_4_1;
break;
952 case 42: *profile_level_val =
954 case 50: *profile_level_val = kVTProfileLevel_H264_Main_5_0;
break;
955 case 51: *profile_level_val =
957 case 52: *profile_level_val =
963 *profile_level_val =
compat_keys.kVTProfileLevel_H264_ConstrainedHigh_AutoLevel;
965 if (vtctx->
level != 0) {
968 "Level is auto-selected when constrained-high profile "
969 "is used. The output may be encoded with a different "
975 switch (vtctx->
level) {
976 case 0: *profile_level_val =
977 compat_keys.kVTProfileLevel_H264_High_AutoLevel;
break;
978 case 30: *profile_level_val =
980 case 31: *profile_level_val =
982 case 32: *profile_level_val =
984 case 40: *profile_level_val =
986 case 41: *profile_level_val =
988 case 42: *profile_level_val =
990 case 50: *profile_level_val = kVTProfileLevel_H264_High_5_0;
break;
991 case 51: *profile_level_val =
993 case 52: *profile_level_val =
998 switch (vtctx->
level) {
999 case 0: *profile_level_val =
1000 compat_keys.kVTProfileLevel_H264_Extended_AutoLevel;
break;
1001 case 50: *profile_level_val =
1002 compat_keys.kVTProfileLevel_H264_Extended_5_0;
break;
1007 if (!*profile_level_val) {
1022 CFStringRef *profile_level_val)
1031 *profile_level_val =
NULL;
1037 *profile_level_val =
1038 compat_keys.kVTProfileLevel_HEVC_Main10_AutoLevel;
1045 "main profile with %d bit input\n",
bit_depth);
1046 *profile_level_val =
1052 "Invalid main10 profile with %d bit input\n",
bit_depth);
1055 *profile_level_val =
1056 compat_keys.kVTProfileLevel_HEVC_Main10_AutoLevel;
1060 *profile_level_val =
1061 compat_keys.kVTProfileLevel_HEVC_Main42210_AutoLevel;
1065 if (!*profile_level_val) {
1076 int* av_pixel_format,
1079 const char *range_name;
1085 if (*av_pixel_format)
1090 "Could not get pixel format for color format '%s' range '%s'.\n",
1092 range_name ? range_name :
"Unknown");
1101 CFDictionarySetValue(dict,
1102 kCVImageBufferColorPrimariesKey,
1107 CFDictionarySetValue(dict,
1108 kCVImageBufferTransferFunctionKey,
1113 CFDictionarySetValue(dict,
1114 kCVImageBufferYCbCrMatrixKey,
1120 CFMutableDictionaryRef* dict)
1122 CFNumberRef cv_color_format_num =
NULL;
1123 CFNumberRef width_num =
NULL;
1124 CFNumberRef height_num =
NULL;
1125 CFMutableDictionaryRef pixel_buffer_info =
NULL;
1126 int cv_color_format;
1132 if (status)
return status;
1134 pixel_buffer_info = CFDictionaryCreateMutable(
1135 kCFAllocatorDefault,
1137 &kCFCopyStringDictionaryKeyCallBacks,
1138 &kCFTypeDictionaryValueCallBacks);
1140 if (!pixel_buffer_info)
goto pbinfo_nomem;
1142 cv_color_format_num = CFNumberCreate(kCFAllocatorDefault,
1143 kCFNumberSInt32Type,
1145 if (!cv_color_format_num)
goto pbinfo_nomem;
1147 CFDictionarySetValue(pixel_buffer_info,
1148 kCVPixelBufferPixelFormatTypeKey,
1149 cv_color_format_num);
1152 width_num = CFNumberCreate(kCFAllocatorDefault,
1153 kCFNumberSInt32Type,
1155 if (!width_num)
goto pbinfo_nomem;
1157 CFDictionarySetValue(pixel_buffer_info,
1158 kCVPixelBufferWidthKey,
1162 height_num = CFNumberCreate(kCFAllocatorDefault,
1163 kCFNumberSInt32Type,
1165 if (!height_num)
goto pbinfo_nomem;
1167 CFDictionarySetValue(pixel_buffer_info,
1168 kCVPixelBufferHeightKey,
1174 *dict = pixel_buffer_info;
1181 if (pixel_buffer_info) CFRelease(pixel_buffer_info);
1187 CFNumberRef *gamma_level)
1191 *gamma_level =
NULL;
1199 *gamma_level = CFNumberCreate(
NULL, kCFNumberFloat32Type, &gamma);
1211 const char *print_option_name,
1217 if (status == kVTPropertyNotSupportedErr) {
1220 "This device does not support the %s option. Value ignored.\n",
1222 }
else if (status != 0) {
1225 "Error setting %s: Error %d\n",
1233 const char* print_option_name,
1235 CFNumberRef value_cfnum = CFNumberCreate(kCFAllocatorDefault,
1239 if (value_cfnum ==
NULL) {
1245 CFRelease(value_cfnum);
1252 CFStringRef profile_level,
1253 CFNumberRef gamma_level,
1254 CFDictionaryRef enc_info,
1255 CFDictionaryRef pixel_buffer_info,
1256 bool constant_bit_rate,
1257 VTCompressionSessionRef *session)
1262 CFNumberRef bit_rate_num;
1263 CFNumberRef bytes_per_second;
1264 CFNumberRef one_second;
1265 CFArrayRef data_rate_limits;
1266 int64_t bytes_per_second_value = 0;
1270 int status = VTCompressionSessionCreate(kCFAllocatorDefault,
1276 kCFAllocatorDefault,
1281 if (status || !vtctx->
session) {
1284#if !TARGET_OS_IPHONE
1286 av_log(avctx,
AV_LOG_ERROR,
"Try -allow_sw 1. The hardware encoder may be busy, or not supported.\n");
1293#if defined (MAC_OS_X_VERSION_10_13) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_13)
1294 if (__builtin_available(macOS 10.13, iOS 11.0, *)) {
1299 status = VTCopySupportedPropertyDictionaryForEncoder(avctx->
width,
1306 if (status != noErr) {
1318 av_log(avctx,
AV_LOG_ERROR,
"-q:v qscale not available for encoder. Use -b:v bitrate instead.\n");
1326 CFNumberRef quality_num = CFNumberCreate(kCFAllocatorDefault,
1327 kCFNumberFloat32Type,
1329 if (!quality_num)
return AVERROR(ENOMEM);
1331 status = VTSessionSetProperty(vtctx->
session,
1332 kVTCompressionPropertyKey_Quality,
1334 CFRelease(quality_num);
1336 bit_rate_num = CFNumberCreate(kCFAllocatorDefault,
1337 kCFNumberSInt32Type,
1339 if (!bit_rate_num)
return AVERROR(ENOMEM);
1341 if (constant_bit_rate) {
1342 status = VTSessionSetProperty(vtctx->
session,
1343 compat_keys.kVTCompressionPropertyKey_ConstantBitRate,
1345 if (status == kVTPropertyNotSupportedErr) {
1346 av_log(avctx,
AV_LOG_ERROR,
"-constant_bit_rate true is not supported by the encoder.\n");
1347 CFRelease(bit_rate_num);
1351 status = VTSessionSetProperty(vtctx->
session,
1352 kVTCompressionPropertyKey_AverageBitRate,
1356 CFRelease(bit_rate_num);
1365 status = VTSessionSetProperty(vtctx->
session,
1366 compat_keys.kVTCompressionPropertyKey_PrioritizeEncodingSpeedOverQuality,
1367 vtctx->
prio_speed ? kCFBooleanTrue : kCFBooleanFalse);
1369 av_log(avctx,
AV_LOG_WARNING,
"PrioritizeEncodingSpeedOverQuality property is not supported on this device. Ignoring.\n");
1375 bytes_per_second_value = max_rate >> 3;
1376 bytes_per_second = CFNumberCreate(kCFAllocatorDefault,
1377 kCFNumberSInt64Type,
1378 &bytes_per_second_value);
1379 if (!bytes_per_second) {
1382 one_second_value = 1;
1383 one_second = CFNumberCreate(kCFAllocatorDefault,
1384 kCFNumberSInt64Type,
1387 CFRelease(bytes_per_second);
1390 nums[0] = (
void *)bytes_per_second;
1391 nums[1] = (
void *)one_second;
1392 data_rate_limits = CFArrayCreate(kCFAllocatorDefault,
1393 (
const void **)nums,
1395 &kCFTypeArrayCallBacks);
1397 if (!data_rate_limits) {
1398 CFRelease(bytes_per_second);
1399 CFRelease(one_second);
1402 status = VTSessionSetProperty(vtctx->
session,
1403 kVTCompressionPropertyKey_DataRateLimits,
1406 CFRelease(bytes_per_second);
1407 CFRelease(one_second);
1408 CFRelease(data_rate_limits);
1424 CFNumberRef alpha_quality_num = CFNumberCreate(kCFAllocatorDefault,
1425 kCFNumberDoubleType,
1427 if (!alpha_quality_num)
return AVERROR(ENOMEM);
1429 status = VTSessionSetProperty(vtctx->
session,
1430 compat_keys.kVTCompressionPropertyKey_TargetQualityForAlpha,
1432 CFRelease(alpha_quality_num);
1437 "Error setting alpha quality: %d\n",
1443 if (profile_level) {
1444 status = VTSessionSetProperty(vtctx->
session,
1445 kVTCompressionPropertyKey_ProfileLevel,
1448 av_log(avctx,
AV_LOG_ERROR,
"Error setting profile/level property: %d. Output will be encoded using a supported profile/level combination.\n", status);
1453 CFNumberRef interval = CFNumberCreate(kCFAllocatorDefault,
1460 status = VTSessionSetProperty(vtctx->
session,
1461 kVTCompressionPropertyKey_MaxKeyFrameInterval,
1463 CFRelease(interval);
1466 av_log(avctx,
AV_LOG_ERROR,
"Error setting 'max key-frame interval' property: %d\n", status);
1472 status = VTSessionSetProperty(vtctx->
session,
1473 kVTCompressionPropertyKey_MoreFramesBeforeStart,
1476 if (status == kVTPropertyNotSupportedErr) {
1477 av_log(avctx,
AV_LOG_WARNING,
"frames_before property is not supported on this device. Ignoring.\n");
1478 }
else if (status) {
1484 status = VTSessionSetProperty(vtctx->
session,
1485 kVTCompressionPropertyKey_MoreFramesAfterEnd,
1488 if (status == kVTPropertyNotSupportedErr) {
1489 av_log(avctx,
AV_LOG_WARNING,
"frames_after property is not supported on this device. Ignoring.\n");
1490 }
else if (status) {
1498 CFMutableDictionaryRef par;
1505 num = CFNumberCreate(kCFAllocatorDefault,
1509 den = CFNumberCreate(kCFAllocatorDefault,
1515 par = CFDictionaryCreateMutable(kCFAllocatorDefault,
1517 &kCFCopyStringDictionaryKeyCallBacks,
1518 &kCFTypeDictionaryValueCallBacks);
1520 if (!par || !
num || !den) {
1521 if (par) CFRelease(par);
1523 if (den) CFRelease(den);
1528 CFDictionarySetValue(
1530 kCMFormatDescriptionKey_PixelAspectRatioHorizontalSpacing,
1533 CFDictionarySetValue(
1535 kCMFormatDescriptionKey_PixelAspectRatioVerticalSpacing,
1538 status = VTSessionSetProperty(vtctx->
session,
1539 kVTCompressionPropertyKey_PixelAspectRatio,
1549 "Error setting pixel aspect ratio to %d:%d: %d.\n",
1560 status = VTSessionSetProperty(vtctx->
session,
1561 kVTCompressionPropertyKey_TransferFunction,
1571 status = VTSessionSetProperty(vtctx->
session,
1572 kVTCompressionPropertyKey_YCbCrMatrix,
1582 status = VTSessionSetProperty(vtctx->
session,
1583 kVTCompressionPropertyKey_ColorPrimaries,
1592 status = VTSessionSetProperty(vtctx->
session,
1593 kCVImageBufferGammaLevelKey,
1602 status = VTSessionSetProperty(vtctx->
session,
1603 kVTCompressionPropertyKey_AllowFrameReordering,
1607 av_log(avctx,
AV_LOG_ERROR,
"Error setting 'allow frame reordering' property: %d\n", status);
1617 status = VTSessionSetProperty(vtctx->
session,
1618 compat_keys.kVTCompressionPropertyKey_H264EntropyMode,
1627 status = VTSessionSetProperty(vtctx->
session,
1629 vtctx->
realtime ? kCFBooleanTrue : kCFBooleanFalse);
1638 compat_keys.kVTCompressionPropertyKey_AllowOpenGOP,
1643 if (avctx->
qmin >= 0) {
1645 compat_keys.kVTCompressionPropertyKey_MinAllowedFrameQP,
1654 if (avctx->
qmax >= 0) {
1656 compat_keys.kVTCompressionPropertyKey_MaxAllowedFrameQP,
1667 kVTCompressionPropertyKey_MaxH264SliceBytes,
1678 compat_keys.kVTCompressionPropertyKey_MaximizePowerEfficiency,
1685 compat_keys.kVTCompressionPropertyKey_ReferenceBufferCount,
1696 compat_keys.kVTCompressionPropertyKey_SpatialAdaptiveQPLevel,
1701 status = VTCompressionSessionPrepareToEncodeFrames(vtctx->
session);
1712 CFMutableDictionaryRef enc_info;
1713 CFMutableDictionaryRef pixel_buffer_info =
NULL;
1716 CFStringRef profile_level =
NULL;
1717 CFNumberRef gamma_level =
NULL;
1726#if defined(MAC_OS_X_VERSION_10_9) && !TARGET_OS_IPHONE && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9)
1728 if (__builtin_available(macOS 10.10, *)) {
1729 VTRegisterProfessionalVideoWorkflowVideoEncoders();
1741 av_log(avctx,
AV_LOG_WARNING,
"Cannot use B-frames with baseline profile. Output will not contain B-frames.\n");
1746 av_log(avctx,
AV_LOG_WARNING,
"CABAC entropy requires 'main' or 'high' profile, but baseline was requested. Encode will not use CABAC entropy.\n");
1760 enc_info = CFDictionaryCreateMutable(
1761 kCFAllocatorDefault,
1763 &kCFCopyStringDictionaryKeyCallBacks,
1764 &kCFTypeDictionaryValueCallBacks
1767 if (!enc_info)
return AVERROR(ENOMEM);
1769#if !TARGET_OS_IPHONE
1771 CFDictionarySetValue(enc_info,
1772 compat_keys.kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder,
1775 CFDictionarySetValue(enc_info,
1776 compat_keys.kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder,
1779 CFDictionarySetValue(enc_info,
1780 compat_keys.kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder,
1790 "please specify bitrate explicitly\n");
1794 CFDictionarySetValue(enc_info,
1795 compat_keys.kVTVideoEncoderSpecification_EnableLowLatencyRateControl,
1835 CFRelease(gamma_level);
1837 if (pixel_buffer_info)
1838 CFRelease(pixel_buffer_info);
1840 CFRelease(enc_info);
1848 CFBooleanRef has_b_frames_cfbool;
1860 if (status)
return status;
1862 status = VTSessionCopyProperty(vtctx->
session,
1863 kVTCompressionPropertyKey_AllowFrameReordering,
1864 kCFAllocatorDefault,
1865 &has_b_frames_cfbool);
1867 if (!status && has_b_frames_cfbool) {
1869 if (CFBooleanGetValue(has_b_frames_cfbool))
1873 CFRelease(has_b_frames_cfbool);
1882 CFArrayRef attachments;
1883 CFDictionaryRef attachment;
1884 CFBooleanRef not_sync;
1887 attachments = CMSampleBufferGetSampleAttachmentsArray(
buffer,
false);
1888 len = !attachments ? 0 : CFArrayGetCount(attachments);
1891 *is_key_frame =
true;
1895 attachment = CFArrayGetValueAtIndex(attachments, 0);
1897 if (CFDictionaryGetValueIfPresent(attachment,
1898 kCMSampleAttachmentKey_NotSync,
1899 (
const void **)¬_sync))
1901 *is_key_frame = !CFBooleanGetValue(not_sync);
1903 *is_key_frame =
true;
1924 size_t sei_payload_size = 0;
1925 uint8_t *nal_start = nal_data;
1931 nal_type = *nal_data & 0x1F;
1938 if (nal_data[nal_size - 1] == 0x80)
1941 while (nal_size > 0 && *nal_data > 0) {
1945 }
while (nal_size > 0 && *nal_data == 0xFF);
1953 sei_payload_size += *nal_data;
1956 }
while (nal_size > 0 && *nal_data == 0xFF);
1958 if (nal_size < sei_payload_size) {
1963 nal_data += sei_payload_size;
1964 nal_size -= sei_payload_size;
1967 *sei_end = nal_data;
1969 return nal_data - nal_start + 1;
1989 uint8_t* dst_end =
dst + dst_size;
1990 const uint8_t* src_end =
src + src_size;
1991 int start_at = dst_offset > 2 ? dst_offset - 2 : 0;
1993 for (
i = start_at;
i < dst_offset &&
i < dst_size;
i++) {
2004 int insert_ep3_byte = *
src <= 3;
2005 if (insert_ep3_byte) {
2023 wrote_bytes =
dst - dst_start;
2026 return -wrote_bytes;
2036 uint8_t *sei_start =
dst;
2037 size_t remaining_sei_size =
sei->size;
2038 size_t remaining_dst_size = dst_size;
2043 if (!remaining_dst_size)
2046 while (sei_type && remaining_dst_size != 0) {
2047 int sei_byte = sei_type > 255 ? 255 : sei_type;
2050 sei_type -= sei_byte;
2052 remaining_dst_size--;
2058 while (remaining_sei_size && remaining_dst_size != 0) {
2059 int size_byte = remaining_sei_size > 255 ? 255 : remaining_sei_size;
2062 remaining_sei_size -= size_byte;
2064 remaining_dst_size--;
2067 if (remaining_dst_size < sei->
size)
2070 header_bytes =
dst - sei_start;
2078 if (bytes_written < 0)
2081 bytes_written += header_bytes;
2082 return bytes_written;
2106 size_t length_code_size,
2107 CMSampleBufferRef sample_buffer,
2112 size_t src_size = CMSampleBufferGetTotalSampleSize(sample_buffer);
2113 size_t remaining_src_size = src_size;
2114 size_t remaining_dst_size = dst_size;
2115 size_t src_offset = 0;
2118 uint8_t size_buf[4];
2120 CMBlockBufferRef
block = CMSampleBufferGetDataBuffer(sample_buffer);
2122 if (length_code_size > 4) {
2126 while (remaining_src_size > 0) {
2127 size_t curr_src_len;
2128 size_t curr_dst_len;
2134 status = CMBlockBufferCopyDataBytes(
block,
2143 status = CMBlockBufferCopyDataBytes(
block,
2144 src_offset + length_code_size,
2155 for (
i = 0;
i < length_code_size;
i++) {
2157 box_len |= size_buf[
i];
2170 remaining_dst_size--;
2175 remaining_dst_size);
2177 if (wrote_bytes < 0)
2180 remaining_dst_size -= wrote_bytes;
2181 dst_data += wrote_bytes;
2183 if (remaining_dst_size <= 0)
2189 remaining_dst_size--;
2194 curr_src_len = box_len + length_code_size;
2197 if (remaining_src_size < curr_src_len) {
2201 if (remaining_dst_size < curr_dst_len) {
2208 status = CMBlockBufferCopyDataBytes(
block,
2209 src_offset + length_code_size,
2224 old_sei_length =
find_sei_end(avctx, dst_box, box_len, &new_sei);
2225 if (old_sei_length < 0)
2226 return old_sei_length;
2231 remaining_dst_size - old_sei_length);
2232 if (wrote_bytes < 0)
2235 if (new_sei + wrote_bytes >= dst_data + remaining_dst_size)
2238 new_sei[wrote_bytes++] = 0x80;
2239 extra_bytes = wrote_bytes - (dst_box + box_len - new_sei);
2241 dst_data += extra_bytes;
2242 remaining_dst_size -= extra_bytes;
2247 src_offset += curr_src_len;
2248 dst_data += curr_dst_len;
2250 remaining_src_size -= curr_src_len;
2251 remaining_dst_size -= curr_dst_len;
2272 if ((
sei->size % 255) == 0)
2275 return copied_size +
sei->size / 255 + 1 +
type / 255 + 1;
2280 CMSampleBufferRef sample_buffer,
2289 size_t length_code_size;
2290 size_t header_size = 0;
2292 size_t out_buf_size;
2293 size_t sei_nalu_size = 0;
2298 CMVideoFormatDescriptionRef vid_fmt;
2304 if (status)
return status;
2309 vid_fmt = CMSampleBufferGetFormatDescription(sample_buffer);
2316 if (status)
return status;
2319 status =
count_nalus(length_code_size, sample_buffer, &nalu_count);
2327 sei_nalu_size =
sizeof(
start_code) + 1 + msg_size + 1;
2330 in_buf_size = CMSampleBufferGetTotalSampleSize(sample_buffer);
2331 out_buf_size = header_size +
2334 nalu_count * ((int)
sizeof(
start_code) - (int)length_code_size);
2342 if(status)
return status;
2350 pkt->data + header_size,
2351 pkt->size - header_size
2360 CMBlockBufferRef buf = CMSampleBufferGetDataBuffer(sample_buffer);
2366 len = CMBlockBufferGetDataLength(buf);
2372 status = CMBlockBufferCopyDataBytes(buf, 0,
len,
pkt->data);
2383 pts = CMSampleBufferGetPresentationTimeStamp(sample_buffer);
2384 dts = CMSampleBufferGetDecodeTimeStamp (sample_buffer);
2386 if (CMTIME_IS_INVALID(
pts)) {
2391 if (CMTIME_IS_INVALID(dts)) {
2410 CVPixelBufferRef cv_img)
2415 size_t num_cv_plane = CVPixelBufferIsPlanar(cv_img) ?
2416 CVPixelBufferGetPlaneCount(cv_img) : 1;
2417 if (num_planes != num_cv_plane) {
2419 "Different number of planes in AVFrame and CVPixelBuffer.\n");
2423 status = CVPixelBufferLockBaseAddress(cv_img, 0);
2425 av_log(avctx,
AV_LOG_ERROR,
"Could not lock base address of CVPixelBuffer: %d.\n", status);
2429 int dst_stride[4] = {0};
2430 uint8_t *dst_addr[4] = {0};
2431 for (
int i = 0;
i < num_planes;
i++) {
2432 dst_addr[
i] = (uint8_t*)CVPixelBufferGetBaseAddressOfPlane(cv_img,
i);
2433 dst_stride[
i] = CVPixelBufferGetBytesPerRowOfPlane(cv_img,
i);
2438 status = CVPixelBufferUnlockBaseAddress(cv_img, 0);
2440 av_log(avctx,
AV_LOG_ERROR,
"Could not unlock CVPixelBuffer base address: %d.\n", status);
2449 CVPixelBufferRef *cv_img,
2453 CVPixelBufferPoolRef pix_buf_pool;
2459 *cv_img = (CVPixelBufferRef)
frame->data[3];
2463 if (
frame->buf[0]) {
2474 &(
int) {0}, &range_guessed);
2480 if (range_guessed) {
2488 pix_buf_pool = VTCompressionSessionGetPixelBufferPool(vtctx->
session);
2489 if (!pix_buf_pool) {
2496 vtstatus = VTCompressionSessionPrepareToEncodeFrames(vtctx->
session);
2497 if (vtstatus == kVTInvalidSessionErr) {
2502 pix_buf_pool = VTCompressionSessionGetPixelBufferPool(vtctx->
session);
2504 if (!pix_buf_pool) {
2510 "kVTInvalidSessionErr error.\n");
2513 status = CVPixelBufferPoolCreatePixelBuffer(
NULL,
2519 av_log(avctx,
AV_LOG_ERROR,
"Could not create pixel buffer from pool: %d.\n", status);
2534 CFDictionaryRef* dict_out)
2536 CFDictionaryRef dict =
NULL;
2538 const void *keys[] = { kVTEncodeFrameOptionKey_ForceKeyFrame };
2539 const void *vals[] = { kCFBooleanTrue };
2541 dict = CFDictionaryCreate(
NULL, keys, vals, 1,
NULL,
NULL);
2542 if(!dict)
return AVERROR(ENOMEM);
2554 CFDictionaryRef frame_dict =
NULL;
2555 CVPixelBufferRef cv_img =
NULL;
2573 if (vtctx->
a53_cc && side_data && side_data->
size) {
2585 status = VTCompressionSessionEncodeFrame(
2605 CFRelease(frame_dict);
2623 CMSampleBufferRef buf =
NULL;
2644 status = VTCompressionSessionCompleteFrames(vtctx->
session,
2662 if (status)
goto end_nopkt;
2663 if (!buf)
goto end_nopkt;
2668 if (status)
goto end_nopkt;
2680 CFStringRef profile_level,
2681 CFNumberRef gamma_level,
2682 CFDictionaryRef enc_info,
2683 CFDictionaryRef pixel_buffer_info)
2687 CVPixelBufferPoolRef pool =
NULL;
2688 CVPixelBufferRef pix_buf =
NULL;
2690 CMSampleBufferRef buf =
NULL;
2707 pool = VTCompressionSessionGetPixelBufferPool(vtctx->
session);
2714 status = CVPixelBufferPoolCreatePixelBuffer(
NULL,
2718 if(status != kCVReturnSuccess){
2728 status = VTCompressionSessionEncodeFrame(vtctx->
session,
2740 "Error sending frame for extradata: %d\n",
2747 status = VTCompressionSessionCompleteFrames(vtctx->
session,
2771 CVPixelBufferRelease(pix_buf);
2795 VTCompressionSessionCompleteFrames(vtctx->
session,
2830#ifdef kCFCoreFoundationVersionNumber10_7
2835#if HAVE_KCVPIXELFORMATTYPE_420YPCBCR10BIPLANARVIDEORANGE
2838#if HAVE_KCVPIXELFORMATTYPE_422YPCBCR8BIPLANARVIDEORANGE
2841#if HAVE_KCVPIXELFORMATTYPE_422YPCBCR10BIPLANARVIDEORANGE
2844#if HAVE_KCVPIXELFORMATTYPE_422YPCBCR16BIPLANARVIDEORANGE
2847#if HAVE_KCVPIXELFORMATTYPE_444YPCBCR8BIPLANARVIDEORANGE
2850#if HAVE_KCVPIXELFORMATTYPE_444YPCBCR10BIPLANARVIDEORANGE
2853#if HAVE_KCVPIXELFORMATTYPE_444YPCBCR16BIPLANARVIDEORANGE
2860#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
2861#define COMMON_OPTIONS \
2862 { "allow_sw", "Allow software encoding", OFFSET(allow_sw), AV_OPT_TYPE_BOOL, \
2863 { .i64 = 0 }, 0, 1, VE }, \
2864 { "require_sw", "Require software encoding", OFFSET(require_sw), AV_OPT_TYPE_BOOL, \
2865 { .i64 = 0 }, 0, 1, VE }, \
2866 { "realtime", "Hint that encoding should happen in real-time if not faster (e.g. capturing from camera).", \
2867 OFFSET(realtime), AV_OPT_TYPE_BOOL, { .i64 = 0 }, -1, 1, VE }, \
2868 { "frames_before", "Other frames will come before the frames in this session. This helps smooth concatenation issues.", \
2869 OFFSET(frames_before), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, \
2870 { "frames_after", "Other frames will come after the frames in this session. This helps smooth concatenation issues.", \
2871 OFFSET(frames_after), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, \
2872 { "prio_speed", "prioritize encoding speed", OFFSET(prio_speed), AV_OPT_TYPE_BOOL, \
2873 { .i64 = -1 }, -1, 1, VE }, \
2874 { "power_efficient", "Set to 1 to enable more power-efficient encoding if supported.", \
2875 OFFSET(power_efficient), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE }, \
2876 { "spatial_aq", "Set to 1 to enable spatial AQ if supported.", \
2877 OFFSET(spatialaq), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE }, \
2878 { "max_ref_frames", \
2879 "Sets the maximum number of reference frames. This only has an effect when the value is less than the maximum allowed by the profile/level.", \
2880 OFFSET(max_ref_frames), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
2887#define OFFSET(x) offsetof(VTEncContext, x)
2898 {
"1.3",
"Level 1.3, only available with Baseline Profile", 0,
AV_OPT_TYPE_CONST, { .i64 = 13 }, INT_MIN, INT_MAX,
VE, .unit =
"level" },
2899 {
"3.0",
"Level 3.0", 0,
AV_OPT_TYPE_CONST, { .i64 = 30 }, INT_MIN, INT_MAX,
VE, .unit =
"level" },
2900 {
"3.1",
"Level 3.1", 0,
AV_OPT_TYPE_CONST, { .i64 = 31 }, INT_MIN, INT_MAX,
VE, .unit =
"level" },
2901 {
"3.2",
"Level 3.2", 0,
AV_OPT_TYPE_CONST, { .i64 = 32 }, INT_MIN, INT_MAX,
VE, .unit =
"level" },
2902 {
"4.0",
"Level 4.0", 0,
AV_OPT_TYPE_CONST, { .i64 = 40 }, INT_MIN, INT_MAX,
VE, .unit =
"level" },
2903 {
"4.1",
"Level 4.1", 0,
AV_OPT_TYPE_CONST, { .i64 = 41 }, INT_MIN, INT_MAX,
VE, .unit =
"level" },
2904 {
"4.2",
"Level 4.2", 0,
AV_OPT_TYPE_CONST, { .i64 = 42 }, INT_MIN, INT_MAX,
VE, .unit =
"level" },
2905 {
"5.0",
"Level 5.0", 0,
AV_OPT_TYPE_CONST, { .i64 = 50 }, INT_MIN, INT_MAX,
VE, .unit =
"level" },
2906 {
"5.1",
"Level 5.1", 0,
AV_OPT_TYPE_CONST, { .i64 = 51 }, INT_MIN, INT_MAX,
VE, .unit =
"level" },
2907 {
"5.2",
"Level 5.2", 0,
AV_OPT_TYPE_CONST, { .i64 = 52 }, INT_MIN, INT_MAX,
VE, .unit =
"level" },
2917 {
"constant_bit_rate",
"Require constant bit rate (macOS 13 or newer)",
OFFSET(constant_bit_rate),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
VE },
2918 {
"max_slice_bytes",
"Set the maximum number of bytes in an H.264 slice.",
OFFSET(max_slice_bytes),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE },
2931 .class_name =
"h264_videotoolbox",
2938 .p.name =
"h264_videotoolbox",
2952 .p.wrapper_name =
"videotoolbox",
2963 {
"alpha_quality",
"Compression quality for the alpha channel",
OFFSET(alpha_quality),
AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0.0, 1.0,
VE },
2965 {
"constant_bit_rate",
"Require constant bit rate (macOS 13 or newer)",
OFFSET(constant_bit_rate),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
VE },
2972 .class_name =
"hevc_videotoolbox",
2979 .p.name =
"hevc_videotoolbox",
2994 .p.wrapper_name =
"videotoolbox",
3013 .class_name =
"prores_videotoolbox",
3020 .p.name =
"prores_videotoolbox",
3035 .p.wrapper_name =
"videotoolbox",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
const FFCodec ff_h264_videotoolbox_encoder
const FFCodec ff_hevc_videotoolbox_encoder
const FFCodec ff_prores_videotoolbox_encoder
static AVFormatContext * ctx
int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len, void **data, size_t *sei_size)
Check AVFrame for A53 side data and allocate and fill SEI message with A53 info.
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static int FUNC sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
#define CODEC_PIXFMTS_ARRAY(array)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define AV_PROFILE_PRORES_STANDARD
#define AV_PROFILE_PRORES_4444
#define AV_PROFILE_H264_MAIN
#define AV_PROFILE_PRORES_LT
#define AV_PROFILE_H264_EXTENDED
#define AV_PROFILE_UNKNOWN
#define AV_PROFILE_PRORES_PROXY
#define AV_PROFILE_HEVC_REXT
#define AV_PROFILE_HEVC_MAIN
#define AV_PROFILE_HEVC_MAIN_10
#define AV_PROFILE_H264_HIGH
#define AV_PROFILE_H264_CONSTRAINED_BASELINE
#define AV_PROFILE_PRORES_XQ
#define AV_PROFILE_PRORES_HQ
#define AV_PROFILE_H264_BASELINE
float fminf(float, float)
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_FLAG_CLOSED_GOP
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
#define AV_CODEC_FLAG_LOW_DELAY
Force low delay.
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_CODEC_CAP_HYBRID
Codec is potentially backed by a hardware implementation, but not necessarily.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
@ AV_FRAME_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static void av_image_copy2(uint8_t *const dst_data[4], const int dst_linesizes[4], uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Wrapper around av_image_copy() to workaround the limitation that the conversion from uint8_t * const ...
@ AV_PICTURE_TYPE_I
Intra.
#define LIBAVUTIL_VERSION_INT
H.264 common definitions.
#define HW_CONFIG_ENCODER_FRAMES(format, device_type_)
CFStringRef av_map_videotoolbox_color_matrix_from_av(enum AVColorSpace space)
Convert an AVColorSpace to a VideoToolbox/CoreVideo color matrix string.
CFStringRef av_map_videotoolbox_color_primaries_from_av(enum AVColorPrimaries pri)
Convert an AVColorPrimaries to a VideoToolbox/CoreVideo color primaries string.
uint32_t av_map_videotoolbox_format_from_pixfmt2(enum AVPixelFormat pix_fmt, bool full_range)
Same as av_map_videotoolbox_format_from_pixfmt function, but can map and return full range pixel form...
CFStringRef av_map_videotoolbox_color_trc_from_av(enum AVColorTransferCharacteristic trc)
Convert an AVColorTransferCharacteristic to a VideoToolbox/CoreVideo color transfer function string.
An API-specific header for AV_HWDEVICE_TYPE_VIDEOTOOLBOX.
static const AVOption h264_options[]
common internal api header.
static const int factor[16]
Macro definitions for various function/variable attributes.
#define MKBETAG(a, b, c, d)
Memory handling functions.
static av_always_inline int pthread_cond_signal(pthread_cond_t *cond)
static av_always_inline int pthread_mutex_lock(pthread_mutex_t *mutex)
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
#define PTHREAD_ONCE_INIT
static av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
static av_always_inline int pthread_once(pthread_once_t *once_control, void(*init_routine)(void))
static av_always_inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const char * av_color_range_name(enum AVColorRange range)
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
AVColorRange
Visual content value range.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_JPEG
Full range content.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_P010LE
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits,...
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
@ AV_PIX_FMT_NV24
planar YUV 4:4:4, 24bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_NV16
interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_AYUV
packed AYUV 4:4:4:4, 32bpp (1 Cr & Cb sample per 1x1 Y & A samples), AYUVAYUV...
AVColorTransferCharacteristic
Color Transfer Characteristic.
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
#define AV_PIX_FMT_AYUV64
enum AVMediaType codec_type
@ SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
A reference to a data buffer.
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
int global_quality
Global quality for codecs which cannot change it per frame.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
int qmin
minimum quantizer
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
int has_b_frames
Size of the frame reordering buffer in the decoder.
int64_t bit_rate
the average bitrate
enum AVColorSpace colorspace
YUV colorspace type.
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
int64_t rc_max_rate
maximum bitrate
int qmax
maximum quantizer
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int flags
AV_CODEC_FLAG_*.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Structure to hold side data for an AVFrame.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
uint64_t flags
Combination of AV_PIX_FMT_FLAG_... flags.
Rational number (pair of numerator and denominator).
CMSampleBufferRef cm_buffer
pthread_cond_t cv_sample_sent
CFStringRef transfer_function
getParameterSetAtIndex get_param_set_func
CFDictionaryRef supported_props
VTCompressionSessionRef session
CFStringRef color_primaries
static int get_frame(AVFilterContext *ctx, int is_second)
static const uint8_t quality[]