@@ -898,6 +898,7 @@ static int vtenc_create_encoder(AVCodecContext *avctx,
{
VTEncContext *vtctx = avctx->priv_data;
SInt32 bit_rate = avctx->bit_rate;
+ SInt32 max_rate = avctx->rc_max_rate;
CFNumberRef bit_rate_num;
int status = VTCompressionSessionCreate(kCFAllocatorDefault,
@@ -938,6 +939,32 @@ static int vtenc_create_encoder(AVCodecContext *avctx,
return AVERROR_EXTERNAL;
}
+ int64_t bytes_per_second_value = max_rate >> 3;
Variables should be declared at the start of the function/scope in C.
+ CFNumberRef bytes_per_second = CFNumberCreate(kCFAllocatorDefault,
+ kCFNumberSInt64Type,
+ &bytes_per_second_value);
The CFNumberCreate() and CFArrayCreate() functions can return NULL when
allocation fails.
+ int64_t two_second_value = 2;
+ CFNumberRef two_second = CFNumberCreate(kCFAllocatorDefault,
+ kCFNumberSInt64Type,
+ &two_second_value);
+ const void* nums[2] = { bytes_per_second, two_second };
Why two seconds?
+ CFArrayRef data_rate_limits = CFArrayCreate(kCFAllocatorDefault,
+ nums,
+ 2,
+ &kCFTypeArrayCallBacks);
+
+ status = VTSessionSetProperty((VTCompressionSessionRef)(vtctx->session),
On March 12, 2017 at 11:55:55 PM, Steven Liu (lq@chinaffmpeg.org) wrote: add kVTCompressionPropertyKey_DataRateLimits support by rc_max_bitrate Signed-off-by: Steven Liu <lq@chinaffmpeg.org> --- libavcodec/videotoolboxenc.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) vtctx->session is already defined as a VTCompressionSessionRef - the cast should be removed for better readability. + kVTCompressionPropertyKey_DataRateLimits, + data_rate_limits); + CFRelease(bytes_per_second); + CFRelease(two_second); + CFRelease(data_rate_limits); + + if (status) { + av_log(avctx, AV_LOG_ERROR, "Error setting max bitrate property: %d\n", status); + return AVERROR_EXTERNAL; + } + if (profile_level) { status = VTSessionSetProperty(vtctx->session, kVTCompressionPropertyKey_ProfileLevel,