From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 872DF405EB for ; Fri, 26 Aug 2022 11:45:53 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E27DA68B99A; Fri, 26 Aug 2022 14:45:50 +0300 (EEST) Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 54AF768B964 for ; Fri, 26 Aug 2022 14:45:44 +0300 (EEST) Received: by mail-wm1-f44.google.com with SMTP id l33-20020a05600c1d2100b003a645240a95so697869wms.1 for ; Fri, 26 Aug 2022 04:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc; bh=iKHmV7z0fv5Amp13SHnhCXtvI898IXGVYoRmxxC+fkA=; b=ccqK6nXDoHmDogmnxH+5LxBJ28oWsCwBeYebVbd4ePekptbAKPBSLhhIC14cftDVUK VMNgZRnpxGykumOde6UFU/4qx5A3kMy/iIxuaU75w0Hiv9/UkajeyAtNadjEyVuCxRm4 BKJdXqvWh8Kkakd58LbmHilPt2iEV//VbZtPB2EJ4jCaIgSwlyqWA84JsmG87nQvqq4b LrqadNW/cjR5djHUlc0YcMUz9oIEB8Q1P56gsJxhMefKekqq61gGf02pdEShh0dbyY6M Hc73ObaFjO93VYmy4HZM8iZTq4bHWp5Wi/QCKlR1TCXe4CKDM0mxUuzpT7RmhIuS1Sfr ZX4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc; bh=iKHmV7z0fv5Amp13SHnhCXtvI898IXGVYoRmxxC+fkA=; b=cbBay0byQ+tpCnAyvyjuSloufjvFjOc6gkev9LvyMRbtOwUtmZ9tzm3a1kt//8njXc n54Rb7pJSwCLRvlEbQd7zmJ481DULD3Vb+vTTQhxF7wtOQKvy5OkVvMXURdnQmuk9WUD npoqnC/Y6NHuz3cLkVm3F4JmFlt3acXViUNCtm2dXcJkEFGf9f+qTaInLTEgik8uClK0 a/LmMZ9jLma9CbzfGcoR6hXcD331Ub5MAvy5DpbZVHRZ5m7jR1cNMG8Kn+a4+VSw/ynd 7ZepeQ9QTZdcchzbmLH0Jh63D+FipUM4NcW1e1s+ntuijB5ScP5F0MCNzqTG4AsYxl45 Mq2g== X-Gm-Message-State: ACgBeo1uZCeja21GFXP1p2UxrHSRURxTH028fycUIADKOFaM4FXpK3/q zMc9fRxPY16oHPfY5gkzlI6e1Bo+sWQ0jDqhoZ4fNHG0ZDWNyA== X-Google-Smtp-Source: AA6agR7uewlO5RC3qyrfovuBVBrk0fZ1YrD4g7SedEF+qpjMHfY6GS4mqWaKksStuPvsL1ZosHrZ6uoA3GQAQPnWE5g= X-Received: by 2002:a1c:7708:0:b0:3a5:5543:cec4 with SMTP id t8-20020a1c7708000000b003a55543cec4mr11195507wmi.47.1661514343380; Fri, 26 Aug 2022 04:45:43 -0700 (PDT) MIME-Version: 1.0 References: <333BB5A1-3A9E-4DCA-9782-4DA302C124F6@outlook.de> In-Reply-To: <333BB5A1-3A9E-4DCA-9782-4DA302C124F6@outlook.de> From: "Diederick C. Niehorster" Date: Fri, 26 Aug 2022 13:45:27 +0200 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH] avcodec/videotoolboxenc: Add CBR option to H264 and HEVC encoder X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Fri, Aug 26, 2022 at 1:42 PM Sebastian Beckmann wrote: > > Adds an option to use constant bitrate instead of average bitrate to the > videotoolbox encoders. This is enabled via -constant_bit_rate true. > macOS 13 is required for this option to work. > > Signed-off-by: Sebastian Beckmann > --- > libavcodec/videotoolboxenc.c | 37 +++++++++++++++++++++++++++++++++--- > 1 file changed, 34 insertions(+), 3 deletions(-) > > diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c > index 823e5ad94e..9eb6fe09a2 100644 > --- a/libavcodec/videotoolboxenc.c > +++ b/libavcodec/videotoolboxenc.c > @@ -101,6 +101,7 @@ static struct{ > CFStringRef kVTCompressionPropertyKey_RealTime; > CFStringRef kVTCompressionPropertyKey_TargetQualityForAlpha; > CFStringRef kVTCompressionPropertyKey_PrioritizeEncodingSpeedOverQuality; > + CFStringRef kVTCompressionPropertyKey_ConstantBitRate; > > CFStringRef kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder; > CFStringRef kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder; > @@ -164,6 +165,7 @@ static void loadVTEncSymbols(){ > "TargetQualityForAlpha"); > GET_SYM(kVTCompressionPropertyKey_PrioritizeEncodingSpeedOverQuality, > "PrioritizeEncodingSpeedOverQuality"); > + GET_SYM(kVTCompressionPropertyKey_ConstantBitRate, "ConstantBitRate"); > > GET_SYM(kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder, > "EnableHardwareAcceleratedVideoEncoder"); > @@ -236,6 +238,7 @@ typedef struct VTEncContext { > int realtime; > int frames_before; > int frames_after; > + bool constant_bit_rate; > > int allow_sw; > int require_sw; > @@ -1073,12 +1076,22 @@ static bool vtenc_qscale_enabled(void) > return !TARGET_OS_IPHONE && TARGET_CPU_ARM64; > } > > +// constant bit rate only on Macs with Apple Silicon running macOS 13 (Ventura) or newer > +static bool vtenc_constant_bit_rate_enabled(void) > +{ > + if (__builtin_available(macOS 13, *)) > + return !TARGET_OS_IPHONE && TARGET_CPU_ARM64; > + else > + return false; > +} vtenc_constant_bit_rate_available() may be a better name for this function, its the user that enables it through the flag you added > static int vtenc_create_encoder(AVCodecContext *avctx, > CMVideoCodecType codec_type, > CFStringRef profile_level, > CFNumberRef gamma_level, > CFDictionaryRef enc_info, > CFDictionaryRef pixel_buffer_info, > + bool constant_bit_rate, > VTCompressionSessionRef *session) > { > VTEncContext *vtctx = avctx->priv_data; > @@ -1122,6 +1135,11 @@ static int vtenc_create_encoder(AVCodecContext *avctx, > return AVERROR_EXTERNAL; > } > > + if (constant_bit_rate && !vtenc_constant_bit_rate_enabled()) { > + av_log(avctx, AV_LOG_ERROR, "Error: -constant_bit_rate true not available for encoder.\n"); > + return AVERROR_EXTERNAL; > + } > + > if (avctx->flags & AV_CODEC_FLAG_QSCALE) { > quality = quality >= 100 ? 1.0 : quality / 100; > quality_num = CFNumberCreate(kCFAllocatorDefault, > @@ -1139,9 +1157,16 @@ static int vtenc_create_encoder(AVCodecContext *avctx, > &bit_rate); > if (!bit_rate_num) return AVERROR(ENOMEM); > > - status = VTSessionSetProperty(vtctx->session, > - kVTCompressionPropertyKey_AverageBitRate, > - bit_rate_num); > + if (constant_bit_rate) { > + status = VTSessionSetProperty(vtctx->session, > + compat_keys.kVTCompressionPropertyKey_ConstantBitRate, > + bit_rate_num); > + } else { > + status = VTSessionSetProperty(vtctx->session, > + kVTCompressionPropertyKey_AverageBitRate, > + bit_rate_num); > + } > + > CFRelease(bit_rate_num); > } > > @@ -1530,6 +1555,7 @@ static int vtenc_configure_encoder(AVCodecContext *avctx) > gamma_level, > enc_info, > pixel_buffer_info, > + vtctx->constant_bit_rate, > &vtctx->session); > > init_cleanup: > @@ -2532,6 +2558,7 @@ static int vtenc_populate_extradata(AVCodecContext *avctx, > gamma_level, > enc_info, > pixel_buffer_info, > + vtctx->constant_bit_rate, > &vtctx->session); > if (status) > goto pe_cleanup; > @@ -2727,6 +2754,8 @@ static const AVOption h264_options[] = { > > { "a53cc", "Use A53 Closed Captions (if available)", OFFSET(a53_cc), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, VE }, > > + { "constant_bit_rate", "Require constant bit rate (macOS 13 or newer)", OFFSET(constant_bit_rate), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, > + > COMMON_OPTIONS > { NULL }, > }; > @@ -2760,6 +2789,8 @@ static const AVOption hevc_options[] = { > > { "alpha_quality", "Compression quality for the alpha channel", OFFSET(alpha_quality), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0.0, 1.0, VE }, > > + { "constant_bit_rate", "Require constant bit rate (macOS 13 or newer)", OFFSET(constant_bit_rate), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, > + > COMMON_OPTIONS > { NULL }, > }; > -- > 2.37.0 (Apple Git-136) > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".