From patchwork Thu Sep 1 10:22:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyaqiang <1035567130@qq.com> X-Patchwork-Id: 37587 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp187252pzh; Thu, 1 Sep 2022 03:23:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR4HxWfLJWBKIKcBqgVBjgEz5+e85Vtn64DvsNcHL9yAI3Kry1uHEGka1Zeky7mJkrsgKXoM X-Received: by 2002:a05:6402:5292:b0:446:80b0:4a5d with SMTP id en18-20020a056402529200b0044680b04a5dmr28243376edb.285.1662027783851; Thu, 01 Sep 2022 03:23:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662027783; cv=none; d=google.com; s=arc-20160816; b=xg6s/YoFVutB6N71+f8jEkGbfeC0/mC8l8nKy8gwyUH9dLE8PpedcMxeSNBro4Iq/z Odnp27B6HwSjfaB9JlPJkWVns0rE/03HVgrprccODJntXhIPdjw+G+ltWgyvRqR3VyHG L9ovlu+HWLJThIRKVEc3+OT5t1E5hJXrS6wYLFap6OuVpahQxPy90QMo2FdK1YFYNCNs 6KB0nmKElp7zW7nELcXI/6/jWig2eihMccyPWp6cMdS59ewLSVLS84cli6aqDdkCAZpy NfbFFQDkQx9EJ9bqaktfZHO4FZqETifBWcOk6hkLNTNhFGXNP4wLIrJL82DIAFVWDQiQ LT3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:date:to:from:message-id :dkim-signature:delivered-to; bh=AIhx53+fH6BDSMJAQW6EDZ0gXW7AAl5oie2WM/1RsfY=; b=zY3gPlPxO4EvZjaiO58ESY0VpLcz+mA+aG8NKNJVK4CyQmuVXgMR0kbghtzxE35SZD wp2GW/NXvjIhAkpqc5hqeFQ9/vV4KUCLYkV6nXtjks6C6imPCiX69cGXVv6xdvFX2+gt 1oOoaOegSmI4Xm0gySKnY1uzyzkYxP3bZtNdeMjtRfvXKEPe1knuXsvqu4tJGLbw6BZ5 plxjDFGGj+FeR34O5oEAV4I53nsLaT7sT+QPoFnxO8TBJhO6cb2LhJcJ6qt/ck4qQAGx vzT6rtaQKF16NBnwl5L5fsgqCYpIqcXxYO6/OfY8Rph3A3EhPdkyyf9OH5SHbtcczCRQ SiEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@qq.com header.s=s201512 header.b=p+SYpDq+; 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=qq.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w10-20020a05640234ca00b0044699451386si1720420edc.9.2022.09.01.03.23.03; Thu, 01 Sep 2022 03:23:03 -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=@qq.com header.s=s201512 header.b=p+SYpDq+; 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=qq.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 04FA468B9D1; Thu, 1 Sep 2022 13:22:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out162-62-57-210.mail.qq.com (out162-62-57-210.mail.qq.com [162.62.57.210]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A3D8268B9D1 for ; Thu, 1 Sep 2022 13:22:51 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1662027768; bh=nZ9L2XpAFG9r2BNOVP0fkwh8Xb8VKiG/eM8ivA987AI=; h=From:To:Cc:Subject:Date; b=p+SYpDq+FHECHXqJqFTHLGqoOo4nWE3nGG/UNbWCWkfa+2vel9pnLfFPhQ7XmV3oq s8+0uZue216NnDXbM1urZ2DxJM1rxRy85UX8ijqMM6nIxrMJg1xFfXWTMGS/+H0j2G bnNxsga0/3aA4Vm2c6hWLS6ORPGVaLzoMhRlVtUQ= Received: from localhost.localdomain ([103.107.217.225]) by newxmesmtplogicsvrszc8.qq.com (NewEsmtp) with SMTP id 5AE8DAD0; Thu, 01 Sep 2022 18:22:46 +0800 X-QQ-mid: xmsmtpt1662027766ti738o47s Message-ID: X-QQ-XMAILINFO: NkHKfw09D6j8eGx/BIGPqSa4qMmuTs8dJ3qpJjjutXwoeYaZFoyuMw9kwk6qu4 tw+rNh5yqA+uqD6gX4f85dz1CVJ4/TpA7YCVfEGPYnqcrIeRLh0BQD0vwiZYyQLGhnDO84cBFRGB 0pCi0/TSr0aN60TaiKLJgyyVZ/DO8OYtaJzRnvim1ODYglbwqtfig0LOWpdsGcibQpHWPSO+HrvG wZVzFdmqtuSwMW+7MqHzz4WI9EsRf9dtK4cR4WhmIstgN7Lzl4aRwcybvZe3PlreJ69XaSsiNWEA m+Dd58Vh1qlWA+HRJY80RfqGovykRfYAw4khpTa/eLIdYYF87bs70Txuv4aVAIV9cOPus0wD/YcC jXLIgI2biUr13EiYsZyea2q4gdMSmem5uYx+2Q/l+lRLhejz728OiriKvXnGrrgEietdaGdO48Dw zWUsN24g9fFF6/YVNmDrv0HYSvr8Ui5gitn1aZyFEJVVp5V2qw2AzTHCPAR26znMrAbEkJlQ99WY /McEGnfKdgasWeMh3zVAi+yv5S0a2zmrl1DGj2n946FqhcNGaQS5mCFvp1yT6VrWhTpnzYz1TaoC tWPCJ1mtk9CsTAZ8XSBzUjMLMOlChcTvyn35GRoI5V/k7SO1cUiYRYPsKXtH9+oiZ9Gi8mgybMGw pL7u7rT2V/rcK3etero0h3YbXOyHqT6IcPuZlHzMS1eCmyOr591GdIVHzDZM7qb5Yh0NGtpjvnyy xt4LAzdJ/TOl/ryTWwyl3yL74quTirjr6zlMC3+uD7ti8xVHJ3Gt60pOobkBPOFoPPD6+1BinXuM EoPQ+QxdgVuUn7T/zAlEc+rO39z20wHIM9mv45yrYrUTKrfyJeol33olq9fMYdKSo5EHPABRLGwX 5ct/lemwhO9hVmIno63CY2FAOqT+gaINJlgmPLPycUxmT4sgoSp3hH3yEDQHsN1w== From: 1035567130@qq.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Sep 2022 18:22:43 +0800 X-OQ-MSGID: <20220901102243.36838-1-1035567130@qq.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/mov: parse the last moof box when mp4 segment format 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 Cc: Wang Yaqiang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 6n7BGJq6rwEe From: Wang Yaqiang In the format of mp4 segment, the bitrate calculation of stream depends on the sample_size in moof->traf->trun box. In the original logic, when the last sidx box is read, it is not parsed backwards, and the total sample_size calculation is smaller. As a result, the bitrate displayed by ffprobe is also smaller than the actual. Increasing the moof_count variable ensures that the last moof is parsed. Test method: You can use -c copy remux a fmp4 file as mp4 and ffprobe the two files will find that the bitrate is inconsistent Befor patch: Stream #0:1[0x2](und): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 59 kb/s After patch: Stream #0:1[0x2](und): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 96 kb/s (default) Signed-off-by: Wang Yaqiang --- libavformat/isom.h | 1 + libavformat/mov.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index f05c2d9c28..183a3c486b 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -296,6 +296,7 @@ typedef struct MOVContext { int has_looked_for_mfra; int use_tfdt; MOVFragmentIndex frag_index; + int moof_count; //ensure last fragment parse moof box int atom_depth; unsigned int aax_mode; ///< 'aax' file has been detected uint8_t file_key[20]; diff --git a/libavformat/mov.c b/libavformat/mov.c index 14550e6456..396658e342 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7784,12 +7784,15 @@ static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom) int64_t start_pos = avio_tell(pb); int64_t left; int err = parse(c, pb, a); + if (a.type == MKTAG('m','o','o','f')) { + c->moof_count ++; + } if (err < 0) { c->atom_depth --; return err; } if (c->found_moov && c->found_mdat && a.size <= INT64_MAX - start_pos && - ((!(pb->seekable & AVIO_SEEKABLE_NORMAL) || c->fc->flags & AVFMT_FLAG_IGNIDX || c->frag_index.complete) || + ((!(pb->seekable & AVIO_SEEKABLE_NORMAL) || c->fc->flags & AVFMT_FLAG_IGNIDX || (c->frag_index.complete && c->moof_count >= c->frag_index.nb_items)) || start_pos + a.size == avio_size(pb))) { if (!(pb->seekable & AVIO_SEEKABLE_NORMAL) || c->fc->flags & AVFMT_FLAG_IGNIDX || c->frag_index.complete) c->next_root_atom = start_pos + a.size; @@ -8361,6 +8364,9 @@ static int mov_read_header(AVFormatContext *s) av_log(s, AV_LOG_ERROR, "moov atom not found\n"); return AVERROR_INVALIDDATA; } + if (mov->frag_index.nb_items > mov->moof_count) { + av_log(s, AV_LOG_WARNING, "the number of moof is less then fragment count\n"); + } av_log(mov->fc, AV_LOG_TRACE, "on_parse_exit_offset=%"PRId64"\n", avio_tell(pb)); if (pb->seekable & AVIO_SEEKABLE_NORMAL) {