diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-01-14 02:27:04 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-01-14 02:27:04 +0000 |
| commit | 1f33b815df5d780f123c6bdf8f110a4f2fc70363 (patch) | |
| tree | da0470537aa82a98029e71f172cac7b593223982 | |
| parent | 77b3fe5cb14784c9365792b0c15f8a68d11546dd (diff) | |
Only put subtitles in a frame if they overlap more than half of that
frame; may help with #1166.
| -rw-r--r-- | src/lib/active_subtitles.cc | 13 | ||||
| -rw-r--r-- | src/lib/active_subtitles.h | 2 | ||||
| -rw-r--r-- | src/lib/dcp_decoder.cc | 4 | ||||
| -rw-r--r-- | src/lib/player.cc | 2 |
4 files changed, 13 insertions, 8 deletions
diff --git a/src/lib/active_subtitles.cc b/src/lib/active_subtitles.cc index ff6724a99..bc34a8942 100644 --- a/src/lib/active_subtitles.cc +++ b/src/lib/active_subtitles.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2017 Carl Hetherington <cth@carlh.net> + Copyright (C) 2017-2018 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -29,13 +29,14 @@ using std::pair; using std::make_pair; using boost::weak_ptr; using boost::shared_ptr; +using boost::optional; -/** Get the subtitles that should be burnt into a frame at a given time. - * @param time Frame time. +/** Get the subtitles that should be burnt into a given period. + * @param period Period of interest. * @param always_burn_subtitles Always burn subtitles even if their content is not set to burn. */ list<PlayerSubtitles> -ActiveSubtitles::get_burnt (DCPTime time, bool always_burn_subtitles) const +ActiveSubtitles::get_burnt (DCPTimePeriod period, bool always_burn_subtitles) const { list<PlayerSubtitles> ps; @@ -52,7 +53,9 @@ ActiveSubtitles::get_burnt (DCPTime time, bool always_burn_subtitles) const } BOOST_FOREACH (Period j, i->second) { - if (j.from <= time && (!j.to || j.to.get() > time)) { + DCPTimePeriod test (j.from, j.to.get_value_or(DCPTime::max())); + optional<DCPTimePeriod> overlap = period.overlap (test); + if (overlap && overlap->duration() > DCPTime(period.duration().get() / 2)) { ps.push_back (j.subs); } } diff --git a/src/lib/active_subtitles.h b/src/lib/active_subtitles.h index 97ca4c7db..1496bc5d2 100644 --- a/src/lib/active_subtitles.h +++ b/src/lib/active_subtitles.h @@ -36,7 +36,7 @@ class Piece; class ActiveSubtitles : public boost::noncopyable { public: - std::list<PlayerSubtitles> get_burnt (DCPTime time, bool always_burn_subtitles) const; + std::list<PlayerSubtitles> get_burnt (DCPTimePeriod period, bool always_burn_subtitles) const; void clear_before (DCPTime time); void clear (); void add_from (boost::weak_ptr<Piece> piece, PlayerSubtitles ps, DCPTime from); diff --git a/src/lib/dcp_decoder.cc b/src/lib/dcp_decoder.cc index 23b834767..68aa214ab 100644 --- a/src/lib/dcp_decoder.cc +++ b/src/lib/dcp_decoder.cc @@ -189,12 +189,14 @@ DCPDecoder::pass_subtitles (ContentTime next) ); BOOST_FOREACH (dcp::SubtitleString i, subs) { + list<dcp::SubtitleString> s; + s.push_back (i); subtitle->emit_text ( ContentTimePeriod ( ContentTime::from_frames (_offset - entry_point, vfr) + ContentTime::from_seconds (i.in().as_seconds ()), ContentTime::from_frames (_offset - entry_point, vfr) + ContentTime::from_seconds (i.out().as_seconds ()) ), - subs + s ); } } diff --git a/src/lib/player.cc b/src/lib/player.cc index 8e56991f8..eb8593e43 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -624,7 +624,7 @@ Player::subtitles_for_frame (DCPTime time) const { list<PositionImage> subtitles; - BOOST_FOREACH (PlayerSubtitles i, _active_subtitles.get_burnt (time, _always_burn_subtitles)) { + BOOST_FOREACH (PlayerSubtitles i, _active_subtitles.get_burnt (DCPTimePeriod(time, time + DCPTime::from_frames(1, _film->video_frame_rate())), _always_burn_subtitles)) { /* Image subtitles */ list<PositionImage> c = transform_image_subtitles (i.image); |
