From 6ab364df4b2a80b53f46d5ba3bd46a5557c90f5a Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 5 Nov 2014 20:47:42 +0100 Subject: demux_mkv: apply subtitle preroll only if needed, based on cue index The demuxer has a hack to seek to the cluster before the target cluster in order to "catch" subtitle lines that start before the seek target, but overlap with the video after the seek target. Avoid this hack if the cue index indicates that there are no overlapping subtitle packets that can be caught by seeking to the previous cluster. --- demux/demux_mkv.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'demux/demux_mkv.c') diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c index 0b51d9386e..417ac1ba38 100644 --- a/demux/demux_mkv.c +++ b/demux/demux_mkv.c @@ -2722,6 +2722,22 @@ static struct mkv_index *seek_with_cues(struct demuxer *demuxer, int seek_id, prev_target = index_pos; } } + if (mkv_d->index_has_durations) { + // If there are no earlier subtitles overlapping with the + // target cluster, then disable preroll-seeking. + bool overlap = false; + for (size_t i = 0; i < mkv_d->num_indexes; i++) { + struct mkv_index *cur = &mkv_d->indexes[i]; + overlap = cur->timecode <= index->timecode && + cur->timecode + cur->duration > index->timecode && + cur->filepos >= prev_target && + cur->filepos != seek_pos; + if (overlap) + break; + } + if (!overlap) + prev_target = 0; + } if (prev_target) seek_pos = prev_target; } -- cgit v1.2.3