From 1f33b815df5d780f123c6bdf8f110a4f2fc70363 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 14 Jan 2018 02:27:04 +0000 Subject: [PATCH] Only put subtitles in a frame if they overlap more than half of that frame; may help with #1166. --- src/lib/active_subtitles.cc | 13 ++++++++----- src/lib/active_subtitles.h | 2 +- src/lib/dcp_decoder.cc | 4 +++- 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 + Copyright (C) 2017-2018 Carl Hetherington 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 -ActiveSubtitles::get_burnt (DCPTime time, bool always_burn_subtitles) const +ActiveSubtitles::get_burnt (DCPTimePeriod period, bool always_burn_subtitles) const { list 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 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 get_burnt (DCPTime time, bool always_burn_subtitles) const; + std::list get_burnt (DCPTimePeriod period, bool always_burn_subtitles) const; void clear_before (DCPTime time); void clear (); void add_from (boost::weak_ptr 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 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 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 c = transform_image_subtitles (i.image); -- 2.30.2