diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
index 2a0cb1f6b5635d09641e0f45d90ebd9a05e9206a..e8a61cef6cdad7e36567ea5e4e07f69f1a0fc17b 100644
--- a/libavcodec/aaccoder.c
+++ b/libavcodec/aaccoder.c
@@ -370,7 +370,7 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s,
     }
     while (idx) {
         sce->sf_idx[bandaddr[idx]] = minq + q0;
-        minq = paths[idx][minq].prev;
+        minq = FFMAX(paths[idx][minq].prev, 0);
         idx--;
     }
     //set the same quantizers inside window groups