diff options
author | Clément Bœsch <u@pkh.me> | 2013-09-08 09:43:53 +0200 |
---|---|---|
committer | Clément Bœsch <u@pkh.me> | 2013-09-08 12:54:49 +0200 |
commit | f8678dcef3c5b0ea82e898e1f419863409fa135f (patch) | |
tree | e905b3a26ff4c371c639be49b539c79c6af116e5 /libavformat/subtitles.c | |
parent | 53fb52ac859c1c1f81a87336b1f40ac6226b3976 (diff) | |
download | ffmpeg-f8678dcef3c5b0ea82e898e1f419863409fa135f.tar.gz |
avformat/vobsub: fix seeking.
Diffstat (limited to 'libavformat/subtitles.c')
-rw-r--r-- | libavformat/subtitles.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c index 21d68a9739..b6d335c6e2 100644 --- a/libavformat/subtitles.c +++ b/libavformat/subtitles.c @@ -111,7 +111,8 @@ int ff_subtitles_queue_seek(FFDemuxSubtitlesQueue *q, AVFormatContext *s, int st for (i = 0; i < q->nb_subs; i++) { int64_t pts = q->subs[i].pts; uint64_t ts_diff = FFABS(pts - ts); - if (pts >= min_ts && pts <= max_ts && ts_diff < min_ts_diff) { + if ((stream_index == -1 || q->subs[i].stream_index == stream_index) && + pts >= min_ts && pts <= max_ts && ts_diff < min_ts_diff) { min_ts_diff = ts_diff; idx = i; } @@ -121,13 +122,24 @@ int ff_subtitles_queue_seek(FFDemuxSubtitlesQueue *q, AVFormatContext *s, int st /* look back in the latest subtitles for overlapping subtitles */ ts_selected = q->subs[idx].pts; for (i = idx - 1; i >= 0; i--) { - if (q->subs[i].duration <= 0) + if (q->subs[i].duration <= 0 || + (stream_index != -1 && q->subs[i].stream_index != stream_index)) continue; if (q->subs[i].pts > ts_selected - q->subs[i].duration) idx = i; else break; } + + /* If the queue is used to store multiple subtitles streams (like with + * VobSub) and the stream index is not specified, we need to make sure + * to focus on the smallest file position offset for a same timestamp; + * queue is ordered by pts and then filepos, so we can take the first + * entry for a given timestamp. */ + if (stream_index == -1) + while (idx > 0 && q->subs[idx - 1].pts == q->subs[idx].pts) + idx--; + q->current_sub_idx = idx; } return 0; |