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

The AAC rate loop restores the coefficients by using the type of the last 
element for every element so for layouts that do not end in a channel pair 
(4.0, 5.1, 6.1, 7.1) the second channel of each pair is not restored.
This is pretty obviously a copy-paste of some other part of the file, such as 
line 1318 or 1440 where tag is actually set with each loop cycle.

Output is unchanged for nmr and for layouts that end in a channel pair. It 
changes for 4.0, 5.1, 6.1 and 7.1 with twoloop and fast.
There is no discernible quality change.

Noticed during a review sweep of ffmpeg using an LLM.

<!--
If this PR requires new FATE test samples, attach them to the PR and
list their target paths below (relative to the fate-suite root).

Attached filenames must match the sample's filename:

```fate-samples
# e.g. vorbis/new-sample.ogg
```
-->



>From 7ee9f0ac348b592b1c38da7ab4922b51b94ad1fc Mon Sep 17 00:00:00 2001
From: romainhedouin <[email protected]>
Date: Fri, 6 Nov 2026 18:27:13 +0100
Subject: [PATCH] avcodec/aacenc: Use the right element type when restoring
 coefficients

When the rate loop encodes a frame again, it first restores the
coefficients of every element. The number of channels to restore came
from the type of the last element, not from the element being
restored. For layouts that do not end in a channel pair (4.0, 5.1, 6.1,
7.1), the second channel of each pair was not restored.

Noticed during a review sweep of ffmpeg using an LLM.

Signed-off-by: romainhedouin <[email protected]>
---
 libavcodec/aacenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index 5b1e3eff0fb..50a1460e61c 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -1650,7 +1650,7 @@ static int aac_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
                 if (is_mode || ms_mode || tns_mode || pred_mode) {
                     for (i = 0; i < s->chan_map[0]; i++) {
                         // Must restore coeffs
-                        chans = tag == TYPE_CPE ? 2 : 1;
+                        chans = s->chan_map[i + 1] == TYPE_CPE ? 2 : 1;
                         cpe = &s->cpe[i];
                         for (ch = 0; ch < chans; ch++)
                             memcpy(cpe->ch[ch].coeffs, cpe->ch[ch].pcoeffs, 
sizeof(cpe->ch[ch].coeffs));
-- 
2.54.0

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

Reply via email to