diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-01-31 21:36:36 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-01-31 21:36:36 +0000 |
| commit | 8bccd0af23b8e1ada43182c2531c21f06036ca37 (patch) | |
| tree | e8a71402c4804e673fa1e1c97bf7beeba40db37f /src/lib | |
| parent | 2d04092a7938c078ade1a1f54a485b96a23d510c (diff) | |
Fix missing subtitles when they start just after the start of a frame.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/dcpomatic_time.h | 4 | ||||
| -rw-r--r-- | src/lib/player.cc | 6 | ||||
| -rw-r--r-- | src/lib/render_subtitles.cc | 19 | ||||
| -rw-r--r-- | src/lib/render_subtitles.h | 2 |
4 files changed, 21 insertions, 10 deletions
diff --git a/src/lib/dcpomatic_time.h b/src/lib/dcpomatic_time.h index 204af3c1e..3d792467b 100644 --- a/src/lib/dcpomatic_time.h +++ b/src/lib/dcpomatic_time.h @@ -125,6 +125,10 @@ public: return Time<S, O> (llrint (HZ * frames_floor(r) / r)); } + Time<S, O> round (double r) const { + return Time<S, O> (llrint (HZ * frames_round(r) / r)); + } + double seconds () const { return double (_t) / HZ; } diff --git a/src/lib/player.cc b/src/lib/player.cc index 9ee8ab72c..ec7a93dac 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -658,7 +658,9 @@ Player::subtitles_for_frame (DCPTime time) const { list<PositionImage> subtitles; - BOOST_FOREACH (PlayerSubtitles i, _active_subtitles.get_burnt (DCPTimePeriod(time, time + DCPTime::from_frames(1, _film->video_frame_rate())), _always_burn_subtitles)) { + int const vfr = _film->video_frame_rate(); + + BOOST_FOREACH (PlayerSubtitles i, _active_subtitles.get_burnt (DCPTimePeriod(time, time + DCPTime::from_frames(1, vfr)), _always_burn_subtitles)) { /* Image subtitles */ list<PositionImage> c = transform_image_subtitles (i.image); @@ -666,7 +668,7 @@ Player::subtitles_for_frame (DCPTime time) const /* Text subtitles (rendered to an image) */ if (!i.text.empty ()) { - list<PositionImage> s = render_subtitles (i.text, i.fonts, _video_container_size, time); + list<PositionImage> s = render_subtitles (i.text, i.fonts, _video_container_size, time, vfr); copy (s.begin(), s.end(), back_inserter (subtitles)); } } diff --git a/src/lib/render_subtitles.cc b/src/lib/render_subtitles.cc index 56343cd50..5f587c313 100644 --- a/src/lib/render_subtitles.cc +++ b/src/lib/render_subtitles.cc @@ -85,7 +85,7 @@ set_source_rgba (Cairo::RefPtr<Cairo::Context> context, dcp::Colour colour, floa * at the same time and with the same fade in/out. */ static PositionImage -render_line (list<SubtitleString> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target, DCPTime time) +render_line (list<SubtitleString> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target, DCPTime time, int frame_rate) { /* XXX: this method can only handle italic / bold changes mid-line, nothing else yet. @@ -242,9 +242,12 @@ render_line (list<SubtitleString> subtitles, list<shared_ptr<Font> > fonts, dcp: /* Compute fade factor */ float fade_factor = 1; - DCPTime const fade_in_start = DCPTime::from_seconds (subtitles.front().in().as_seconds ()); + /* Round the fade start/end to the nearest frame start. Otherwise if a subtitle starts just after + the start of a frame it will be faded out. + */ + DCPTime const fade_in_start = DCPTime::from_seconds(subtitles.front().in().as_seconds()).round(frame_rate); DCPTime const fade_in_end = fade_in_start + DCPTime::from_seconds (subtitles.front().fade_up_time().as_seconds ()); - DCPTime const fade_out_end = DCPTime::from_seconds (subtitles.front().out().as_seconds ()); + DCPTime const fade_out_end = DCPTime::from_seconds (subtitles.front().out().as_seconds()).round(frame_rate); DCPTime const fade_out_start = fade_out_end - DCPTime::from_seconds (subtitles.front().fade_down_time().as_seconds ()); if (fade_in_start <= time && time <= fade_in_end && fade_in_start != fade_in_end) { @@ -347,23 +350,25 @@ render_line (list<SubtitleString> subtitles, list<shared_ptr<Font> > fonts, dcp: return PositionImage (image, Position<int> (max (0, x), max (0, y))); } -/** @param time Time of the frame that these subtitles are going on */ +/** @param time Time of the frame that these subtitles are going on. + * @param frame_rate DCP frame rate. + */ list<PositionImage> -render_subtitles (list<SubtitleString> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target, DCPTime time) +render_subtitles (list<SubtitleString> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target, DCPTime time, int frame_rate) { list<SubtitleString> pending; list<PositionImage> images; BOOST_FOREACH (SubtitleString const & i, subtitles) { if (!pending.empty() && fabs (i.v_position() - pending.back().v_position()) > 1e-4) { - images.push_back (render_line (pending, fonts, target, time)); + images.push_back (render_line (pending, fonts, target, time, frame_rate)); pending.clear (); } pending.push_back (i); } if (!pending.empty ()) { - images.push_back (render_line (pending, fonts, target, time)); + images.push_back (render_line (pending, fonts, target, time, frame_rate)); } return images; diff --git a/src/lib/render_subtitles.h b/src/lib/render_subtitles.h index 02bf3ec65..b1239bb3d 100644 --- a/src/lib/render_subtitles.h +++ b/src/lib/render_subtitles.h @@ -27,5 +27,5 @@ class Font; std::string marked_up (std::list<SubtitleString> subtitles, int target_height, float fade_factor); std::list<PositionImage> render_subtitles ( - std::list<SubtitleString>, std::list<boost::shared_ptr<Font> > fonts, dcp::Size, DCPTime + std::list<SubtitleString>, std::list<boost::shared_ptr<Font> > fonts, dcp::Size, DCPTime, int ); |
