From: Zhao Zhili <zhiliz...@tencent.com> --- libavformat/avformat.h | 2 ++ libavformat/mov.c | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 498c557a3c..f83151a73f 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -611,6 +611,8 @@ typedef struct AVIndexEntry { #define AVINDEX_DISCARD_FRAME 0x0002 /** * Flag is used to indicate which frame should be discarded after decoding. */ +#define AVINDEX_NEW_SEQUENCE 0x0004 /* Mark the start of a new sequence */ + int flags:2; int size:30; //Yeah, trying to keep the size of this small to reduce memory requirements (it is 24 vs. 32 bytes due to possible 8-byte alignment). int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */ diff --git a/libavformat/mov.c b/libavformat/mov.c index bf526db67a..787a2b87e6 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -4394,20 +4394,23 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) } } - if (add_index_entry(st, current->pos, edit_list_dts_counter, current->size, - current->min_distance, flags) == -1) { - av_log(mov->fc, AV_LOG_ERROR, "Cannot add index entry\n"); - break; - } // Update the index ranges array if (!current_index_range || index != current_index_range->end) { current_index_range = current_index_range ? current_index_range + 1 : msc->index_ranges; current_index_range->start = index; + if ((flags & AVINDEX_KEYFRAME) && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) + flags |= AVINDEX_NEW_SEQUENCE; } current_index_range->end = index + 1; + if (add_index_entry(st, current->pos, edit_list_dts_counter, current->size, + current->min_distance, flags) == -1) { + av_log(mov->fc, AV_LOG_ERROR, "Cannot add index entry\n"); + break; + } + // Only start incrementing DTS in frame_duration amounts, when we encounter a frame in edit list. if (edit_list_start_encountered > 0) { edit_list_dts_counter = edit_list_dts_counter + frame_duration; @@ -10889,7 +10892,11 @@ static int mov_finalize_packet(AVFormatContext *s, AVStream *st, AVIndexEntry *s uint8_t sample_is_depended_on = (sample_flags >> 2) & 0x3; pkt->flags |= sample_is_depended_on == MOV_SAMPLE_DEPENDENCY_NO ? AV_PKT_FLAG_DISPOSABLE : 0; } - pkt->flags |= sample->flags & AVINDEX_KEYFRAME ? AV_PKT_FLAG_KEY : 0; + if (sample->flags & AVINDEX_KEYFRAME) { + pkt->flags |= AV_PKT_FLAG_KEY; + if (sample->flags & AVINDEX_NEW_SEQUENCE) + pkt->flags |= AV_PKT_FLAG_NEW_SEQUENCE; + } pkt->pos = sample->pos; /* Multiple stsd handling. */ -- 2.46.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".