PR #24582 opened by Forgejo_Fairy
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24582
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24582.patch

FFmpeg's libmp3lame wrapper currently ignores strict_std_compliance. With LAME 
3.100, generated 44.1 kHz stereo audio encoded at 320 kb/s reproduces l3dec 
2.72's `ERROR (300c): Granule exceeds maximum dynamic part length`, including 
when `-strict strict` is requested.

Apply the mapping suggested in #23733: call `lame_set_strict_ISO(s->gfp, 1)` 
before `lame_init_params()` when compliance is at least FF_COMPLIANCE_STRICT. 
Document the option. Lower compliance levels retain LAME's defaults. Sample 
rate and bitrate remain as requested; strict mode reduces reservoir use 
according to LAME's own constraints.

Validation:

- The generated CBR reproducer fails in l3dec before the change and reaches EOF 
without decoder errors with patched `-strict strict` and `-strict very`.
- Tested 54 combinations covering all nine supported sample rates, mono/stereo, 
and CBR/ABR/VBR. Default and lower compliance output remain byte-identical to 
baseline; strict and very match, and their outputs decode successfully in 
FFmpeg.
- `fate-mpegaudiodecheader-libmp3lame` passes on AArch64.
- Builds tested on AArch64 and x86-64 with LAME 3.100.

The separate `fairy/issue23733-tooling` branch at b29a0b9c111f preserves the 
generated reproducer, validation scripts, and legacy decoder runtime setup. The 
reported hardware player was not tested, and the tested VBR input decoded 
successfully both before and after the change.


>From b41a8110991da7736464bff25b825b94146d0adc Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <[email protected]>
Date: Sun, 20 Sep 2026 12:25:50 +0000
Subject: [PATCH] avcodec/libmp3lame: honor strict ISO compliance

Enable LAME strict ISO buffer constraints when strict_std_compliance is at 
least FF_COMPLIANCE_STRICT, as suggested in #23733. Preserve the library 
defaults for lower compliance levels.

This lets users opt into the constraints used by lame --strictly-enforce-ISO 
without changing the requested sample rate or bitrate. Document the mapping.

Assisted-by: Fairy
---
 doc/encoders.texi       | 6 ++++++
 libavcodec/libmp3lame.c | 4 ++++
 2 files changed, 10 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index a3ce15fcff..3a07b9d3d7 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -895,6 +895,12 @@ while producing the worst quality.
 Set lowpass cutoff frequency. If unspecified, the encoder dynamically
 adjusts the cutoff.
 
+@item strict (@emph{--strictly-enforce-ISO})
+Enable LAME's strict ISO buffer constraints when set to @samp{strict} or
+@samp{very}. Other values leave LAME's default buffer constraints unchanged.
+This can improve compatibility with some decoders, at the cost of reduced
+bit reservoir usage.
+
 @item reservoir
 Enable use of bit reservoir when set to 1. Default value is 1. LAME
 has this enabled by default, but can be overridden by use
diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
index 88a5ba34a8..b84cfa8b4d 100644
--- a/libavcodec/libmp3lame.c
+++ b/libavcodec/libmp3lame.c
@@ -146,6 +146,10 @@ static av_cold int mp3lame_encode_init(AVCodecContext 
*avctx)
     /* original flag */
     lame_set_original(s->gfp, s->original);
 
+    /* strict ISO compliance */
+    if (avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT)
+        lame_set_strict_ISO(s->gfp, 1);
+
     /* set specified parameters */
     if (lame_init_params(s->gfp) < 0) {
         ret = AVERROR_EXTERNAL;
-- 
2.52.0

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

Reply via email to