If the last four bytes form a valid start code, the loop would run another time. Since (start == buf_end), start_code is invalidated so the loop terminates.
However, calling avpriv_find_start_code() with p == end, it will immediately return due to the zero size buffer. Thus the history is not needed. --- libavcodec/cbs_mpeg2.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index f2efedde5d..bf95fb7546 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -168,8 +168,9 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, // the next unit will be treated as the last unit. start_code = 0; } - - end = avpriv_find_start_code(start, buf_end, &start_code, 0); + else { + end = avpriv_find_start_code(start, buf_end, &start_code, 1); + } start--; // decrement so start points to the byte containing the start_code_identifier // (may be the last byte of fragment->data); end points to the byte -- 2.32.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".