diff options
| author | Carl Hetherington <cth@carlh.net> | 2021-03-16 14:24:48 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2021-03-16 14:37:42 +0100 |
| commit | 3b78e9223c9be784531475acacb88b59b2459f48 (patch) | |
| tree | 7c97e11d3e4fd364f015c186594b41d13bcca495 /src/lib | |
| parent | 7a1563c37d6e4e8ab016e8d3b2bcf5e29a327053 (diff) | |
Split subtitles at reel boundaries (#1918).
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/reel_writer.cc | 11 | ||||
| -rw-r--r-- | src/lib/writer.cc | 32 | ||||
| -rw-r--r-- | src/lib/writer.h | 12 |
3 files changed, 49 insertions, 6 deletions
diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc index ad52a1ca1..184707373 100644 --- a/src/lib/reel_writer.cc +++ b/src/lib/reel_writer.cc @@ -868,11 +868,12 @@ ReelWriter::write (PlayerText subs, TextType type, optional<DCPTextTrack> track, DCPOMATIC_ASSERT (false); } - auto const vfr = film()->video_frame_rate(); + /* timecode rate for subtitles we emit; we might as well stick to ms accuracy here, I think */ + auto const tcr = 1000; for (auto i: subs.string) { - i.set_in (dcp::Time(period.from.seconds() - _period.from.seconds(), vfr)); - i.set_out (dcp::Time(period.to.seconds() - _period.from.seconds(), vfr)); + i.set_in (dcp::Time(period.from.seconds() - _period.from.seconds(), tcr)); + i.set_out (dcp::Time(period.to.seconds() - _period.from.seconds(), tcr)); asset->add (make_shared<dcp::SubtitleString>(i)); } @@ -880,8 +881,8 @@ ReelWriter::write (PlayerText subs, TextType type, optional<DCPTextTrack> track, asset->add ( make_shared<dcp::SubtitleImage>( i.image->as_png(), - dcp::Time(period.from.seconds() - _period.from.seconds(), vfr), - dcp::Time(period.to.seconds() - _period.from.seconds(), vfr), + dcp::Time(period.from.seconds() - _period.from.seconds(), tcr), + dcp::Time(period.to.seconds() - _period.from.seconds(), tcr), i.rectangle.x, dcp::HAlign::LEFT, i.rectangle.y, dcp::VAlign::TOP, dcp::Time(), dcp::Time() ) diff --git a/src/lib/writer.cc b/src/lib/writer.cc index ad588f0a6..4386b8e26 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -545,6 +545,7 @@ Writer::finish (boost::filesystem::path output_dcp) LOG_GENERAL_NC ("Finishing ReelWriters"); for (auto& i: _reels) { + write_hanging_text (i); i.finish (output_dcp); } @@ -798,6 +799,23 @@ Writer::write (PlayerText text, TextType type, optional<DCPTextTrack> track, DCP while ((*reel)->period().to <= period.from) { ++(*reel); DCPOMATIC_ASSERT (*reel != _reels.end()); + write_hanging_text (**reel); + } + + if (period.to > (*reel)->period().to) { + /* This text goes off the end of the reel. Store parts of it that should go into + * other reels. + */ + for (auto i = std::next(*reel); i != _reels.end(); ++i) { + auto overlap = i->period().overlap(period); + if (overlap) { + _hanging_texts.push_back (HangingText{text, type, track, *overlap}); + } + } + /* Back off from the reel boundary by a couple of frames to avoid tripping checks + * for subtitles being too close together. + */ + period.to = (*reel)->period().to - DCPTime::from_frames(2, film()->video_frame_rate()); } (*reel)->write (text, type, track, period); @@ -907,3 +925,17 @@ Writer::calculate_referenced_digests (boost::function<void (float)> set_progress } } + +void +Writer::write_hanging_text (ReelWriter& reel) +{ + vector<HangingText> new_hanging_texts; + for (auto i: _hanging_texts) { + if (i.period.from == reel.period().from) { + reel.write (i.text, i.type, i.track, i.period); + } else { + new_hanging_texts.push_back (i); + } + } + _hanging_texts = new_hanging_texts; +} diff --git a/src/lib/writer.h b/src/lib/writer.h index 14d4b7faa..aab7d5fc7 100644 --- a/src/lib/writer.h +++ b/src/lib/writer.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -129,6 +129,7 @@ private: void set_digest_progress (Job* job, float progress); void write_cover_sheet (boost::filesystem::path output_dcp); void calculate_referenced_digests (boost::function<void (float)> set_progress); + void write_hanging_text (ReelWriter& reel); std::weak_ptr<Job> _job; std::vector<ReelWriter> _reels; @@ -204,4 +205,13 @@ private: bool _have_subtitles = false; /** all closed caption tracks that we have on any reel */ std::set<DCPTextTrack> _have_closed_captions; + + struct HangingText { + PlayerText text; + TextType type; + boost::optional<DCPTextTrack> track; + dcpomatic::DCPTimePeriod period; + }; + + std::vector<HangingText> _hanging_texts; }; |
