From patchwork Wed Jul 7 15:41:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guangyu Sun X-Patchwork-Id: 28854 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5d:965a:0:0:0:0:0 with SMTP id d26csp6203988ios; Wed, 7 Jul 2021 08:49:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWYmVMf+TkA7v19b1ZwRFCGdIUCdxb3l106wtfaQY5Jhme65dZ4D31L7hu9UC3ohXdjl/Z X-Received: by 2002:a05:6402:34d3:: with SMTP id w19mr21197559edc.53.1625672963212; Wed, 07 Jul 2021 08:49:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625672963; cv=none; d=google.com; s=arc-20160816; b=XvJaUi5l6MVwwnxZX3o6vciIqBYlmEPp+1MJfmHc+k+anxJyyvjRFjuPNNBwJKFTST 0eTYaNJIXy4d0s6kHG5+wkO1rKxeEvjVTpAdjaAoTgKJwNijYiAZaUq4yGpStigIUj2p /OZBKTcXuwCcn26sO/yLoQvHbctn3Hcfh+ahyZhfzj+ZVn1Ft8qduwU3HC7v/V7BhVTk qRwoiNSqQsBQ2BDsaKB765w9DMK2KvpkNAbf1OvhcbUFpNTZhQ2naSvNQxmBUOSxxMZl a7Zb5S1iXYf/8z3aLtLJPsXcMi1LFgjiZUHWPC7wzmyjCXZRrpBKvxj34IR/EDUQldTJ dSNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=zg0FJmq32rv+zXTXI23oBTZuGMbJef0ppMIleTVl4OM=; b=tojU31iWxd6yW5e/dQO4evwX7SlKPeh6IqTHDqC81DiD5Cpa3Rgp5tgLHTjfCvvdvZ 4F6gtmi3l1PuLgE7oBltHMC6Ju9dxl5lIs4OnVduKEVLJK+cxYtk+mnEmPsJs8cffN1E rt8x1YcUJhtre0gd3SLcPeNp0T7mEq0lkjtIaBuNoPoQBtztwjpbjMFwNYatIF5PCgWK nrV4XDs2XCTMqGfVgvyJ7D+QAaDZXpyQCZZidhQRHqJfGH/GPRAzREAjdZfa8EVtVR7c AKCnHCc4KLlXKGRvPgcWGXNVwpvrnNvXJfeG6QXw4emZmSeXsTyoO3qMKGcyPCzTwBn5 hXSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b="YCY/Hxep"; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a4si19887582edj.511.2021.07.07.08.49.18; Wed, 07 Jul 2021 08:49:23 -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=@gmail.com header.s=20161025 header.b="YCY/Hxep"; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9AF4468A758; Wed, 7 Jul 2021 18:49:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0FC2768A704 for ; Wed, 7 Jul 2021 18:48:59 +0300 (EEST) Received: by mail-qv1-f46.google.com with SMTP id i4so768611qvq.10 for ; Wed, 07 Jul 2021 08:48:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=vA2DaF4Ha0PX3+0h0zB9XgVetAMBIpapNAMbYsjgpEQ=; b=YCY/Hxepb+skGscOQmTRN9AoVkOzCAy6IZJeTFO4bxTDBQrxGAHN2+N8j+bftu4u/g FbvcW4FCeIMcMoFhAJv7VFsZ0lGe7DlH3GTQnK734GlvvqCsxQwRSBAnVdJDcVxWZ511 IWGHkbb627T1ARZCRb/ac5CjAjZ7DeaGkGycIgygXX12FVotMRUQVTbdUvSS6EacxghL IJ6Hi1oWauHC9UlKLekQuJYNcY0cHDranJz09gTxNEv0i3xJ7k85X1z5hRGmyTtuYjPC w3/Du5L9xExGcSFmzpz8zCvKSRDdY/TfUqsNNahSShkJPuwzOxU2W1SFTdQfriImD/uq rv1g== 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:mime-version :content-transfer-encoding; bh=vA2DaF4Ha0PX3+0h0zB9XgVetAMBIpapNAMbYsjgpEQ=; b=eUUmc2zvbMXG11Rj/4Bl6RMNlZi+pk/7mgfSQWkI1AxpTrZsJ7PCDTFEVqTx2/mkng MnpWX9jm8oIo2sFY3w0xWkPepSie4n45BWW5WYmYFPvQEGboqBnbBZmipiLY6EbcuwiU YV/ByOpSr/V9pWzD6baAEz8Z1rVfP3ynHIzzlFGEuKBqu8dhWGazxVaxPf5Zg8LrbKSd 1Fucs+bpuzFqbz6aWC/Q7M6eftCvFzIC0e8SZ01436fGMchyqi3nyEcdi++xPGFcc/Xz RYjsnIhBS5xKOwDzt/qMDpdN55cS3qr4R0J8LlDvcPdPJrUwL5aXx7zCxkFvTsjzjfvk WGLw== X-Gm-Message-State: AOAM532jMl3fOA0ipmKyO1rMm/y+JmbSZZQtjdx3sPx1QqPSdqaOF6/M /mJZSGT+JpHnAASVETZPOaDuDDc9QFIe5A== X-Received: by 2002:a17:902:aa0b:b029:128:eb4c:15e5 with SMTP id be11-20020a170902aa0bb0290128eb4c15e5mr21297412plb.45.1625672496626; Wed, 07 Jul 2021 08:41:36 -0700 (PDT) Received: from localhost.localdomain ([98.42.211.210]) by smtp.gmail.com with ESMTPSA id co12sm6750829pjb.33.2021.07.07.08.41.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Jul 2021 08:41:36 -0700 (PDT) From: Guangyu Sun X-Google-Original-From: Guangyu Sun To: ffmpeg-devel@ffmpeg.org Date: Wed, 7 Jul 2021 08:41:32 -0700 Message-Id: <20210707154134.59769-1-gsun@roblox.com> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avformat/oggparsevorbis: Update end_trimming for the last packet 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: WyjijsRhCnwk Without end_trimming, the last packet will contain unexpected samples used for padding. This commit partially fixes #6367 when the audio length is long enough. dd if=/dev/zero of=./silence.raw count=20 bs=500 oggenc --raw silence.raw --output=silence.ogg oggdec --raw --output silence.oggdec.raw silence.ogg ffmpeg -codec:a libvorbis -i silence.ogg -f s16le -codec:a pcm_s16le silence.libvorbis.ffmpeg.raw ffmpeg -i silence.ogg -f s16le -codec:a pcm_s16le silence.native.ffmpeg.raw ls -l *.raw The original test case in #6367 is still not fixed due to a remaining issue. The remaining issue is that ogg_stream->private is not kept during ogg_save()/ogg_restore(). Field final_duration in the private data is important to calculate end_trimming. Some common operations such as avformat_open_input() and avformat_find_stream_info() before reading packet will trigger ogg_save() and ogg_restore(). Luckily, final_duration will not get updated until the last ogg page. The save/restore mentioned above will not change final_duration most of the time. But if the audio length is short, those reads may be performed on the last ogg page, causing trouble keeping the correct value of final_duration. We probably need a more complicated patch to address this issue. Signed-off-by: Guangyu Sun --- libavformat/oggparsevorbis.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c index 0e8c25c030..c48658ceda 100644 --- a/libavformat/oggparsevorbis.c +++ b/libavformat/oggparsevorbis.c @@ -492,8 +492,12 @@ static int vorbis_packet(AVFormatContext *s, int idx) priv->final_pts = os->lastpts; priv->final_duration = 0; } - if (os->segp == os->nsegs) + if (os->segp == os->nsegs) { + int64_t skip = priv->final_pts + priv->final_duration + os->pduration - os->granule; + if (skip > 0) + os->end_trimming = skip; os->pduration = os->granule - priv->final_pts - priv->final_duration; + } priv->final_duration += os->pduration; }