Try to fix overrunning subtitles.
authorCarl Hetherington <cth@carlh.net>
Wed, 24 Oct 2012 12:52:24 +0000 (13:52 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 24 Oct 2012 12:52:24 +0000 (13:52 +0100)
src/lib/decoder.cc
src/lib/ffmpeg_decoder.cc

index da75decc8411af6874efd3f71f072ef8728a3838..045c1b818270052d58a93249377a7e2a6f5c6e27 100644 (file)
@@ -463,7 +463,7 @@ Decoder::process_subtitle (shared_ptr<TimedSubtitle> s)
 {
        _timed_subtitle = s;
        
-       if (_opt->apply_crop) {
+       if (_timed_subtitle && _opt->apply_crop) {
                Position const p = _timed_subtitle->subtitle()->position ();
                _timed_subtitle->subtitle()->set_position (Position (p.x - _fs->crop().left, p.y - _fs->crop().top));
        }
index e954294ecee2c198a8275d22164f09c6a8c8eb8b..9891bb55b75366ff2c20b1a80e327464ce98fadc 100644 (file)
@@ -309,11 +309,13 @@ FFmpegDecoder::do_pass ()
                int got_subtitle;
                AVSubtitle sub;
                if (avcodec_decode_subtitle2 (_subtitle_codec_context, &sub, &got_subtitle, &_packet) && got_subtitle) {
-                       /* I'm not entirely sure why, but sometimes we get an AVSubtitle with
-                          no AVSubtitleRects.
+                       /* Sometimes we get an empty AVSubtitle, which is used by some codecs to
+                          indicate that the previous subtitle should stop.
                        */
                        if (sub.num_rects > 0) {
                                process_subtitle (shared_ptr<TimedSubtitle> (new TimedSubtitle (sub, _first_video.get())));
+                       } else {
+                               process_subtitle (shared_ptr<TimedSubtitle> ());
                        }
                        avsubtitle_free (&sub);
                }