hello, I came across this bug that causes audio artifact when seeking AAC HE file, its reproducible on newest ffmpeg which I compiled today from git, tested with ffplay, and it seems to be fixed with attached patch. However I am not well versed with ffmpeg aac codec architecture so please advice if the approach even makes sense. thanks, Nayana
From c8be7b3a7eeb32365bb704cedfc53b680b7ba97b Mon Sep 17 00:00:00 2001 From: Nayana Topolsky <[email protected]> Date: Fri, 25 Sep 2026 18:04:08 +0200 Subject: [PATCH] avcodec/aac: zero the SBR data upon flush
When doing flush as e.g. part of seek operation the SBR data are still populated by previous audio data and after the seek it would make a nasty screech sound (high frequency static noise). SBR data needs to be cleared when flushing. Signed-off-by: Nayana Topolsky <[email protected]> --- libavcodec/aac/aacdec.c | 2 ++ libavcodec/aacsbr.h | 4 ++++ libavcodec/aacsbr_template.c | 9 +++++++++ 3 files changed, 15 insertions(+) diff --git a/libavcodec/aac/aacdec.c b/libavcodec/aac/aacdec.c index fdebe139c3..2adfe01a2d 100644 --- a/libavcodec/aac/aacdec.c +++ b/libavcodec/aac/aacdec.c @@ -565,6 +565,8 @@ static av_cold void flush(AVCodecContext *avctx) for (j = 0; j <= 1; j++) { memset(che->ch[j].saved, 0, sizeof(che->ch[j].saved)); } + /* Clear SBR history buffers on seek flush */ + ff_aac_sbr_flush(che); } } } diff --git a/libavcodec/aacsbr.h b/libavcodec/aacsbr.h index afc8ad188a..2ec8f7698b 100644 --- a/libavcodec/aacsbr.h +++ b/libavcodec/aacsbr.h @@ -82,6 +82,10 @@ int ff_aac_sbr_ctx_alloc_init_fixed(AACDecContext *ac, ChannelElement **che, int void ff_aac_sbr_ctx_close(ChannelElement *che); void ff_aac_sbr_ctx_close_fixed(ChannelElement *che); +/** Flush SBR state history on seek flush */ +void ff_aac_sbr_flush(ChannelElement *che); +void ff_aac_sbr_flush_fixed(ChannelElement *che); + /** Decode one SBR element. */ int ff_aac_sbr_decode_extension(AACDecContext *ac, ChannelElement *che, GetBitContext *gb, int crc, int cnt, int id_aac, diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c index c10f5f312d..45cb55fe55 100644 --- a/libavcodec/aacsbr_template.c +++ b/libavcodec/aacsbr_template.c @@ -119,6 +119,15 @@ av_cold void AAC_RENAME(ff_aac_sbr_ctx_close)(ChannelElement *che) av_tx_uninit(&sbr->mdct_ana); } +void AAC_RENAME(ff_aac_sbr_flush)(ChannelElement *che) +{ + SpectralBandReplication *sbr = get_sbr(che); + if (sbr) { + memset(&sbr->data, 0, sizeof(sbr->data)); + sbr->start = 0; + } +} + static int qsort_comparison_function_int16(const void *a, const void *b) { return *(const int16_t *)a - *(const int16_t *)b; -- 2.25.1
_______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
