From d978725394991e13a07a8002e0ff8b7d01eea08a Mon Sep 17 00:00:00 2001 From: Xiujun Wang Date: Tue, 29 Sep 2026 12:51:57 +0800 Subject: [PATCH] Fix repeated encoder_headers calls accumulating NALs Generate stream headers in a fresh NALList and transfer the result to the encoder-owned list. This prevents repeated calls on one encoder from returning previous VPS, SPS, PPS, and SEI NALs again while preserving the configured Annex B mode. Verified against unmodified upstream and this change with three consecutive calls in Annex B and length-prefixed modes. Upstream returned 4, 8, then 12 NALs; this change returns 4 on every call with identical payloads. --- source/encoder/api.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/encoder/api.cpp b/source/encoder/api.cpp index efcc6bdb6..364f832f0 100644 --- a/source/encoder/api.cpp +++ b/source/encoder/api.cpp @@ -282,7 +282,10 @@ int x265_encoder_headers(x265_encoder *enc, x265_nal **pp_nal, uint32_t *pi_nal) return -1; } } - encoder->getStreamHeaders(encoder->m_nalList, sbacCoder, bs); + NALList nalList; + nalList.m_annexB = encoder->m_nalList.m_annexB; + encoder->getStreamHeaders(nalList, sbacCoder, bs); + encoder->m_nalList.takeContents(nalList); *pp_nal = &encoder->m_nalList.m_nal[0]; if (pi_nal) *pi_nal = encoder->m_nalList.m_numNal; return encoder->m_nalList.m_occupancy;