diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-10-24 00:57:46 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-10-24 00:57:46 +0100 |
| commit | 6d1748f37097e6f61ee1c6fb66c4352b0834ec8c (patch) | |
| tree | eadd9dc24388fff2e54a0cab07afd9a9ed27602e /src/lib | |
| parent | 2783bac450101e809c485ef249ce55a9c6d7996e (diff) | |
Try to fix up subtitle timing a bit.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/decoder.cc | 2 | ||||
| -rw-r--r-- | src/lib/ffmpeg_decoder.cc | 4 | ||||
| -rw-r--r-- | src/lib/subtitle.cc | 5 | ||||
| -rw-r--r-- | src/lib/subtitle.h | 2 |
4 files changed, 7 insertions, 6 deletions
diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc index c0ad85da3..da75decc8 100644 --- a/src/lib/decoder.cc +++ b/src/lib/decoder.cc @@ -352,7 +352,7 @@ Decoder::process_video (AVFrame* frame) } shared_ptr<Subtitle> sub; - if (_timed_subtitle && _timed_subtitle->displayed_at (double (last_video_frame()) / rint (_fs->frames_per_second()))) { + if (_timed_subtitle && _timed_subtitle->displayed_at (double (last_video_frame()) / _fs->frames_per_second())) { sub = _timed_subtitle->subtitle (); } diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index e2aa8add0..e954294ec 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -304,7 +304,7 @@ FFmpegDecoder::do_pass () process_audio (_frame->data[0], data_size); } - } else if (_subtitle_stream >= 0 && _packet.stream_index == _subtitle_stream && _opt->decode_subtitles) { + } else if (_subtitle_stream >= 0 && _packet.stream_index == _subtitle_stream && _opt->decode_subtitles && _first_video) { int got_subtitle; AVSubtitle sub; @@ -313,7 +313,7 @@ FFmpegDecoder::do_pass () no AVSubtitleRects. */ if (sub.num_rects > 0) { - process_subtitle (shared_ptr<TimedSubtitle> (new TimedSubtitle (sub))); + process_subtitle (shared_ptr<TimedSubtitle> (new TimedSubtitle (sub, _first_video.get()))); } avsubtitle_free (&sub); } diff --git a/src/lib/subtitle.cc b/src/lib/subtitle.cc index f851d5643..37c372c20 100644 --- a/src/lib/subtitle.cc +++ b/src/lib/subtitle.cc @@ -32,13 +32,14 @@ using namespace boost; /** Construct a TimedSubtitle. This is a subtitle image, position, * and a range of time over which it should be shown. * @param sub AVSubtitle to read. + * @param c Fractional seconds that should be subtracted from the AVSubtitle's PTS. */ -TimedSubtitle::TimedSubtitle (AVSubtitle const & sub) +TimedSubtitle::TimedSubtitle (AVSubtitle const & sub, double c) { assert (sub.rects > 0); /* subtitle PTS in seconds */ - float const packet_time = (sub.pts / AV_TIME_BASE) + float (sub.pts % AV_TIME_BASE) / 1e6; + double const packet_time = ((sub.pts / AV_TIME_BASE) + float (sub.pts % AV_TIME_BASE) / 1e6) - c; /* hence start time for this sub */ _from = packet_time + (double (sub.start_display_time) / 1e3); diff --git a/src/lib/subtitle.h b/src/lib/subtitle.h index 38ba4e70e..590e0dd31 100644 --- a/src/lib/subtitle.h +++ b/src/lib/subtitle.h @@ -63,7 +63,7 @@ subtitle_transformed_area ( class TimedSubtitle { public: - TimedSubtitle (AVSubtitle const &); + TimedSubtitle (AVSubtitle const &, double c); bool displayed_at (double t) const; |
