[FFmpeg-devel] [PATCH] avcodec/videotoolbox: add rc_max_bitrate control into videotoolbox

Steven Liu lq at chinaffmpeg.org
Mon Mar 13 05:55:04 EET 2017


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;
+    CFNumberRef bytes_per_second = CFNumberCreate(kCFAllocatorDefault,
+                                                  kCFNumberSInt64Type,
+                                                  &bytes_per_second_value);
+    int64_t two_second_value = 2;
+    CFNumberRef two_second = CFNumberCreate(kCFAllocatorDefault,
+                                            kCFNumberSInt64Type,
+                                            &two_second_value);
+    const void* nums[2] = { bytes_per_second, two_second };
+    CFArrayRef data_rate_limits = CFArrayCreate(kCFAllocatorDefault,
+                                                nums,
+                                                2,
+                                                &kCFTypeArrayCallBacks);
+
+    status = VTSessionSetProperty((VTCompressionSessionRef)(vtctx->session),
+                                  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





More information about the ffmpeg-devel mailing list