diff options
author | John Stebbins <[email protected]> | 2017-06-19 10:22:28 -0700 |
---|---|---|
committer | John Stebbins <[email protected]> | 2017-06-19 10:35:41 -0700 |
commit | 9ea4f44fd42c8617d418a8a34d126995164f3c32 (patch) | |
tree | a92aa131ed5e5a9ea2cbe5fb49d2af857b76a346 /libhb/reader.c | |
parent | 5e588aca20fb3a6412a9a503e7a765ba1ea742db (diff) |
reader: fix live preview generation for some streams
Fixes https://github.com/HandBrake/HandBrake/issues/685
For some stream types, libav does not seek all streams within the file
to the same position. So we get data from streams that is prior to the
desired preview start position leaking through. The result, for example,
is a preview that has audio that starts from the beginning of the file
and video that starts much later at the desired start pos.
Diffstat (limited to 'libhb/reader.c')
-rw-r--r-- | libhb/reader.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/libhb/reader.c b/libhb/reader.c index 7f1e7cc1a..53a8180a1 100644 --- a/libhb/reader.c +++ b/libhb/reader.c @@ -159,9 +159,29 @@ static int hb_reader_open( hb_work_private_t * r ) return 1; if (r->job->start_at_preview) { - hb_stream_seek(r->stream, (float)(r->job->start_at_preview - 1) / - (r->job->seek_points ? (r->job->seek_points + 1.0) - : 11.0)); + // First try seeking to PTS title duration / (seek_points + 1) + float frac = (float)(r->job->start_at_preview - 1) / + (r->job->seek_points ? (r->job->seek_points + 1.0) + : 11.0); + int64_t start = r->title->duration * frac; + if (hb_stream_seek_ts(r->stream, start) >= 0) + { + // If successful, we know the video stream has been seeked + // to the right location. But libav does not seek all + // streams (e.g. audio and subtitles) to the same position + // for some stream types (AVI). Setting start_found = 0 + // enables code that filters out packets that we receive + // before the correct start time is encountered. + r->start_found = 0; + r->job->reader_pts_offset = AV_NOPTS_VALUE; + } + else + { + // hb_stream_seek_ts only works for libav streams. + // TS and PS streams have not index and have timestamp + // discontinuities, so we seek to a byte position in these. + hb_stream_seek(r->stream, frac); + } } else if (r->job->pts_to_start) { |