From d5dc6e380409b003fc52a97251c2c16b29641cf0 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 27 Jun 2019 23:09:36 +0100 Subject: [PATCH] Fix incorrect timing of PNG subtitles in second and subsequent reels. Backported from 5728b8095b9522626d61b1c684a9492f759e2870 in v2.15.x. --- src/lib/reel_writer.cc | 4 +- test/data | 2 +- test/subtitle_reel_test.cc | 88 ++++++++++++++++++++++++++++++++++++++ test/wscript | 1 + 4 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 test/subtitle_reel_test.cc diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc index 3b9e413a2..b7ccc07ce 100644 --- a/src/lib/reel_writer.cc +++ b/src/lib/reel_writer.cc @@ -619,8 +619,8 @@ ReelWriter::write (PlayerText subs, TextType type, optional track, shared_ptr( new dcp::SubtitleImage( i.image->as_png(), - dcp::Time(period.from.seconds(), _film->video_frame_rate()), - dcp::Time(period.to.seconds(), _film->video_frame_rate()), + dcp::Time(period.from.seconds() - _period.from.seconds(), _film->video_frame_rate()), + dcp::Time(period.to.seconds() - _period.from.seconds(), _film->video_frame_rate()), i.rectangle.x, dcp::HALIGN_LEFT, i.rectangle.y, dcp::VALIGN_TOP, dcp::Time(), dcp::Time() ) diff --git a/test/data b/test/data index e5257e572..eda45cf07 160000 --- a/test/data +++ b/test/data @@ -1 +1 @@ -Subproject commit e5257e5721bde4d182f8317373030a1d99fbff93 +Subproject commit eda45cf0736a897f944a8c38e9aed9ca98d4c3ce diff --git a/test/subtitle_reel_test.cc b/test/subtitle_reel_test.cc new file mode 100644 index 000000000..7a722b460 --- /dev/null +++ b/test/subtitle_reel_test.cc @@ -0,0 +1,88 @@ +/* + Copyright (C) 2019 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + +#include "lib/film.h" +#include "lib/image_content.h" +#include "lib/dcp_subtitle_content.h" +#include "lib/video_content.h" +#include "test.h" +#include +#include +#include +#include +#include +#include + +using std::list; +using boost::shared_ptr; + +/* Check that timings are done correctly for multi-reel DCPs with PNG subs */ +BOOST_AUTO_TEST_CASE (subtitle_reel_test) +{ + shared_ptr film = new_test_film2 ("subtitle_reel_test"); + film->set_interop (true); + shared_ptr red_a (new ImageContent("test/data/flat_red.png")); + shared_ptr red_b (new ImageContent("test/data/flat_red.png")); + shared_ptr sub_a (new DCPSubtitleContent("test/data/png_subs/subs.xml")); + shared_ptr sub_b (new DCPSubtitleContent("test/data/png_subs/subs.xml")); + + film->examine_and_add_content (red_a); + film->examine_and_add_content (red_b); + film->examine_and_add_content (sub_a); + film->examine_and_add_content (sub_b); + + BOOST_REQUIRE (!wait_for_jobs()); + + red_a->set_position (film, dcpomatic::DCPTime()); + red_a->video->set_length (240); + sub_a->set_position (film, dcpomatic::DCPTime()); + red_b->set_position (film, dcpomatic::DCPTime::from_seconds(10)); + red_b->video->set_length (240); + sub_b->set_position (film, dcpomatic::DCPTime::from_seconds(10)); + + film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT); + + film->make_dcp (); + BOOST_REQUIRE (!wait_for_jobs()); + + dcp::DCP dcp ("build/test/subtitle_reel_test/" + film->dcp_name()); + dcp.read (); + BOOST_REQUIRE_EQUAL (dcp.cpls().size(), 1); + shared_ptr cpl = dcp.cpls().front(); + + list > reels = cpl->reels (); + BOOST_REQUIRE_EQUAL (reels.size(), 2); + list >::const_iterator i = reels.begin (); + BOOST_REQUIRE ((*i)->main_subtitle()); + BOOST_REQUIRE ((*i)->main_subtitle()->asset()); + shared_ptr A = boost::dynamic_pointer_cast((*i)->main_subtitle()->asset()); + BOOST_REQUIRE (A); + ++i; + BOOST_REQUIRE ((*i)->main_subtitle()); + BOOST_REQUIRE ((*i)->main_subtitle()->asset()); + shared_ptr B = boost::dynamic_pointer_cast((*i)->main_subtitle()->asset()); + BOOST_REQUIRE (B); + + BOOST_REQUIRE_EQUAL (A->subtitles().size(), 1); + BOOST_REQUIRE_EQUAL (B->subtitles().size(), 1); + + /* These times should be the same as they are should be offset from the start of the reel */ + BOOST_CHECK (A->subtitles().front()->in() == B->subtitles().front()->in()); +} diff --git a/test/wscript b/test/wscript index 8059ae2d3..5e7634ea3 100644 --- a/test/wscript +++ b/test/wscript @@ -106,6 +106,7 @@ def build(bld): ssa_subtitle_test.cc stream_test.cc subtitle_charset_test.cc + subtitle_reel_test.cc subtitle_reel_number_test.cc subtitle_trim_test.cc test.cc -- 2.30.2