[FFmpeg-devel] [PATCH] avcodec/videotoolbox: add rc_max_bitrate control into videotoolbox
Richard Kern
kernrj at gmail.com
Tue Mar 14 15:37:55 EET 2017
On March 12, 2017 at 11:55:55 PM, Steven Liu (lq at chinaffmpeg.org) wrote:
add kVTCompressionPropertyKey_DataRateLimits support by rc_max_bitrate
Signed-off-by: Steven Liu <lq at chinaffmpeg.org>
---
libavcodec/videotoolboxenc.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 005f5d6..9738152 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -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),
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,
--
2.10.1.382.ga23ca1b.dirty
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel at ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
More information about the ffmpeg-devel
mailing list