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.
This commit is contained in:
wm4 2014-11-05 20:47:42 +01:00
parent 805e952d82
commit 6ab364df4b
1 changed files with 16 additions and 0 deletions

View File

@ -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;
}