Cope with AVSubtitles having no AVSubtitleRects.
authorCarl Hetherington <cth@carlh.net>
Fri, 19 Oct 2012 23:52:08 +0000 (00:52 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 19 Oct 2012 23:52:08 +0000 (00:52 +0100)
src/lib/ffmpeg_decoder.cc
src/lib/subtitle.cc

index 828934604b0db42426567aae5a17863db4d425b0..5541883439a753c53d25b53c9eb49d792ce2b3ac 100644 (file)
@@ -254,7 +254,12 @@ FFmpegDecoder::do_pass ()
                int got_subtitle;
                AVSubtitle sub;
                if (avcodec_decode_subtitle2 (_subtitle_codec_context, &sub, &got_subtitle, &_packet) && got_subtitle) {
-                       process_subtitle (shared_ptr<TimedSubtitle> (new TimedSubtitle (sub)));
+                       /* I'm not entirely sure why, but sometimes we get an AVSubtitle with
+                          no AVSubtitleRects.
+                       */
+                       if (sub.num_rects > 0) {
+                               process_subtitle (shared_ptr<TimedSubtitle> (new TimedSubtitle (sub)));
+                       }
                        avsubtitle_free (&sub);
                }
        }
index 451d836913f5a07e4476d0dd3c50de29e98e9723..f851d5643a34792ddbfe7bf12694d70407db22f7 100644 (file)
@@ -35,6 +35,8 @@ using namespace boost;
  */
 TimedSubtitle::TimedSubtitle (AVSubtitle const & sub)
 {
+       assert (sub.rects > 0);
+       
        /* subtitle PTS in seconds */
        float const packet_time = (sub.pts / AV_TIME_BASE) + float (sub.pts % AV_TIME_BASE) / 1e6;