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 EE38447D18 for ; Thu, 19 Oct 2023 02:37:32 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A995D68C94E; Thu, 19 Oct 2023 05:37:29 +0300 (EEST) Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7D2D268C9D4 for ; Thu, 19 Oct 2023 05:37:22 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id DD9761060155 for ; Thu, 19 Oct 2023 02:37:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1697683041; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:Sender; bh=xVkySfsdzsIHmA8uOECVyfJTjwPyYyuLQnb+BupUzwc=; b=Je7gZMN2eo4r1dmDP1IlF7LGS9NPO9h3nrSCSyNMfSVN862GowEvJPYjZWzoUJgC SIwlURpRvlALCGLj8e+WSXCbxwK9OD7EpttZWpwjqwdVx3IO6eeB2zGuxBCjqzoVr4n 6vR6JX9sIim0BlowO/L/8hn0aP3IBFm2a4soJD9YSUMYmTMk1DX31YuVLTvMf6WgMsZ /TEMsVOefKBZelBs7zROwaGJED8SALQyPRVszEJmZTZ6QIIZiHiMfcBaWbGAF4YdNP2 TiKzDsTQGoUuEmDZxQVrXxzaBC/2hz5Q+7iXjK1ryBLirHLjTVIn7rz7bgEdllphTbB bBg1ToegGg== Date: Thu, 19 Oct 2023 04:37:21 +0200 (CEST) From: Lynne To: Ffmpeg Devel Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_345728_1457781073.1697683041549" Subject: [FFmpeg-devel] [PATCH 1/2] lavc/internal: add skip_samples2 field 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" Archived-At: List-Archive: List-Post: ------=_Part_345728_1457781073.1697683041549 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit The issue is that avci->skip_samples will be overridden by any side-data. When operating on raw files (adts, for example), the decoder is free to decide the amount of samples to skip. Usually, this is the algorithmic delay of the decoder. When operating on more complete containers, like ISOBMFF, the amount of samples to be skipped is recorded and signalled by the encoder. However, it turns out many encoders have an arbitrary choice of padding to insert at the start. Normally, they would signal the amount into the container. But with ISOBMFF, there isn't just a single option - the format has been extended multiple times, and has multiple ways to signal padding. In the case of fdkaac-encoded samples, the STTS is used, rather than the CTTS, which ends up with us leaving the padding in. But it's not just containers, as it turns out, most AAC encoders use an arbitrary amount of padding at the start that may, or may not be trimmed (usually, it won't be). Furthermore, AAC has specific amount of algorithmic delay for SBR operation. This delay is not accounter for anywhere. While it's an option to skip the samples in the decoder, doing this in decode.c, along with the rest of the skip adjustments, is a neater way, and can be extended to other codecs. Patch attached. ------=_Part_345728_1457781073.1697683041549 Content-Type: text/x-diff; charset=us-ascii; name=0001-lavc-internal-add-skip_samples2-field.patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0001-lavc-internal-add-skip_samples2-field.patch >From 9986c7f0c71d944101f1c7fe7b1395ee21e34a8e Mon Sep 17 00:00:00 2001 From: Lynne Date: Thu, 19 Oct 2023 04:28:03 +0200 Subject: [PATCH 1/2] lavc/internal: add skip_samples2 field The issue is that avci->skip_samples will be overridden by any side-data. When operating on raw files (adts, for example), the decoder is free to decide the amount of samples to skip. Usually, this is the algorithmic delay of the decoder. When operating on more complete containers, like ISOBMFF, the amount of samples to be skipped is recorded and signalled by the encoder. However, it turns out many encoders have an arbitrary choice of padding to insert at the start. Normally, they would signal the amount into the container. But with ISOBMFF, there isn't just a single option - the format has been extended multiple times, and has multiple ways to signal padding. In the case of fdkaac-encoded samples, the STTS is used, rather than the CTTS, which ends up with us leaving the padding in. But it's not just containers, as it turns out, most AAC encoders use an arbitrary amount of padding at the start that may, or may not be trimmed (usually, it won't be). Furthermore, AAC has specific amount of algorithmic delay for SBR operation. This delay is not accounter for anywhere. While it's an option to skip the samples in the decoder, doing this in decode.c, along with the rest of the skip adjustments, is a neater way, and can be extended to other codecs. --- libavcodec/decode.c | 2 ++ libavcodec/internal.h | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index ad39021354..32944a6b6a 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -338,6 +338,8 @@ static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *disca return AVERROR(EAGAIN); } + avci->skip_samples += avci->skip_samples2; + if (avci->skip_samples > 0) { if (frame->nb_samples <= avci->skip_samples){ *discarded_samples += frame->nb_samples; diff --git a/libavcodec/internal.h b/libavcodec/internal.h index eb9e0d707c..3d8d4d9a4d 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -115,9 +115,18 @@ typedef struct AVCodecInternal { /** * Number of audio samples to skip at the start of the next decoded frame + * + * Note: This will be overridden by any side data. */ int skip_samples; + /** + * Additional samples to skip ad the start of the next decoded frame. + * + * These will be added to any skip amount after taking side data into account. + */ + int skip_samples2; + /** * hwaccel-specific private data */ -- 2.42.0 ------=_Part_345728_1457781073.1697683041549 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". ------=_Part_345728_1457781073.1697683041549--