From patchwork Wed Sep 28 18:29:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Toohill X-Patchwork-Id: 769 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.66 with SMTP id o63csp566018vsd; Wed, 28 Sep 2016 11:36:29 -0700 (PDT) X-Received: by 10.194.162.162 with SMTP id yb2mr28175944wjb.38.1475087789168; Wed, 28 Sep 2016 11:36:29 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y3si9969221wje.211.2016.09.28.11.36.26; Wed, 28 Sep 2016 11:36:29 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A114D689C95; Wed, 28 Sep 2016 21:36:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f181.google.com (mail-pf0-f181.google.com [209.85.192.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5F1CF689C5B for ; Wed, 28 Sep 2016 21:36:06 +0300 (EEST) Received: by mail-pf0-f181.google.com with SMTP id l25so20011525pfb.1 for ; Wed, 28 Sep 2016 11:36:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yLpGngUZscxXaZIkaglurRUaro9o44nZNT1jyRKGaRk=; b=LzcFHLDa9cCo8Kz6ZoTZE+9BSasCsRBbOVcVRZo0jnsXkfWJx0dF3aXQTq54bXesMm p2BIX3gIgN00Lkzc5UDmRAB++w4YuXtf+nC4CegBtOwwcZXV2uS+7iWUt1zOEmSI4P+N 1LkOMqSjATJkfMkLc7/eSQBjU40XtF7nPxpEAb27lga4JqQP3lC3MhDkTAqhcZiRkwc1 PC2eIIJl0XS2cozZlFQvjNuEhH9oKlGK2+KarWWo0roPZyVmeuslZ4sOaLRt1exBz081 +TyOEcrHkmjuw1mnjuwwO6e4nZfoyKdaJ43qGttlo9cG1Ps/bmB4/vwfK1T7ILZpRW4N lRzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yLpGngUZscxXaZIkaglurRUaro9o44nZNT1jyRKGaRk=; b=h5WJFj6VZZV+agljR+MywYQpROU4w3pgRuMTbqBQLlvRzHPYZKPqn2I/F1dAlIumcm 2I2v92CM2LpTXhpOWFleRMV5z12x4ARq97faTueDdNXLacVfxknJsGeeOZDInK9DjEq1 XvBeF/HDoeLLnu7Tx0vvudfRQanzI5eAWkebf7Rx+FbsQxRD9vtfpWhxWbDdWiA2uPVd nLxmwmqlE14LFs2DqH1fgTdi4rnaV9yXnAUN30IW8lZYpZH3sSF4nxNxWbz0dTL5QJAS qi5QuAJk2M7vLJ8spJTy9E3OLMKVeyKh2jClMzCMKm4/o/tAgm8CdeZgiEAZAvMNUeAm 9Jvw== X-Gm-Message-State: AE9vXwNobfby4v9h1dwbFPoOb3/GX94F2PithtRCPGhPM3HZKNhLhX0bVet3Z+EuHZAvE72X X-Received: by 10.98.198.70 with SMTP id m67mr59439543pfg.34.1475087364834; Wed, 28 Sep 2016 11:29:24 -0700 (PDT) Received: from mungolini.mtv.corp.google.com ([100.96.2.73]) by smtp.gmail.com with ESMTPSA id wa9sm14248493pac.35.2016.09.28.11.29.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Sep 2016 11:29:23 -0700 (PDT) From: Jon Toohill To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Sep 2016 11:29:02 -0700 Message-Id: <1475087343-29745-5-git-send-email-jtoohill@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1475087343-29745-1-git-send-email-jtoohill@google.com> References: <1475087343-29745-1-git-send-email-jtoohill@google.com> Subject: [FFmpeg-devel] [PATCH 3/4] lavf/mp3enc: write encoder delay/padding upon closing 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 Cc: Jon Toohill MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" trailing_padding is not known before encoding. --- libavformat/mp3enc.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index de63401..37608f1 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -247,12 +247,7 @@ static int mp3_write_xing(AVFormatContext *s) ffio_fill(dyn_ctx, 0, 8); // empty replaygain fields avio_w8(dyn_ctx, 0); // unknown encoding flags avio_w8(dyn_ctx, 0); // unknown abr/minimal bitrate - - // encoder delay - if (par->initial_padding - 528 - 1 >= 1 << 12) { - av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n"); - } - avio_wb24(dyn_ctx, FFMAX(par->initial_padding - 528 - 1, 0)<<12); + avio_wb24(dyn_ctx, 0); // empty encoder delay/padding avio_w8(dyn_ctx, 0); // misc avio_w8(dyn_ctx, 0); // mp3gain @@ -381,7 +376,7 @@ static void mp3_update_xing(AVFormatContext *s) AVReplayGain *rg; uint16_t tag_crc; uint8_t *toc; - int i, rg_size; + int i, rg_size, delay, padding; /* replace "Xing" identification string with "Info" for CBR files. */ if (!mp3->has_variable_bitrate) @@ -422,6 +417,17 @@ static void mp3_update_xing(AVFormatContext *s) } } + /* write encoder delay/padding */ + delay = FFMAX(s->streams[0]->codecpar->initial_padding - 528 - 1, 0); + padding = s->streams[0]->codecpar->trailing_padding; + if (delay >= 1 << 12) { + av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n"); + } + if (padding >= 1 << 12) { + av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n"); + } + AV_WB24(mp3->xing_frame + mp3->xing_offset + 141, (delay << 12) + padding); + AV_WB32(mp3->xing_frame + mp3->xing_offset + XING_SIZE - 8, mp3->audio_size); AV_WB16(mp3->xing_frame + mp3->xing_offset + XING_SIZE - 4, mp3->audio_crc);