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 358B745B9A for ; Mon, 24 Apr 2023 12:26:18 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4A9BA68BF7F; Mon, 24 Apr 2023 15:26:15 +0300 (EEST) Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 815BB68BECC for ; Mon, 24 Apr 2023 15:26:09 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id 3578410601A7 for ; Mon, 24 Apr 2023 12:26:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1682339169; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:References:Sender; bh=FqOEVIj+XuOdcyvDP/fn2Ae5+/m0nItKAQ00DI3AP/M=; b=eaHb1jOWd6zjBpQXQtWrH3wJmtrOQRT84XLOdCkaVDu6rRPzIvoi7gbA36dxgBWb Zy6ReezSVSaoyDPNxaR9OD/wzXGVZAkrZMLDjLp/2VNQknSW9Y+1XrU/K8ZazBtz+IF zcBaNptdbo9PUF8RCr3yWT1fYR+ZEVktGUeXooYQZIIm1OekXXjHOGMz5PV7y58hU6l s8pqBnfLQhPdoEe1Bm0efWX3etOyMVHVqCB7tJCoZ89tdiFdxMR9d9hSp7PYHOsq8Nt t8adAGMT259a8+5iODH+6w9jSGGCGGncrUfjc2GWk1EVBLnB5nIP7NBwCB4zQL6Ru0y hzae0HI90A== Date: Mon, 24 Apr 2023 14:26:09 +0200 (CEST) From: Lynne To: FFmpeg development discussions and patches Message-ID: In-Reply-To: <20230424092634.1012785-1-jrwu@chromium.org> References: <20230424092634.1012785-1-jrwu@chromium.org> MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH] avcodec/aacenc: add strict bit rate control mode 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: Apr 24, 2023, 11:27 by jrwu@chromium.org: > From: Jeremy Wu > > In certain use cases, controlling the maximum frame size is critical. An > example is when transmitting AAC packets over Bluetooth A2DP. > > While the spec allows the packets be fragmented (though UNRECOMMENDED), > in practice most headsets do not recognize nor reassemble such packets. > > In this patch, we add a new mode to specify that the configured bit rate > should be followed strictly up to frame level. > > Signed-off-by: Jeremy Wu > --- > doc/APIchanges | 3 +++ > libavcodec/aacenc.c | 11 +++++++++++ > libavcodec/avcodec.h | 4 ++++ > libavcodec/version.h | 2 +- > 4 files changed, 19 insertions(+), 1 deletion(-) > > diff --git a/doc/APIchanges b/doc/APIchanges > index 0b609e3d3b..e730a7e126 100644 > --- a/doc/APIchanges > +++ b/doc/APIchanges > @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09 > > 2023-04-10 - xxxxxxxxxx - lavu 58.6.100 - frame.h > av_frame_get_plane_buffer() now accepts const AVFrame*. > > diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c > index ed036209e9..daf5538056 100644 > --- a/libavcodec/aacenc.c > +++ b/libavcodec/aacenc.c > @@ -1106,6 +1106,17 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, > too_many_bits = FFMIN(too_many_bits, 6144 * s->channels - 3); > too_few_bits = FFMIN(FFMAX(rate_bits - rate_bits/4, target_bits), too_many_bits); > > + if (avctx->flags & AV_CODEC_FLAG_STRICT_BITRATE) { > Use avctx->bit_rate_tolerance instead. By default, it's set to ~400ish kbps. Just detect if it's set to zero to enable this code path. You can set the variable via both the command line and the API. > + if (rate_bits < frame_bits) { > + /* temporarily degrade quality and repeat until frame fits */ > + s->lambda *= 0.75f; > + continue; > + } > + /* reset lambda when solution is found */ > + s->lambda = avctx->global_quality > 0 ? avctx->global_quality : 120; > + break; > + } > That's a heavy handed approach. A better way would be to use the rate_bits/frame_bits, multiply lambda by the ratio, and use that lambda as the starting point. That way, you'd need less reencodes to satisfy the condition. By the way, do you have any specific use for the encoder? I am in the process of rewriting it, and I'd like to know where it's useful, apart from the obvious streaming use-case. _______________________________________________ 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".