summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-04-12 22:25:04 +0200
committerCarl Hetherington <cth@carlh.net>2025-04-12 22:25:04 +0200
commit19f1a934c9e3531da3bd95cdc854f491ee14e215 (patch)
tree93d473ae0c7edee05fe9ced05a1fa265ea27fdbb
parent2b38754e56ded471019ef910fb9c9a579fe5e1d9 (diff)
Fix case where -ve duration subtitles could be created at reel boundaries (#3012)
-rw-r--r--src/lib/writer.cc8
-rw-r--r--test/subtitle_reel_test.cc25
2 files changed, 31 insertions, 2 deletions
diff --git a/src/lib/writer.cc b/src/lib/writer.cc
index 9f64a1686..ce5d40c75 100644
--- a/src/lib/writer.cc
+++ b/src/lib/writer.cc
@@ -846,7 +846,11 @@ Writer::write (PlayerText text, TextType type, optional<DCPTextTrack> track, DCP
}
auto back_off = [this](DCPTimePeriod period) {
- period.to -= DCPTime::from_frames(2, film()->video_frame_rate());
+ auto const vfr = film()->video_frame_rate();
+ period.to -= DCPTime::from_frames(2, vfr);
+ if (period.duration().frames_floor(vfr) <= 0) {
+ period.to = period.from + DCPTime::from_frames(1, vfr);
+ }
return period;
};
@@ -860,7 +864,7 @@ Writer::write (PlayerText text, TextType type, optional<DCPTextTrack> track, DCP
_hanging_texts.push_back (HangingText{text, type, track, back_off(*overlap)});
}
}
- /* Back off from the reel boundary by a couple of frames to avoid tripping checks
+ /* Try to 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;
diff --git a/test/subtitle_reel_test.cc b/test/subtitle_reel_test.cc
index 877709f73..d72a543fd 100644
--- a/test/subtitle_reel_test.cc
+++ b/test/subtitle_reel_test.cc
@@ -234,3 +234,28 @@ BOOST_AUTO_TEST_CASE (subtitles_split_at_reel_boundaries)
}
}
+
+BOOST_AUTO_TEST_CASE(bad_subtitle_not_created_at_reel_boundaries)
+{
+ boost::filesystem::path const srt = "build/test/bad_subtitle_not_created_at_reel_boundaries.srt";
+ dcp::write_string_to_file("1\n00:00:10,000 -> 00:00:20,000\nHello world", srt);
+ auto content = content_factory(srt)[0];
+
+ auto film = new_test_film("bad_subtitle_not_created_at_reel_boundaries", { content });
+ film->set_reel_type(ReelType::CUSTOM);
+ content->text[0]->set_language(dcp::LanguageTag("de-DE"));
+ /* This is 1 frame after the start of the subtitle */
+ film->set_custom_reel_boundaries({dcpomatic::DCPTime::from_frames(241, 24)});
+
+ /* This is a tricky situation and the way DoM deals with it gives two Bv2.1
+ * warnings, but these are "should" not "shall" so I think it's OK.
+ */
+ make_and_verify_dcp(
+ film,
+ {
+ dcp::VerificationNote::Code::MISSING_CPL_METADATA,
+ dcp::VerificationNote::Code::INVALID_SUBTITLE_DURATION,
+ dcp::VerificationNote::Code::INVALID_SUBTITLE_SPACING,
+ });
+}
+