[FFmpeg-devel] [PATCH 4/6] avcodec/packet: Add AV_PKT_FLAG_NEW_SEQUENCE flag

Zhao Zhili quinkblack at foxmail.com
Tue Mar 18 14:58:47 EET 2025


From: Zhao Zhili <zhilizhao at tencent.com>

Sometimes AV_PKT_FLAG_KEY is the start of a new sequence, sometimes
it's not. For example, HEVC CRA NALU can be marked as keyframe.

hevc decoder doesn't check AV_PKT_FLAG_KEY, and doesn't treat CRA
as new sequence. But sometimes CRA is really the start of a new
sequence, and the decoder should flush all pictures out, e.g.,
after a rewind by mp4 editlist.

AV_PKT_FLAG_KEY works with no problem for seek, AV_PKT_FLAG_NEW_SEQUENCE
works for rewind inside demuxer, that is, no explicit flush on
decoder.
---
 libavcodec/packet.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/libavcodec/packet.h b/libavcodec/packet.h
index c1f1ad7b43..331c66d7aa 100644
--- a/libavcodec/packet.h
+++ b/libavcodec/packet.h
@@ -612,6 +612,16 @@ typedef struct AVPacketList {
  */
 #define AV_PKT_FLAG_DISPOSABLE 0x0010
 
+/**
+ * Flag is used to indicate the start of a new sequence.
+ *
+ * For example, HEVC CRA can be handled differently depending on whether it's
+ * the start of a new sequence or not.
+ *
+ * A new sequence can be created by timeline map in mp4 editlist.
+ */
+#define AV_PKT_FLAG_NEW_SEQUENCE 0x0020
+
 enum AVSideDataParamChangeFlags {
     AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE    = 0x0004,
     AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS     = 0x0008,
-- 
2.46.0



More information about the ffmpeg-devel mailing list