From patchwork Sun Sep 20 17:06:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 22535 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 0782344B943 for ; Sun, 20 Sep 2020 20:06:42 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DA31768B5C9; Sun, 20 Sep 2020 20:06:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0A68F68B981 for ; Sun, 20 Sep 2020 20:06:33 +0300 (EEST) Received: by mail-lj1-f196.google.com with SMTP id k25so9169716ljk.0 for ; Sun, 20 Sep 2020 10:06:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=bjH593OgIxBCO/9az4CcjlgAUOrlyO0knJ0cdMnNq0o=; b=S/OCHhXrmWBwYdOJ6drXQgDDslPXp+ihoOF6K9a9O44fwjlJvISF98L1zPPQRpDr/d VhPWhnJFv02howK01sPAiAImzoMSwICknaKEN6u7No9VjfX1M52QReEJzebLOX+supCf QJsKp9upqrblpi6z6pXNcbstsfhDDSWXYPyTo05b1Yot8h0nTyrd/3Sdw8LvODeAscrW u5pK/NRwj2MXZPu0n0P6Zmo1ScAy1HZBujpZotbaRy5F9kFXo6FQ9nBmLc+0D3MvKny5 GyHdEsjBeoAEtGRDmijAxJ2POPwTrf3qMK1ZZ5xcusPFYilD43GHI3pMGJXPObMKQ+hA 9z0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bjH593OgIxBCO/9az4CcjlgAUOrlyO0knJ0cdMnNq0o=; b=NKwYE5fLi+46eCvm3Scoe8KWxWfFbxlzPVFX8zyYjwC/CfHjzyLuh2q9ezznzdfGoo GlCPn3t+HTqd6kXHXADRCng1CKiqm+eUvju+VZ19+Bl3JY03LW2RBf8UmwZvsUAwGxTH XtLiL8REgKj1lsTIdTXPYhYgsNhjz6qESzcI5mhDXkhDgzb2FHmSA4MYEnLEmnAlWi9N 4TS6ekA5jhPKnq+40++sisbo+noHwhnG5W6ua4VJ8xelBonEmYzyJEiUodf8bWKMQohc 0rrSyjhp04rTb1TMU4al02RPjT/Q2bVHdlSP00jLT+Tzb22DAHQ5UmTNYsJ9QpyHBS/U TqdQ== X-Gm-Message-State: AOAM531AfotiQZqGkmdp/pwQlzkgC9Wq+dbjViLZMGffTOc0WcGQV3E2 r2WzVUeLheDkRyAHJFAXJiv8/XZBBS0= X-Google-Smtp-Source: ABdhPJwPFLp1KQpaIhHlZ/W0gSeNbzqo7LF/ceEziLycKFPi4ele/2Cfxm+pSLxZytUnJb8gnTashQ== X-Received: by 2002:a05:651c:1253:: with SMTP id h19mr13856627ljh.55.1600621591892; Sun, 20 Sep 2020 10:06:31 -0700 (PDT) Received: from localhost.localdomain (91-159-194-103.elisa-laajakaista.fi. [91.159.194.103]) by smtp.gmail.com with ESMTPSA id x14sm1909108lfc.93.2020.09.20.10.06.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 10:06:31 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Sep 2020 20:06:25 +0300 Message-Id: <20200920170629.26504-2-jeebjp@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200920170629.26504-1-jeebjp@gmail.com> References: <20200920170629.26504-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/5] avformat/movenc: split MPEG-4 bit rate value calculation X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This can now be re-utilized in other places. --- libavformat/movenc.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 12471c7d68..33331962f2 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -633,12 +633,36 @@ static unsigned compute_avg_bitrate(MOVTrack *track) return size * 8 * track->timescale / track->track_duration; } +struct mpeg4_bit_rate_values { + uint32_t buffer_size; ///< Size of the decoding buffer for the elementary stream in bytes. + uint32_t max_bit_rate; ///< Maximum rate in bits/second over any window of one second. + uint32_t avg_bit_rate; ///< Average rate in bits/second over the entire presentation. +}; + +static struct mpeg4_bit_rate_values calculate_mpeg4_bit_rates(MOVTrack *track) +{ + AVCPBProperties *props = \ + (AVCPBProperties*)av_stream_get_side_data(track->st, + AV_PKT_DATA_CPB_PROPERTIES, + NULL); + unsigned avg_bit_rate = compute_avg_bitrate(track); + + + return (struct mpeg4_bit_rate_values){ + .buffer_size = props ? props->buffer_size / 8 : 0, + // (FIXME should be max rate in any 1 sec window) + .max_bit_rate = props ? \ + FFMAX3(props->max_bitrate, props->avg_bitrate, avg_bit_rate) : \ + FFMAX(track->par->bit_rate, avg_bit_rate), + .avg_bit_rate = avg_bit_rate, + }; +} + static int mov_write_esds_tag(AVIOContext *pb, MOVTrack *track) // Basic { - AVCPBProperties *props; + struct mpeg4_bit_rate_values bit_rates = calculate_mpeg4_bit_rates(track); int64_t pos = avio_tell(pb); int decoder_specific_info_len = track->vos_len ? 5 + track->vos_len : 0; - unsigned avg_bitrate; avio_wb32(pb, 0); // size ffio_wfourcc(pb, "esds"); @@ -669,14 +693,9 @@ static int mov_write_esds_tag(AVIOContext *pb, MOVTrack *track) // Basic else avio_w8(pb, 0x11); // flags (= Visualstream) - props = (AVCPBProperties*)av_stream_get_side_data(track->st, AV_PKT_DATA_CPB_PROPERTIES, - NULL); - - avio_wb24(pb, props ? props->buffer_size / 8 : 0); // Buffersize DB - - avg_bitrate = compute_avg_bitrate(track); - avio_wb32(pb, props ? FFMAX3(props->max_bitrate, props->avg_bitrate, avg_bitrate) : FFMAX(track->par->bit_rate, avg_bitrate)); // maxbitrate (FIXME should be max rate in any 1 sec window) - avio_wb32(pb, avg_bitrate); + avio_wb24(pb, bit_rates.buffer_size); // Buffersize DB + avio_wb32(pb, bit_rates.max_bit_rate); // maxbitrate + avio_wb32(pb, bit_rates.avg_bit_rate); if (track->vos_len) { // DecoderSpecific info descriptor