[FFmpeg-cvslog] avcodec/videotoolboxenc: add rc_max_bitrate control into videotoolbox

Steven Liu git at videolan.org
Wed Mar 15 15:39:04 EET 2017


ffmpeg | branch: master | Steven Liu <lq at chinaffmpeg.org> | Tue Mar 14 22:53:43 2017 +0800| [0052f3f527c4558d32b4f710063acb096493d99c] | committer: Rick Kern

avcodec/videotoolboxenc: add rc_max_bitrate control into videotoolbox

add kVTCompressionPropertyKey_DataRateLimits support by rc_max_bitrate

Reviewed-by: Rick Kern <kernrj at gmail.com>
Signed-off-by: Steven Liu <lq at chinaffmpeg.org>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0052f3f527c4558d32b4f710063acb096493d99c
---

 libavcodec/videotoolboxenc.c | 47 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 005f5d6..4b8718c 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -898,7 +898,14 @@ 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;
+    CFNumberRef  bytes_per_second;
+    CFNumberRef  one_second;
+    CFArrayRef   data_rate_limits;
+    int64_t      bytes_per_second_value = 0;
+    int64_t      one_second_value = 0;
+    void         *nums[2];
 
     int status = VTCompressionSessionCreate(kCFAllocatorDefault,
                                             avctx->width,
@@ -938,6 +945,46 @@ static int vtenc_create_encoder(AVCodecContext   *avctx,
         return AVERROR_EXTERNAL;
     }
 
+    bytes_per_second_value = max_rate >> 3;
+    bytes_per_second = CFNumberCreate(kCFAllocatorDefault,
+                                      kCFNumberSInt64Type,
+                                      &bytes_per_second_value);
+    if (!bytes_per_second) {
+        return AVERROR(ENOMEM);
+    }
+    one_second_value = 1;
+    one_second = CFNumberCreate(kCFAllocatorDefault,
+                                kCFNumberSInt64Type,
+                                &one_second_value);
+    if (!one_second) {
+        CFRelease(bytes_per_second);
+        return AVERROR(ENOMEM);
+    }
+    nums[0] = bytes_per_second;
+    nums[1] = one_second;
+    data_rate_limits = CFArrayCreate(kCFAllocatorDefault,
+                                     nums,
+                                     2,
+                                     &kCFTypeArrayCallBacks);
+
+    if (!data_rate_limits) {
+        CFRelease(bytes_per_second);
+        CFRelease(one_second);
+        return AVERROR(ENOMEM);
+    }
+    status = VTSessionSetProperty(vtctx->session,
+                                  kVTCompressionPropertyKey_DataRateLimits,
+                                  data_rate_limits);
+
+    CFRelease(bytes_per_second);
+    CFRelease(one_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,



More information about the ffmpeg-cvslog mailing list