[FFmpeg-devel] [PATCH] mov: Make sure PTS are both monotonically increasing, and unique

Derek Buitenhuis derek.buitenhuis at gmail.com
Tue May 15 22:44:47 EEST 2018


We already did this for audio, but it should be done for video too.
If we don't, seeking back to the start of the file, for example, can
become quite broken, since the first N packets will have repeating
and nonmonotonic PTS, yet they need to be decoded even if they are
to be discarded.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
---
 libavformat/mov.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 1975011..a74983f 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3579,7 +3579,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
                     flags |= AVINDEX_DISCARD_FRAME;
                     av_log(mov->fc, AV_LOG_DEBUG, "drop a frame at curr_cts: %"PRId64" @ %"PRId64"\n", curr_cts, index);
 
-                    if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && edit_list_start_encountered == 0) {
+                    if (edit_list_start_encountered == 0) {
                         num_discarded_begin++;
                         frame_duration_buffer = av_realloc(frame_duration_buffer,
                                                            num_discarded_begin * sizeof(int64_t));
@@ -3605,7 +3605,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
                     edit_list_start_encountered = 1;
                     // Make timestamps strictly monotonically increasing for audio, by rewriting timestamps for
                     // discarded packets.
-                    if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && frame_duration_buffer) {
+                    if (frame_duration_buffer) {
                         fix_index_entry_timestamps(st, st->nb_index_entries, edit_list_dts_counter,
                                                    frame_duration_buffer, num_discarded_begin);
                         av_freep(&frame_duration_buffer);
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list