PR #24662 opened by Hunter Kvalevog (kvog)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24662
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24662.patch

Hi. I doubt anybody has been using `-write_peak only -rf64 always` to begin 
with, as this has been broken since `-write_peak` was added 12 years ago.

`-rf64 auto` is disallowed as well because the WAV to RF64 promotion can 
technically still happen in peak-only mode if a `fact` chunk is written with a 
sample count > UINT32_MAX. I considered adding a 2nd commit to prevent writing 
`fact` in peak-only mode, but it felt out of scope. I would be happy to include 
it if requested.


>From e9eafe05bd103127455ee5ba30af4f2b0054f8bc Mon Sep 17 00:00:00 2001
From: Hunter Kvalevog <[email protected]>
Date: Wed, 23 Sep 2026 19:23:14 -0500
Subject: [PATCH] avformat/wavenc: disallow write_peak=only with RF64

Prior to this commit, the following command would generate an RF64 file
with a broken header:
    $ ffmpeg -i inp.wav -write_peak only -rf64 always out.wav

There is no good reason to allow these options together. RF64 requires
a ds64 chunk, but write_peak=only omits all chunks except for levl.

Since 8eae5de5af, this combination will also write RF64 fmt values over
the peak envelope chunk. Rather than adding yet another check for
PEAK_ONLY, this commit forbids combining these options.

Signed-off-by: Hunter Kvalevog <[email protected]>
---
 libavformat/wavenc.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/libavformat/wavenc.c b/libavformat/wavenc.c
index 58579d2449..462e760711 100644
--- a/libavformat/wavenc.c
+++ b/libavformat/wavenc.c
@@ -145,6 +145,18 @@ static void bwf_write_bext_chunk(AVFormatContext *s)
     ff_end_tag(s->pb, bext);
 }
 
+static av_cold int wav_init(AVFormatContext *s)
+{
+    WAVMuxContext *wav = s->priv_data;
+
+    if (wav->write_peak == PEAK_ONLY && wav->rf64 != RF64_NEVER) {
+        av_log(s, AV_LOG_ERROR, "write_peak=only is not compatible with 
RF64\n");
+        return AVERROR(EINVAL);
+    }
+
+    return 0;
+}
+
 static av_cold void wav_deinit(AVFormatContext *s)
 {
     WAVMuxContext *wav = s->priv_data;
@@ -533,6 +545,7 @@ const FFOutputFormat ff_wav_muxer = {
     .p.audio_codec     = AV_CODEC_ID_PCM_S16LE,
     .p.video_codec     = AV_CODEC_ID_NONE,
     .p.subtitle_codec  = AV_CODEC_ID_NONE,
+    .init              = wav_init,
     .write_header      = wav_write_header,
     .write_packet      = wav_write_packet,
     .write_trailer     = wav_write_trailer,
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to