Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Zhao Zhili <quinkblack-at-foxmail.com@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Zhao Zhili <zhilizhao@tencent.com>
Subject: [FFmpeg-devel] [PATCH 5/6] avformat/mov: Notify new sequence at the start of editlist
Date: Tue, 18 Mar 2025 20:58:51 +0800
Message-ID: <tencent_2B963DCD1C203A4DB24FE9D504A73FB89207@qq.com> (raw)

From: Zhao Zhili <zhilizhao@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-request@ffmpeg.org with subject "unsubscribe".

                 reply	other threads:[~2025-03-18 12:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_2B963DCD1C203A4DB24FE9D504A73FB89207@qq.com \
    --to=quinkblack-at-foxmail.com@ffmpeg.org \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=zhilizhao@tencent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git