Try to fix up subtitle timing a bit.
authorCarl Hetherington <cth@carlh.net>
Tue, 23 Oct 2012 23:57:46 +0000 (00:57 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 23 Oct 2012 23:57:46 +0000 (00:57 +0100)
src/lib/decoder.cc
src/lib/ffmpeg_decoder.cc
src/lib/subtitle.cc
src/lib/subtitle.h

index c0ad85da3523ca3effa15a599a8024ae55e17e38..da75decc8411af6874efd3f71f072ef8728a3838 100644 (file)
@@ -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 ();
                        }
 
index e2aa8add061a3973e00e742ab994be22181c12dd..e954294ecee2c198a8275d22164f09c6a8c8eb8b 100644 (file)
@@ -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);
                }
index f851d5643a34792ddbfe7bf12694d70407db22f7..37c372c20548f2f01508ead78346daf363494afc 100644 (file)
@@ -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);
index 38ba4e70e0170fabd5e2a71ee2ad9eadceb5a2ee..590e0dd31b8ac2865d680b5f3e7343bc76560e39 100644 (file)
@@ -63,7 +63,7 @@ subtitle_transformed_area (
 class TimedSubtitle
 {
 public:
-       TimedSubtitle (AVSubtitle const &);
+       TimedSubtitle (AVSubtitle const &, double c);
 
        bool displayed_at (double t) const;