From patchwork Fri Mar 8 00:53:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 46880 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c995:b0:1a1:738b:6bc0 with SMTP id gy21csp635221pzb; Thu, 7 Mar 2024 16:54:15 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVhX/1wmGvcpORDRDnDq37WvGshhfyc210BqOg5+vEINK4/M3yodE93hkcmFHzJSRMrSQYOnySvGtwXd74eXR03WrrQ9RAY2AYoQQ== X-Google-Smtp-Source: AGHT+IEkqAE4uE1OX2EN8Lr/7R8EPt8JdomTeKI7R7derO4O/NkgXv/7sRUAkva868+SOjSzciKl X-Received: by 2002:a17:906:2306:b0:a45:b848:62c6 with SMTP id l6-20020a170906230600b00a45b84862c6mr5193917eja.62.1709859254994; Thu, 07 Mar 2024 16:54:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709859254; cv=none; d=google.com; s=arc-20160816; b=D7tzM4aIujg1vBmjcAvu4QS6ndc/sCt9DNMS1ITP1czN5QcSBLZtXg3UqkkxmmJ2vq FP/P4TOwnKpJsjRNH39xlLnveNPHymaYWNFVMW9OHmxXG3XPGwrGQKegzeTeIU2FQZOS PnDkgZ1taqDvd6rW2ZFv8AP2NpA5NsQPHAfFhEnq2lVAG2u2WOuLd7lHUygMWCiruIXz iPOOKtHRQc4B7cJgcYBsbXVtoCPCPKq7LOEweqz74xOrVixCrWU1WVGxH9Zi+sPEk7av haPVVWmjypQHLbDtANJQAabubV+JdMsJ5IpJAcs3p92WjEfGh9EebmoVtDVU83Up/cv6 0s4A== 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:references:in-reply-to :message-id:date:to:from:delivered-to; bh=29TyY6HTZM+RaYgOe0R1fMt0W14tnAxyc/ec/6RBCAA=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=iYK3wrb/BwGvgctT00494DZJ5bXqUYxNZDoeEYu+f/TJnHXru2+7pEahiPpjOo2gp/ uaD8wQNjB42vieKkLRF2o+v+reQsiLPyhKyVF8gFjbr2t4QLwrfEpikiS0jGvlFyrQEk StFgnXYBIGF+vsOoTQjyWIJ1nAx5GVUF4sJvElEfFUMcy37BjzIUWJZzANT8z0GwNRSr l0gmpYopNDQUU7eASXYuKjZ3rnrMk3lpLqNVp47oQXD3j2VwJdDqtmxhTr9i+7ghy60a /VNNC2Yghh+3PCxzQDpRlLdUpjgN9+8ibq7N8nOGvZ04VSHpKWrTJyJVfMYJc/zwqn0n RB1Q==; dara=google.com ARC-Authentication-Results: i=1; mx.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i14-20020a170906264e00b00a43f3f8d3f6si7186408ejc.383.2024.03.07.16.54.14; Thu, 07 Mar 2024 16:54:14 -0800 (PST) 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; 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 27CF168CD06; Fri, 8 Mar 2024 02:54:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 06BF768CCB8 for ; Fri, 8 Mar 2024 02:53:56 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 9DE39E9EDB; Fri, 8 Mar 2024 01:53:55 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XjH5QxmEX4hY; Fri, 8 Mar 2024 01:53:52 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 36B98E9EDC; Fri, 8 Mar 2024 01:53:52 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Mar 2024 01:53:27 +0100 Message-Id: <20240308005333.12416-3-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240308005333.12416-1-cus@passwd.hu> References: <20240308005333.12416-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 3/9] avformat/daudenc: force 2000 sample packet size with a bsf 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: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 8U+ZyakIzVnQ The samples I found all have 2000 sample packets, and by forcing the packet size with a bsf we could automagically make muxing work for packets containing more than 3640 samples. Signed-off-by: Marton Balint --- configure | 1 + doc/muxers.texi | 16 +++++----------- libavformat/daudenc.c | 11 +++++------ tests/ref/fate/dcinema-encode | 31 +++++++++++-------------------- 4 files changed, 22 insertions(+), 37 deletions(-) diff --git a/configure b/configure index 05f8283af9..525902cf10 100755 --- a/configure +++ b/configure @@ -3517,6 +3517,7 @@ caf_demuxer_select="iso_media" caf_muxer_select="iso_media" dash_muxer_select="mp4_muxer" dash_demuxer_deps="libxml2" +daud_muxer_select="pcm_rechunk_bsf" dirac_demuxer_select="dirac_parser" dts_demuxer_select="dca_parser" dtshd_demuxer_select="dca_parser" diff --git a/doc/muxers.texi b/doc/muxers.texi index 2104cc4a95..5b63eec552 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -1387,23 +1387,17 @@ D-Cinema audio muxer. It accepts a single 6-channels audio stream resampled at 96000 Hz encoded with the @samp{pcm_24daud} codec. -In addition, each muxed packet size must not be greater than 65535 bytes. - @subsection Example Use @command{ffmpeg} to mux input audio to a @samp{5.1} channel layout resampled at 96000Hz: @example -ffmpeg -i INPUT -af aresample=96000,pan=5.1,asetnsamples=3640 slow.302 -@end example - -The @samp{asetnsamples} filter is used to reduce the number of samples -of each audio packet, with a size computed according to the formula: -@example -65535 / (@var{channels} * @var{encoded_sample_size}) = 655535 / (6 * 3) = 3640 +ffmpeg -i INPUT -af aresample=96000,pan=5.1 slow.302 @end example -The @var{encoded_sample_size} = 3 factor is due to sample size of the -@samp{pcm_24daud} encoder. +For ffmpeg versions before 7.0 you might have to use the @samp{asetnsamples} +filter to limit the muxed packet size, because this format does not support +muxing packets larger than 65535 bytes (3640 samples). For newer ffmpeg +versions audio is automatically packetized to 36000 byte (2000 sample) packets. @section dv DV (Digital Video) muxer. diff --git a/libavformat/daudenc.c b/libavformat/daudenc.c index 37c20618bd..a995838351 100644 --- a/libavformat/daudenc.c +++ b/libavformat/daudenc.c @@ -25,6 +25,7 @@ static int daud_init(struct AVFormatContext *s) { AVCodecParameters *par = s->streams[0]->codecpar; + int ret; if (par->ch_layout.nb_channels != 6) { av_log(s, AV_LOG_ERROR, @@ -40,17 +41,15 @@ static int daud_init(struct AVFormatContext *s) return AVERROR(EINVAL); } + ret = ff_stream_add_bitstream_filter(s->streams[0], "pcm_rechunk", "n=2000:pad=0"); + if (ret < 0) + return ret; + return 0; } static int daud_write_packet(struct AVFormatContext *s, AVPacket *pkt) { - if (pkt->size > 65535) { - av_log(s, AV_LOG_ERROR, - "Packet size %d too large for s302m, must be <= 65535.\n", - pkt->size); - return AVERROR_INVALIDDATA; - } avio_wb16(s->pb, pkt->size); avio_wb16(s->pb, 0x8010); // unknown avio_write(s->pb, pkt->data, pkt->size); diff --git a/tests/ref/fate/dcinema-encode b/tests/ref/fate/dcinema-encode index 566d8f5091..8eec68901e 100644 --- a/tests/ref/fate/dcinema-encode +++ b/tests/ref/fate/dcinema-encode @@ -7,23 +7,14 @@ #sample_rate 0: 96000 #channel_layout_name 0: 5.1(side) #stream#, dts, pts, duration, size, hash -0, 0, 0, 1024, 12288, 848250bf0a20e324f60151629134ebd5 -0, 1024, 1024, 1024, 12288, cd3c42240d163a7e8835aeda9538f881 -0, 2048, 2048, 1024, 12288, f213a268e7ab62b53a4a4acb9b303dfb -0, 3072, 3072, 1024, 12288, 14d4f3289b057394abc995bfea58912a -0, 4096, 4096, 1024, 12288, a69453c3f0c23abfacb49b15aedc432a -0, 5120, 5120, 1024, 12288, 6578b4a89b1fa4c8897b1376974b685d -0, 6144, 6144, 1024, 12288, 4893b62addf1bea4c03c173f173aa082 -0, 7168, 7168, 1024, 12288, 992b70ea94c339dfda2d3514ac56c4a9 -0, 8192, 8192, 1024, 12288, 543f85139b77d30f8a46fd22d63e3ec7 -0, 9216, 9216, 1024, 12288, f52f825a2fe71f66786d5cd08487e271 -0, 10240, 10240, 1024, 12288, 50ac352cd73a803f52bfd393e610f83b -0, 11264, 11264, 1024, 12288, e9475a9a8794b9b0b912b855bc05001f -0, 12288, 12288, 1024, 12288, bf205474f44a381583b1f077ab8a9d0c -0, 13312, 13312, 1024, 12288, f5655b1da90d808c7e05b4bda02233ca -0, 14336, 14336, 1024, 12288, f8493bb74a270b50706cace85549c317 -0, 15360, 15360, 1024, 12288, c299fbbdcae68c97bca63210f6a1f7da -0, 16384, 16384, 1024, 12288, 2f263932e3d4c419853e3369d70ef8d9 -0, 17408, 17408, 1024, 12288, 09862736b8a1a1ce5c8d23814fb054cd -0, 18432, 18432, 1024, 12288, a99506638c5a3d84d3fa46ee2ba6c5ad -0, 19456, 19456, 1024, 12288, ab6f04f68cfbf2c9a89e9641604b3a50 +0, 0, 0, 2000, 24000, f7b7be0b72225eeaa98ec0b2ea7ad34d +0, 2000, 2000, 2000, 24000, c2d1d19b65f9ec1f7415bce5f2fbac8e +0, 4000, 4000, 2000, 24000, 461979d3566bc69cd4d1911ed1559191 +0, 6000, 6000, 2000, 24000, 8fe028dc7a9e5512b6c24d33cf76c4f6 +0, 8000, 8000, 2000, 24000, 8f7be8b0e562cc56110ee5de6b97bec3 +0, 10000, 10000, 2000, 24000, 53f053a72010471bd1a150af0873ec4a +0, 12000, 12000, 2000, 24000, adcfe7407ec384f65f384cfd85793963 +0, 14000, 14000, 2000, 24000, 4c541973df0e37a77eca16022d4d316c +0, 16000, 16000, 2000, 24000, 362d410570c821384e3ba30a03cdc907 +0, 18000, 18000, 2000, 24000, 00643563149102a4834841217a85d284 +0, 20000, 20000, 480, 5760, 7401d92e7105169bef3deb34e53e9605