summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-09-25 22:10:35 +0100
committerCarl Hetherington <cth@carlh.net>2015-09-25 22:10:35 +0100
commit19483a961b274befaff263d8646a78a56c102c65 (patch)
tree9480b25324384144a239c1170163da0a490241fe /src
parent8046947a9f3d7d71084a0a70e055e85f3f453c8b (diff)
Fix assertion failure with .MTS files.
These files have subs which start but are never officially finished; this means there are no `to' times to find in find_subtitle_to. Cope with this by stopping the previous sub when a new one arrives if there hasn't been a proper "stop" in the mean time.
Diffstat (limited to 'src')
-rw-r--r--src/lib/ffmpeg_examiner.cc28
-rw-r--r--src/lib/ffmpeg_examiner.h3
2 files changed, 26 insertions, 5 deletions
diff --git a/src/lib/ffmpeg_examiner.cc b/src/lib/ffmpeg_examiner.cc
index 576782d0b..6173e0415 100644
--- a/src/lib/ffmpeg_examiner.cc
+++ b/src/lib/ffmpeg_examiner.cc
@@ -134,6 +134,17 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c, shared_ptr<Jo
break;
}
}
+
+ for (LastSubtitleMap::const_iterator i = _last_subtitle_start.begin(); i != _last_subtitle_start.end(); ++i) {
+ if (i->second) {
+ i->first->add_subtitle (
+ ContentTimePeriod (
+ i->second.get (),
+ ContentTime::from_frames (video_length(), video_frame_rate().get_value_or (24))
+ )
+ );
+ }
+ }
}
void
@@ -176,14 +187,23 @@ FFmpegExaminer::subtitle_packet (AVCodecContext* context, shared_ptr<FFmpegSubti
AVSubtitle sub;
if (avcodec_decode_subtitle2 (context, &sub, &frame_finished, &_packet) >= 0 && frame_finished) {
FFmpegSubtitlePeriod const period = subtitle_period (sub);
- if (sub.num_rects <= 0 && _last_subtitle_start) {
- stream->add_subtitle (ContentTimePeriod (_last_subtitle_start.get (), period.from));
- _last_subtitle_start = optional<ContentTime> ();
+ LastSubtitleMap::iterator last = _last_subtitle_start.find (stream);
+ if (last != _last_subtitle_start.end() && last->second) {
+ /* We have seen the start of a subtitle but not yet the end. Whatever this is
+ finishes the previous subtitle, so add it */
+ stream->add_subtitle (ContentTimePeriod (last->second.get (), period.from));
+ if (sub.num_rects == 0) {
+ /* This is a `proper' end-of-subtitle */
+ _last_subtitle_start[stream] = optional<ContentTime> ();
+ } else {
+ /* This is just another subtitle, so we start again */
+ _last_subtitle_start[stream] = period.from;
+ }
} else if (sub.num_rects == 1) {
if (period.to) {
stream->add_subtitle (ContentTimePeriod (period.from, period.to.get ()));
} else {
- _last_subtitle_start = period.from;
+ _last_subtitle_start[stream] = period.from;
}
}
avsubtitle_free (&sub);
diff --git a/src/lib/ffmpeg_examiner.h b/src/lib/ffmpeg_examiner.h
index 6fd3220d4..27bff08b4 100644
--- a/src/lib/ffmpeg_examiner.h
+++ b/src/lib/ffmpeg_examiner.h
@@ -85,5 +85,6 @@ private:
Frame _video_length;
bool _need_video_length;
- boost::optional<ContentTime> _last_subtitle_start;
+ typedef std::map<boost::shared_ptr<FFmpegSubtitleStream>, boost::optional<ContentTime> > LastSubtitleMap;
+ LastSubtitleMap _last_subtitle_start;
};