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

2017-03-14 Thread Richard Kern
On March 12, 2017 at 11:55:55 PM, Steven Liu (l...@chinaffmpeg.org) wrote:

add kVTCompressionPropertyKey_DataRateLimits support by rc_max_bitrate

Signed-off-by: Steven Liu 
---
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,
+ _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,
+ _second_value);
+ const void* nums[2] = { bytes_per_second, two_second };

Why two seconds?


+ CFArrayRef data_rate_limits = CFArrayCreate(kCFAllocatorDefault,
+ nums,
+ 2,
+ );
+
+ 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@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2017-03-12 Thread Steven Liu
add kVTCompressionPropertyKey_DataRateLimits support by rc_max_bitrate

Signed-off-by: Steven Liu 
---
 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,
+  _per_second_value);
+int64_t two_second_value = 2;
+CFNumberRef two_second = CFNumberCreate(kCFAllocatorDefault,
+kCFNumberSInt64Type,
+_second_value);
+const void* nums[2] = { bytes_per_second, two_second };
+CFArrayRef data_rate_limits = CFArrayCreate(kCFAllocatorDefault,
+nums,
+2,
+);
+
+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



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel