From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 7A6F54E451 for ; Fri, 23 Jan 2026 04:01:34 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'FliRzED0meCcjhGxwS6p4fWxdc6j6QzULN0DAbfy3Bw=', expected b'lPwBZ6PUZI5KDJxMLD7ltU5iUx4xxmwzfm4As2+TFnU=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1769140848; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=FliRzED0meCcjhGxwS6p4fWxdc6j6QzULN0DAbfy3Bw=; b=sx+tirY2jwl8bYtmfIjPk8N0C81BvrUSuW8puGZEenVdWcNJuy93yg5O02qnVAUyorZYd sPx6wHJ/K9NJAQ8poWpgz+ppi4WHvZ4ZfshhA7anVBLOT1esXganKq8Xggbl6Z34kXGvZCe ACoZ3XRZPBEEhY6XF7dqStdNsfpwNulw2fJ3uAXHxCY6vvIQ1szKMH/QDVS1WndERFdQGnn ywcO/9TCheTiAiRuBdJDR+vAOqf9FLy5euRJqXgYZjAvVds55B3nvq+ETO9Qm+3BVXtWX8q 3N9duF55RHJn5eeKSxSodtjheZMIvfXwk/A67zDQLW6oPi7EK+qTXoQ2lMaA== Received: from [172.20.0.4] (unknown [172.20.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 56979691261; Fri, 23 Jan 2026 06:00:48 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1769140812; b=gHKts23ds+8DYw5dDgLmdmhOLA/KFSdiravKp0VIgZoDNBv9cjKoKOC9tGtWyAMF6bpOh baChrZX54DLvxWPVVq70rN99/Hsg1CXkKwxlD0z8GMvLkq9x4LK4JdCTfgDc1gEOP7ItuCW iOM9suZndBwq/4/VMzFE7bOWecaMmGsTeMa6RyDPSTGC0fKGHw89JxRVC+T5gXnMcu1Oe/l G84CbM9yrREOz3p7O4EQPcoJ7OUUjQVGPZbmDZWAXS5m3NOLgmuLXpOu+W50COwdvRS+DLI xRFKv3IdAoz2Sld51GxOgvSfSVsqgmgjiE8hAk82bM2Mm48nNHVY5W5o9RKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1769140812; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=B5OD1bUVDIXC0gvuadSsd9uFNsDIUHrxiwHf1GKFCV0=; b=ir4P6O8yYs9bsZ/ioNLAKRfMqMiZixZDZtA7ibN90yaT/bKhFjWACoAm5JzXrXojyrGdi hnwAkMn9Vz/LxLc+n94/7tXTLqA2LFXAq/ApB3IAGXhYOyhoPJN0RcwnLt0x+k8YR9nBzwV qf5s7MQu0rHgoNZh6RGoBVT2chtL5aa4Tr1PwF0QFTaIFj5NeV+W7JWxTbB16SCbnOKAvUx DDfLcXx0F52zZMcdgPUZcexmWrTN0af53HAVcUDOQswzTfDIdeq8r8HSZRRmS/ayOnncNDB xY4GWmP5fUbAbSAMfz8ikYahHrHGEkxt1bvx056L10t2yBW822FikLStDzhw== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1769140801; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=lPwBZ6PUZI5KDJxMLD7ltU5iUx4xxmwzfm4As2+TFnU=; b=SWVbJ428LBYvCU5BjJz9I2flkFvqWXuRaLrW3Lq+nWKYBE3A1pzUqkWR12zSrMrP4SoNm WoH97FPZGNw6qK2uj4ReLEVhvqxIQEOqCjUkv6KOy8XhztpUuCFBGCMUEizPt10A6qQ/ANj S81dD4udWJdvpda7SIouSEjvo5qWCY+XxoAklFIgz8f4AOSWJyi4VitGcBNlfVTYZ/IdlWI nG7Kw+m9He4J7ruiSzIk8N+wE6iZ4HX95sRwFWvyVKJmikpiwtiw4pyMkcpfFcdX7nOQTw4 8rvac2dH2XMwiDghdyRr6iXoCqgvNXy+M7F/VwGPN+IlXG/RFGeWIQaDuHjQ== Received: from 69dab402ede7 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 708486911C9 for ; Fri, 23 Jan 2026 06:00:01 +0200 (EET) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Fri, 23 Jan 2026 04:00:01 -0000 Message-ID: <176914080160.25.6194786246880957852@4457048688e7> Message-ID-Hash: 6MBRD5NGO5S7IHHTOGWSNPYPHQBIVAGT X-Message-ID-Hash: 6MBRD5NGO5S7IHHTOGWSNPYPHQBIVAGT X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PR] lavf/cafenc: fix incorrect duration for Opus in CAF container (PR #21553) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Jun Zhao via ffmpeg-devel Cc: Jun Zhao Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #21553 opened by Jun Zhao (mypopydev) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21553 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21553.patch Reproduce: ffmpeg -f lavfi -i sine=f=440:d=2 -c:a opus -strict -2 out.caf ffprobe out.caf # Shows 00:00:00.25 instead of 00:00:02.00 The native Opus encoder sets frame_size=120 (2.5ms minimum input unit), not the actual packet duration (960 samples). The muxer incorrectly used this value for mFramesPerPacket and mNumberValidFrames calculation. Fix by tracking actual packet durations during muxing and using the accumulated total in the trailer. Signed-off-by: Jun Zhao >>From 599f13a2f5ad134f811149f4e4e09a2cee069bcf Mon Sep 17 00:00:00 2001 From: Jun Zhao Date: Fri, 23 Jan 2026 11:58:16 +0800 Subject: [PATCH] lavf/cafenc: fix incorrect duration for Opus in CAF container Reproduce: ffmpeg -f lavfi -i sine=f=440:d=2 -c:a opus -strict -2 out.caf ffprobe out.caf # Shows 00:00:00.25 instead of 00:00:02.00 The native Opus encoder sets frame_size=120 (2.5ms minimum input unit), not the actual packet duration (960 samples). The muxer incorrectly used this value for mFramesPerPacket and mNumberValidFrames calculation. Fix by tracking actual packet durations during muxing and using the accumulated total in the trailer. Signed-off-by: Jun Zhao --- libavformat/cafenc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libavformat/cafenc.c b/libavformat/cafenc.c index 89ecb51e53..d19e703270 100644 --- a/libavformat/cafenc.c +++ b/libavformat/cafenc.c @@ -32,6 +32,7 @@ typedef struct { int64_t data; + int64_t total_duration; int size_buffer_size; int size_entries_used; int packets; @@ -57,7 +58,6 @@ static uint32_t codec_flags(enum AVCodecID codec_id) { static uint32_t samples_per_packet(const AVCodecParameters *par) { enum AVCodecID codec_id = par->codec_id; int channels = par->ch_layout.nb_channels, block_align = par->block_align; - int frame_size = par->frame_size, sample_rate = par->sample_rate; switch (codec_id) { case AV_CODEC_ID_PCM_S8: @@ -89,7 +89,7 @@ static uint32_t samples_per_packet(const AVCodecParameters *par) { case AV_CODEC_ID_MP1: return 384; case AV_CODEC_ID_OPUS: - return frame_size * 48000 / sample_rate; + return 0; // Variable, will be calculated in trailer from actual packet durations case AV_CODEC_ID_MP2: case AV_CODEC_ID_MP3: return 1152; @@ -235,6 +235,7 @@ static int caf_write_packet(AVFormatContext *s, AVPacket *pkt) } pkt_sizes[caf->size_entries_used++] = pkt->size & 127; caf->packets++; + caf->total_duration += pkt->duration; } avio_write(s->pb, pkt->data, pkt->size); return 0; @@ -255,7 +256,7 @@ static int caf_write_trailer(AVFormatContext *s) if (!par->block_align) { int packet_size = samples_per_packet(par); if (!packet_size) { - packet_size = st->duration / (caf->packets - 1); + packet_size = caf->total_duration / caf->packets; avio_seek(pb, FRAME_SIZE_OFFSET, SEEK_SET); avio_wb32(pb, packet_size); } @@ -263,7 +264,7 @@ static int caf_write_trailer(AVFormatContext *s) ffio_wfourcc(pb, "pakt"); avio_wb64(pb, caf->size_entries_used + 24U); avio_wb64(pb, caf->packets); ///< mNumberPackets - avio_wb64(pb, caf->packets * packet_size); ///< mNumberValidFrames + avio_wb64(pb, caf->total_duration); ///< mNumberValidFrames avio_wb32(pb, 0); ///< mPrimingFrames avio_wb32(pb, 0); ///< mRemainderFrames avio_write(pb, st->priv_data, caf->size_entries_used); -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org