From patchwork Tue Sep 12 06:10:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 43706 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4e27:b0:149:dfde:5c0a with SMTP id gk39csp2583364pzb; Mon, 11 Sep 2023 23:10:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH+ZCCjJAFedEo+DZOX7KSWZcEFFcslyNVCgzkg+bj4ZdO8eVi2PAE5OQjOR0pUuYmt73lK X-Received: by 2002:a05:6512:3082:b0:4ff:83b2:42b7 with SMTP id z2-20020a056512308200b004ff83b242b7mr11149377lfd.42.1694499031958; Mon, 11 Sep 2023 23:10:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694499031; cv=none; d=google.com; s=arc-20160816; b=zECnIDaiGc3O/F9KvMTF+HSTDRO7Pl7oDTITDgwXxHUsWQ5Gt9TSGdQNmedG5IGyww 5bmAuePn3k4R4Rz1mbSF1a1YAscLW087iIAxeEdnMkPBxqoTMK/tu98SMtk2aKz1p4Eb QSzFzCISPS9wtpe8+5fbsLFWCCasavfBN5ALlQzuHcIVjID+vOGQvYWby6KUIaamsy1m d6U+mZolWpuZ0vy3JjZJXWSKYR6G1ej9fuZHRP+eDRv76QfHAGoOJs3L9gWJ4qGGQi3h xs1qq7S8ZlSxXiC0eCFoMDUYePCQQy7E3Wv7STwEhI1XgmXLKJdm0GAzuqxplvOZ2dQq 2RTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:message-id:to:from:date:dkim-signature:delivered-to; bh=wO/lKkaFb+2grICXPEjdduivK5mS6yRA/2uHAo3Aq4A=; fh=Q46kXK7oI5D1Jhi90JBr53c7NIaTxGaU4KPeRZyM/hI=; b=xHxfcLAaZqo8pGOo9UPk4C/a3eviobGT5lKO3MZVyRrrDzfOIjFcNIZMg9EYsBeezq 1ILEG9MddPyyGMRnFcb1Y/znsUidWKvK3LsX3ZGludTEQNBQRNu7M/jlQ4e1kRSsuBCl X36NdIiia68oadlVXgcAamDwkUg6eyjpaZcS5zNk/MtL6kKlOIctGUesn/DSzNTZJwZ+ RmuinQqxZflrVsdFr4Xj7VeVptYRNflMBvC2afGyzk2HB/W1iE/VNl2YIF8vdqxFUQTU wkMflgK3A4G4EaUtMaAT+BINuhD7Dt+WohN11MZe+lQV3oeorG9IPpDVryC5GSo6w8Jh 0slg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=nvd22ojQ; 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=NONE dis=NONE) header.from=lynne.ee Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id pv20-20020a170907209400b0099bd1531117si7902265ejb.33.2023.09.11.23.10.29; Mon, 11 Sep 2023 23:10:31 -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=@lynne.ee header.s=s1 header.b=nvd22ojQ; 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=NONE dis=NONE) header.from=lynne.ee Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3AEEB68C59D; Tue, 12 Sep 2023 09:10:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 91DB468C946 for ; Tue, 12 Sep 2023 09:10:18 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id B311F106030B for ; Tue, 12 Sep 2023 06:10:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1694499017; 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=qsD1V8dl84e1dyqdgF8E5BIIV7s7wgW2dD8+gfMj+9s=; b=nvd22ojQAiozf99iJqRza3hpjiJzktk8VEVdqrbR7e9Efg/gTO/Wg2YIXIASte39 bHsiclqsqJ8ou5iSPpzpOmZ/9BODJSheGlA48u71nAirIE/tXKe14NeDvXf1i5FO07U KJeAXJlB4QkYLNXuqwQ7E3xb+OJfT07rJIPsDBv/BoFb72vWmuD2MWASG2/RP2uhJDb 0KXwFv3mDy79WX739sXTjMxAhRNKsC1yt8KrJiatX5iSLxOPqdcj6eHlDAbQb+pCRjd Uxc86SEQk1V6lFoZwLIpa4C0Ih+r96y8LOoOw3bqAZsV70IOezCj76eylIXtMk5NCk6 ty4GtlTxEg== Date: Tue, 12 Sep 2023 08:10:17 +0200 (CEST) From: Lynne To: Ffmpeg Devel Message-ID: MIME-Version: 1.0 Subject: [FFmpeg-devel] [RFC PATCH 1/3] aacdec: always skip the first 2048 samples if there's no side data 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: 0oT9lom9Y8LT For some reason, this was never set, which meant all **raw** AAC in ADTS streams, except faac, had extra samples at the start. Despite this being a standard MDCT-based codec with a frame size of 1024, hence a delay of 1024 samples at the start, all major encoders, excluding faac and FFmpeg, use 2048 samples of padding. The FFmpeg encoder will be modified to also output 2048 samples of padding at the start, to make it in line with other encoders. Yes, this leaves FATE pretty sad. Will fix it with the real version of the patch. From 079235e1f1a9caeadfd2b8d78b3fe2273d86018a Mon Sep 17 00:00:00 2001 From: Lynne Date: Fri, 11 Aug 2023 17:50:54 +0200 Subject: [PATCH 1/3] aacdec: always skip the first 2048 samples if there's no side data For some reason, this was never set, which meant all **raw** AAC in ADTS streams, except faac, had extra samples at the start. Despite this being a standard MDCT-based codec with a frame size of 1024, hence a delay of 1024 samples at the start, all major encoders, excluding faac and FFmpeg, use 2048 samples of padding. The FFmpeg encoder will be modified to also output 2048 samples of padding at the start, to make it in line with other encoders. --- libavcodec/aacdec_template.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c index f8039e490b..0e4a274fea 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -1273,6 +1273,9 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) if (ret < 0) return ret; + /* Usually overridden by side data */ + avctx->internal->skip_samples = 2048; + return 0; } @@ -2417,14 +2420,16 @@ static int decode_dynamic_range(DynamicRangeControl *che_drc, return n; } -static int decode_fill(AACContext *ac, GetBitContext *gb, int len) { +static int decode_fill(AACContext *ac, GetBitContext *gb, int len) +{ uint8_t buf[256]; - int i, major, minor; + int i, major, minor, micro; if (len < 13+7*8) goto unknown; - get_bits(gb, 13); len -= 13; + get_bits(gb, 13); + len -= 13; for(i=0; i+1=8; i++, len-=8) buf[i] = get_bits(gb, 8); @@ -2434,7 +2439,11 @@ static int decode_fill(AACContext *ac, GetBitContext *gb, int len) { av_log(ac->avctx, AV_LOG_DEBUG, "FILL:%s\n", buf); if (sscanf(buf, "libfaac %d.%d", &major, &minor) == 2){ - ac->avctx->internal->skip_samples = 1024; + ac->avctx->internal->skip_samples -= 1024; + } + + if ((sscanf(buf, "avc %d.%d.%d", &major, &minor, µ) == 3)) { + ac->avctx->internal->skip_samples -= 1024; } unknown: -- 2.40.1 From patchwork Tue Sep 12 06:11:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 43707 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4e27:b0:149:dfde:5c0a with SMTP id gk39csp2583776pzb; Mon, 11 Sep 2023 23:11:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHlCB5f6T/hVLFGjI4UPG63V0Ap4p19/5hRxKDb9ciOvu12hNk/jFX5zd91erFcSwmWDgLZ X-Received: by 2002:aa7:d759:0:b0:52b:d169:b373 with SMTP id a25-20020aa7d759000000b0052bd169b373mr8843557eds.32.1694499096335; Mon, 11 Sep 2023 23:11:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694499096; cv=none; d=google.com; s=arc-20160816; b=Uh+J+1eT6BQu3bUOLnDydBf83hW5r7LiJKGmGEMJzxGaeFWfFxCGAFEQd9Egg1Ow9b MA8xHuDF5LovxZKL7qjcGykDQgeOf0cOZc7q9XIZathhNRdnABGgvlAeWF9EK30Jl09D /ntWb/MMZxlnDOqy1vRbinJDTbjvdAgQ4gT+wrqUUdefYpnBAzB3fWaXIZbkp+OHruuJ aI/SjcbH9wR1tEgFG7c5zuWklzfTy+lL4R9Kyaded3f+/laF1Wu3d2b4FO4Q0pt7YDTf UQcn1OJmWriUcOhFqz+EjoUXJjrwpR8eeIVaF5nJ5i+HnQs9kplyGf8WCXea5u8OQIAV 7HwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:to:from:date :dkim-signature:delivered-to; bh=ojl6KnVcWmxw9qcnBt40YzUhZS3XFE/efbPvcIx0Zyw=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=l30ZBJ12NwMMcioRtQR10+9WyTJGnWWXKDxHbGY2KzxY3iMpDXFm6MaWq7ATZIMvsZ CqwvkJRIQTXoPmgLd6L53YUaqk6lFwirZ6ZhqEw1+p/TOqrCFHTQhFx2xjpl3AZiKLdr dIHhqXUm5pwyhDYTUDr9Ur/4fuvQ3Vlp/JE3sG2cVNv8qFdGXMb3qLY71Ge07g6upMUR GJnZ1ZY9pZ7J/dhsveLXoygUDVkqMqX9p4zd6F/mgejtwL00ZiyngzCm+ZCtkWJ/FeOa 8AdEPr5XMyrLDwwy9bPLHcaPNRCMBOY7ToRsMWt35PIcOAeHlNr9eNbIkR4NhjxjCobP kujg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=FLjecYAL; 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=NONE dis=NONE) header.from=lynne.ee Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i39-20020a0564020f2700b0052f86a13858si2102340eda.140.2023.09.11.23.11.35; Mon, 11 Sep 2023 23:11:36 -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=@lynne.ee header.s=s1 header.b=FLjecYAL; 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=NONE dis=NONE) header.from=lynne.ee Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7FA7668C980; Tue, 12 Sep 2023 09:11:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 805B268C59D for ; Tue, 12 Sep 2023 09:11:27 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id 395E910602D4 for ; Tue, 12 Sep 2023 06:11:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1694499087; 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:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:References:Sender; bh=XhhMMYsrQY7PNKiFrRN5ZDomh58XumoFs+9RGMs13Yk=; b=FLjecYALu1IX43KbwelBx8plhZc+rMQcuomdD3OYJ0ZrYArHrdqHwi29aUKv3wQi tt6mlHj9k39vCR4ocI9Vni+JakK2+pXlwpWgvITNMMABgwFksE8hgWuS9sIfkEQc+kD yH342gWjx82RGsJlr7EIf36jZGPWjdkp3hXdZX5ooQOUi6MsGTBvn/cC9+dAujc4HEK dixJraDyjf8tGxHWA4cEk3AGv/k8E5CspeVCSPx12F/5RxMnrwy4Wgl64ytTTgZHaU2 7vOAFxl0bH+hZ9LTFY5l24yC77GMTlkqtF5Jcxw5T8Z6xuKoz6d1kSadWWALAnJBBl/ BfgSRC4tyg== Date: Tue, 12 Sep 2023 08:11:27 +0200 (CEST) From: Lynne To: FFmpeg development discussions and patches Message-ID: In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [RFC PATCH 2/3] decode: allow decoders to override skip_samples 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: SIzeN8yBonTa Very hacky. There must be a better way of doing this. From 843809ac072bbaf9ae0d3d3946723f1fcfb07923 Mon Sep 17 00:00:00 2001 From: Lynne Date: Tue, 12 Sep 2023 08:00:02 +0200 Subject: [PATCH 2/3] decode: allow decoders to override skip_samples --- libavcodec/decode.c | 5 ++++- libavcodec/internal.h | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 169ee79acd..9e8a4532f2 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -312,7 +312,10 @@ static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *disca side = av_frame_get_side_data(frame, AV_FRAME_DATA_SKIP_SAMPLES); if (side && side->size >= 10) { - avci->skip_samples = AV_RL32(side->data); + if (avci->skip_samples_add) + avci->skip_samples += AV_RL32(side->data); + else + avci->skip_samples = AV_RL32(side->data); avci->skip_samples = FFMAX(0, avci->skip_samples); discard_padding = AV_RL32(side->data + 4); av_log(avctx, AV_LOG_DEBUG, "skip %d / discard %d samples due to side data\n", diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 83e0bc3fb2..8f59a117ba 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -118,6 +118,11 @@ typedef struct AVCodecInternal { */ int skip_samples; + /** + * In case there's side data, add it to skip_samples, instead of overriding it. + */ + int skip_samples_add; + /** * hwaccel-specific private data */ -- 2.40.1 From patchwork Tue Sep 12 06:14:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 43708 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4e27:b0:149:dfde:5c0a with SMTP id gk39csp2584836pzb; Mon, 11 Sep 2023 23:14:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpr85pgP7GSWA8ONtXaCoU7JfK5Nz2ymRTBADfwhGRnJAMUScqz+DKhVZY03rKnw2JUZYo X-Received: by 2002:a05:6402:1482:b0:528:88f5:eafc with SMTP id e2-20020a056402148200b0052888f5eafcmr10122588edv.23.1694499271671; Mon, 11 Sep 2023 23:14:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694499271; cv=none; d=google.com; s=arc-20160816; b=UPGbgn89UgzO0BaQU+DI5LOtw6JwHJIcaWTfx0JdM2+zpMijJ4ccGHNL0N9uNPBXim 7pezIvuBLZyCD+x8CY84HBsduGpYyFPQtyuaplsXIH44u5HaXOtWDWOo5pHpri67R6U1 A4VDHUVIyTAEVqew5ZD0VNh8FC89K/+PmQRSaGKHISr7SVaAsbPanUuk4l9gW40u1Kn1 hYKtZ9QyakkzJr1oeZJyFKkDoxBuSmoJOj3ZLXpga+Va0/iQV839c7IHAWgNoGVlQIgK awualBf3riEEnTil+blyG5jl5T+6sH22eb1tM5ccR7oqzxy2wotpBjTEFp2gDoPMng8E f99A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:to:from:date :dkim-signature:delivered-to; bh=vO24VvYZuSHK4vGjQGtZ7JzBnq1x+zh6a3AO5VJD0JI=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=xzn9OUCVIAwDXZuyRd5F6Clm8bNrXaujBvoqDoYqtWj2BwstQXC+VUb98wcVWZNzCb wEvvI7gncLuVDJGnvFsjVU6yaRrDoVXvExLVjMPPY+tB+OGGberQ1PBzxMM3/K4iLiwB HCiGiLMWkppIDS1vhCHmGFQGCjbUtOZo+Q62UGl+3yBSII4wp54BTPzig5Z6ZHX/dF8+ zFtQ48NseNAIKELcQHwQFe9bOyYPwXeyPOXQ3E/BRhLeSs0bLxuxYdpcsV/wTJV5LCRb qYYp4spRLXRoF3Y17hSityJUlJEXDa3uhf8IAj/7q9ldT0cDhHinxYeF3keNLckHMppi pQJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=kQvpIAV5; 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=NONE dis=NONE) header.from=lynne.ee Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a9-20020aa7d749000000b005256d5bdb32si7883596eds.448.2023.09.11.23.14.31; Mon, 11 Sep 2023 23:14:31 -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=@lynne.ee header.s=s1 header.b=kQvpIAV5; 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=NONE dis=NONE) header.from=lynne.ee Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D757168C990; Tue, 12 Sep 2023 09:14:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2421268C946 for ; Tue, 12 Sep 2023 09:14:22 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id CD6E21060152 for ; Tue, 12 Sep 2023 06:14:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1694499261; 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:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:References:Sender; bh=696GEUQLsgD1y4PRTMqjwKsCvtc5Q6QTweUePr88GqY=; b=kQvpIAV5kWxlBaZsqgT9KpNFfqoYqfgaaxdpAZGUsKw6PzQ41AV6XL4epQ94aZyC XfG7XbcNb40Ct3ixTetTozwW2uiphjh4aIVfVPpltthZa/Q0C0Nz8q6yCucY882OXi3 5uqJiNlMRMKvKllM94stp/4VHPdYXtTJSKmka+7/ruK4sKjqB4j1nHjbJYQEy4XCf+u ftu8vzdhSd8XJVXPJaT5Amu8K2L1CLq0EKD48RSc22wyvTJPIEJmiJifEaYjg9WcZEf YjAKvbByPQkn7YX9/fQXzrsa/crKAHIpBWUd0RAGUw07dBVtAr5NkLMMFp7USdfIqg2 QEFyEtEb7A== Date: Tue, 12 Sep 2023 08:14:21 +0200 (CEST) From: Lynne To: FFmpeg development discussions and patches Message-ID: In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [RFC PATCH 3/3] aacdec: allow to skip sbr start-up delay 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: nZHSShZvoMxW As it happens, there's no standard between startup delay for SBR between decoders either. libfdkaac uses 5056 samples, but Apple's encoder (via afconvert) uses 3136. Currently, this only fixes libfdk-aac. Would like to have more samples from more encoders so I can fix all known cases. From 079235e1f1a9caeadfd2b8d78b3fe2273d86018a Mon Sep 17 00:00:00 2001 From: Lynne Date: Fri, 11 Aug 2023 17:50:54 +0200 Subject: [PATCH 1/3] aacdec: always skip the first 2048 samples if there's no side data For some reason, this was never set, which meant all **raw** AAC in ADTS streams, except faac, had extra samples at the start. Despite this being a standard MDCT-based codec with a frame size of 1024, hence a delay of 1024 samples at the start, all major encoders, excluding faac and FFmpeg, use 2048 samples of padding. The FFmpeg encoder will be modified to also output 2048 samples of padding at the start, to make it in line with other encoders. --- libavcodec/aacdec_template.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c index f8039e490b..0e4a274fea 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -1273,6 +1273,9 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) if (ret < 0) return ret; + /* Usually overridden by side data */ + avctx->internal->skip_samples = 2048; + return 0; } @@ -2417,14 +2420,16 @@ static int decode_dynamic_range(DynamicRangeControl *che_drc, return n; } -static int decode_fill(AACContext *ac, GetBitContext *gb, int len) { +static int decode_fill(AACContext *ac, GetBitContext *gb, int len) +{ uint8_t buf[256]; - int i, major, minor; + int i, major, minor, micro; if (len < 13+7*8) goto unknown; - get_bits(gb, 13); len -= 13; + get_bits(gb, 13); + len -= 13; for(i=0; i+1=8; i++, len-=8) buf[i] = get_bits(gb, 8); @@ -2434,7 +2439,11 @@ static int decode_fill(AACContext *ac, GetBitContext *gb, int len) { av_log(ac->avctx, AV_LOG_DEBUG, "FILL:%s\n", buf); if (sscanf(buf, "libfaac %d.%d", &major, &minor) == 2){ - ac->avctx->internal->skip_samples = 1024; + ac->avctx->internal->skip_samples -= 1024; + } + + if ((sscanf(buf, "avc %d.%d.%d", &major, &minor, µ) == 3)) { + ac->avctx->internal->skip_samples -= 1024; } unknown: -- 2.40.1