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 EC58C4E49E for ; Fri, 23 Jan 2026 09:43:26 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'6OcPIYFd7nLe1jqasW938exXydzSAuo1D8VirEQGYSc=', expected b'rCcoNkiYp7TXxILxma5cWy9Z8M4F56bytjToQgL7DR0=')) 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=1769161389; 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=6OcPIYFd7nLe1jqasW938exXydzSAuo1D8VirEQGYSc=; b=xcmxIVIynK3lTbdUR5pe8ndxFEqbv06oh5EtnLN1hLut1UwDiC1VlepgckowV82ZrZSA1 s6/BRPhz3ylF4Zqm0hIo5aJPk0yt6XFAMEYg8RXLWxqWZ3IfWkcZHgrOTWmyXpfBxBa9KZk D/fuVld+NELPu78U3tQCEuQ97QROUbFeMx60rX8ZHRfkJV2OzL39EYCWY5AjEy2Qc7uNmiD llRmE3O8cCWhdm/bVphA15B7Gkb7TMJG0wLSPbyNo1IJJtoi15Ndz+2XCvgrwGWSsGQ2eM3 hPW6/E9tNi0Usr8+DzKONSdoV3Rs1KuCpbsHU97RHm8bePk0tKvlAo9LOaJw== Received: from [172.20.0.4] (unknown [172.20.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 5B6F569142C; Fri, 23 Jan 2026 11:43:09 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1769161375; b=OcJCzbi26UTqMqeLizmWs0ENw7v+uaBYae2VVsyWzyxrd+ixdlCQWhStvL75qrXbD+RhE GbXuWCFpHjgZMiiP2Z1z2M8Cr0np+74PLYPent4O/sFyOPWbow4Nt3s7EjL8suMSZ1U2E5z F3AazJ8wndJ5IHuMJoE5Rv5hE6Tb2dRHi1IrcNRxspQTPpH7RRBsUH7IbNpYddGQoRBiLF3 KPnvVU/oKVA5Xa6otyWxs/PY4KMKEvqGtyIh8lR68f3aPne4bT52CUOdWNuf1WwOJVB07Ch Oz+yLSr0b/972nqeiGGqAjohc0FrDSepH+54mlycKkDcqnFOv+HheSoVSa+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1769161375; 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=MxLgaSha1Mb2sEXD4wgr2LFdnGOc5Ggwa2IdX4bEWXQ=; b=D/h8SWbsObVGwn6cfzYluvSBZ5BuQNJWR50HNFfBx3VH0IV4RVdiG3ywdV4UEO8thy7NW t3KyejqDGf0ssHVZMRWnGHzw7nJnQhPhW7H2iUzcA0LIqTwoTeNmnPQgCBOqL4mlM6X6We2 /bCt9NkYJ/luMNt69zxpopZUga1KfMb4K1EX8aSaZD15rl0jFQrX3b8bKeWDSNCESw1LkAs M/G5vrzywjNvdLks48VbHsTnaEsU4MAbrEWpEVhR4kRM4+OGgDzVdiS357rAEZZfVtAU8Ks RiZW0H4AzGO4hdf6U1xdyN3Y9N5cHfPDTY9e3nC8N1Fj0VhfYz7F0W56LW3Q== 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=1769161366; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=rCcoNkiYp7TXxILxma5cWy9Z8M4F56bytjToQgL7DR0=; b=N6ZieVscJkfZVnPRkJ6Wly4hnYya0uNPHyZJCBSQ8CxkY7BE2ufsIGTph1QyqWsLL18ba zAHqw9UFfxaF80sr4+cB+up14sMrCwGvcjcqfZdc3car76jBrZUdkxgwPsopd8AcsMJNUv+ FxSSvrrT7lMSss1nNIxMPSnmb+Zc9fmFXBW7BzBtvaygaSabOAiPKHXyCEvEtwFuhniWj5m jmqFT7zUCLrgbW8HFyIP0QTGTjATu2sqWAsHfWnzJl6+HNx+v8AIdFO4elr+tfp6tg5AUM3 9k5KONuw5jJNVy7cSRV4PoMGSIKtLZd5xgheFanv5tbg3WEFZPZdtb75ciAg== Received: from 69dab402ede7 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 4EE326913A3 for ; Fri, 23 Jan 2026 11:42:46 +0200 (EET) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Fri, 23 Jan 2026 09:42:45 -0000 Message-ID: <176916136646.25.701545660977719295@4457048688e7> Message-ID-Hash: D2EJMYDP5H7KMUAMYNX52AJIGY7CFGZE X-Message-ID-Hash: D2EJMYDP5H7KMUAMYNX52AJIGY7CFGZE 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] avformat/wavenc: Keep fmt chunk first for -rf64 auto (PR #21556) 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: Daniel Verkamp via ffmpeg-devel Cc: Daniel Verkamp Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #21556 opened by Daniel Verkamp (drv) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21556 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21556.patch When the WAV muxer's `-rf64 auto` option is used, the output is intended to be a normal WAV file if possible, only extended to RF64 format when the file size grows too large. This was accomplished by reserving space for the extra RF64-specific data using a standard JUNK chunk (ignored by readers), then overwriting the reserved space later with a ds64 chunk if needed. In the original rf64 auto implementation, the JUNK chunk was placed right after the RIFF/WAVE file header, before the fmt chunk; this is the design suggested by the "Achieving compatibility between BWF and RF64" section of the RF64 spec: RIFF 'WAVE' ... However, this approach means that the fmt chunk is no longer in its conventional location at the beginning of the file, and some WAV-reading tools are confused by this layout. For example, the `file` tool is not able to show the format information for a file with the extra JUNK chunk before fmt. This change shuffles the order of the chunks for `-rf64 auto` mode so that the reserved space follows fmt instead of preceding it: RIFF 'WAVE' ... With this small modification, tools expecting the fmt chunk to be the first chunk in the file work with files produced by `-rf64 auto`. This means the fmt chunk won't be in the location required by RF64, so if the automatic RF64 conversion is triggered, the fmt chunk needs to be relocated by rewriting it following the ds64 chunk during the conversion: RF64 'WAVE' ... >>From 18ab86bee591be78f5e1a9771bb770e59c8efafc Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Fri, 23 Jan 2026 00:53:09 -0800 Subject: [PATCH] avformat/wavenc: Keep fmt chunk first for -rf64 auto When the WAV muxer's `-rf64 auto` option is used, the output is intended to be a normal WAV file if possible, only extended to RF64 format when the file size grows too large. This was accomplished by reserving space for the extra RF64-specific data using a standard JUNK chunk (ignored by readers), then overwriting the reserved space later with a ds64 chunk if needed. In the original rf64 auto implementation, the JUNK chunk was placed right after the RIFF/WAVE file header, before the fmt chunk; this is the design suggested by the "Achieving compatibility between BWF and RF64" section of the RF64 spec: RIFF 'WAVE' ... However, this approach means that the fmt chunk is no longer in its conventional location at the beginning of the file, and some WAV-reading tools are confused by this layout. For example, the `file` tool is not able to show the format information for a file with the extra JUNK chunk before fmt. This change shuffles the order of the chunks for `-rf64 auto` mode so that the reserved space follows fmt instead of preceding it: RIFF 'WAVE' ... With this small modification, tools expecting the fmt chunk to be the first chunk in the file work with files produced by `-rf64 auto`. This means the fmt chunk won't be in the location required by RF64, so if the automatic RF64 conversion is triggered, the fmt chunk needs to be relocated by rewriting it following the ds64 chunk during the conversion: RF64 'WAVE' ... --- libavformat/wavenc.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/libavformat/wavenc.c b/libavformat/wavenc.c index a515f4e2a2..01fffaafe5 100644 --- a/libavformat/wavenc.c +++ b/libavformat/wavenc.c @@ -315,9 +315,9 @@ static int wav_write_header(AVFormatContext *s) ffio_wfourcc(pb, "WAVE"); - if (wav->rf64 != RF64_NEVER) { - /* write empty ds64 chunk or JUNK chunk to reserve space for ds64 */ - ffio_wfourcc(pb, wav->rf64 == RF64_ALWAYS ? "ds64" : "JUNK"); + if (wav->rf64 == RF64_ALWAYS) { + /* write empty ds64 chunk */ + ffio_wfourcc(pb, "ds64"); avio_wl32(pb, 28); /* chunk size */ wav->ds64 = avio_tell(pb); ffio_fill(pb, 0, 28); @@ -332,6 +332,16 @@ static int wav_write_header(AVFormatContext *s) return AVERROR(ENOSYS); } ff_end_tag(pb, fmt); + + if (wav->rf64 == RF64_AUTO) { + /* reserve space for ds64 */ + ffio_wfourcc(pb, "JUNK"); + avio_wl32(pb, 28); /* chunk size */ + ffio_fill(pb, 0, 28); + + /* in RF64_AUTO mode, fmt + JUNK will be overwritten by ds64 + fmt */ + wav->ds64 = fmt; + } } if (s->streams[0]->codecpar->codec_tag != 0x01 /* hence for all other than PCM */ @@ -411,6 +421,7 @@ static int wav_write_trailer(AVFormatContext *s) WAVMuxContext *wav = s->priv_data; int64_t file_size, data_size; int64_t number_of_samples = 0; + int64_t pos; int rf64 = 0; int ret = 0; @@ -459,7 +470,7 @@ static int wav_write_trailer(AVFormatContext *s) ffio_wfourcc(pb, "RF64"); avio_wl32(pb, -1); - /* write ds64 chunk (overwrite JUNK if rf64 == RF64_AUTO) */ + /* write ds64 chunk (overwrite fmt + JUNK if rf64 == RF64_AUTO) */ avio_seek(pb, wav->ds64 - 8, SEEK_SET); ffio_wfourcc(pb, "ds64"); avio_wl32(pb, 28); /* ds64 chunk size */ @@ -468,6 +479,11 @@ static int wav_write_trailer(AVFormatContext *s) avio_wl64(pb, number_of_samples); /* fact chunk number of samples */ avio_wl32(pb, 0); /* number of table entries for non-'data' chunks */ + /* rewrite fmt in its RF64 position after ds64 */ + pos = ff_start_tag(pb, "fmt "); + ret = ff_put_wav_header(s, pb, s->streams[0]->codecpar, 0); + ff_end_tag(pb, pos); + /* write -1 in data chunk size */ avio_seek(pb, wav->data - 4, SEEK_SET); avio_wl32(pb, -1); -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org