diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-10-08 00:45:22 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-10-08 00:45:22 +0100 |
| commit | 37494990bbe81f41f581de8258dc7353b82d662d (patch) | |
| tree | 01fd28caeff323c9ffed0bf9b04ecee358b316d0 /src/lib/text_subtitle_decoder.cc | |
| parent | b0463c6c22d51f6297eea313b429348c3bec3971 (diff) | |
Fix overlapping burnt-in subtitles in some cases (#959).
Firstly, when finding subtitles that exist during a period, only
return those which overlap more than half the period. This means
that, in a fight over a frame, the longest-running subtitle in that
frame will win.
Secondly, make SubtitleDecoder::get pick the wanted subtitles from
the cache simply by comparing their periods to those that were
requested. I think this is nicer than what was there before
(basically reevaulating 'what subtitle(s) for this period') and
also makes the first part of this commit effective.
Diffstat (limited to 'src/lib/text_subtitle_decoder.cc')
| -rw-r--r-- | src/lib/text_subtitle_decoder.cc | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/lib/text_subtitle_decoder.cc b/src/lib/text_subtitle_decoder.cc index bec2ab9b7..05bde829c 100644 --- a/src/lib/text_subtitle_decoder.cc +++ b/src/lib/text_subtitle_decoder.cc @@ -85,10 +85,20 @@ TextSubtitleDecoder::text_subtitles_during (ContentTimePeriod p, bool starting) list<ContentTimePeriod> d; + /* Only take `during' (not starting) subs if they overlap more than half the requested period; + here's the threshold for being significant. + */ + ContentTime const significant (p.duration().get() / 2); + for (vector<sub::Subtitle>::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) { ContentTimePeriod t = content_time_period (*i); - if ((starting && p.contains (t.from)) || (!starting && p.overlap (t))) { + if (starting && p.contains(t.from)) { d.push_back (t); + } else if (!starting) { + optional<ContentTimePeriod> const o = p.overlap (t); + if (o && o->duration() > significant) { + d.push_back (t); + } } } |
