2 Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 /** @file test/srt_subtitle_test.cc
22 * @brief Test writing DCPs with subtitles from .srt.
27 #include "lib/string_text_file_content.h"
28 #include "lib/dcp_content_type.h"
30 #include "lib/ratio.h"
31 #include "lib/text_content.h"
33 #include <boost/test/unit_test.hpp>
34 #include <boost/algorithm/string.hpp>
39 using boost::shared_ptr;
41 /** Make a very short DCP with a single subtitle from .srt with no specified fonts */
42 BOOST_AUTO_TEST_CASE (srt_subtitle_test)
44 shared_ptr<Film> film = new_test_film ("srt_subtitle_test");
45 film->set_container (Ratio::from_id ("185"));
46 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
47 film->set_name ("frobozz");
48 film->set_audio_channels (6);
49 film->set_interop (false);
50 shared_ptr<StringTextFileContent> content (new StringTextFileContent("test/data/subrip2.srt"));
51 film->examine_and_add_content (content);
52 BOOST_REQUIRE (!wait_for_jobs());
54 content->only_text()->set_use (true);
55 content->only_text()->set_burn (false);
57 BOOST_REQUIRE (!wait_for_jobs());
59 /* Should be blank video with a subtitle MXF */
60 check_dcp ("test/data/srt_subtitle_test", film->dir (film->dcp_name ()));
63 /** Same again but with a `font' specified */
64 BOOST_AUTO_TEST_CASE (srt_subtitle_test2)
66 shared_ptr<Film> film = new_test_film ("srt_subtitle_test2");
67 film->set_container (Ratio::from_id ("185"));
68 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
69 film->set_name ("frobozz");
70 film->set_audio_channels (6);
71 film->set_interop (false);
72 shared_ptr<StringTextFileContent> content (new StringTextFileContent ("test/data/subrip2.srt"));
73 film->examine_and_add_content (content);
74 BOOST_REQUIRE (!wait_for_jobs());
76 content->only_text()->set_use (true);
77 content->only_text()->set_burn (false);
78 /* Use test/data/subrip2.srt as if it were a font file */
79 content->only_text()->fonts().front()->set_file("test/data/subrip2.srt");
82 BOOST_REQUIRE (!wait_for_jobs());
84 /* Should be blank video with a subtitle MXF */
85 check_dcp ("test/data/srt_subtitle_test2", film->dir (film->dcp_name ()));
89 check_subtitle_file (shared_ptr<Film> film, boost::filesystem::path ref)
91 /* Find the subtitle file and check it */
93 ignore.push_back ("SubtitleID");
94 check_xml (subtitle_file(film), ref, ignore);
97 /** Make another DCP with a longer .srt file */
98 BOOST_AUTO_TEST_CASE (srt_subtitle_test3)
100 shared_ptr<Film> film = new_test_film ("srt_subtitle_test3");
102 film->set_container (Ratio::from_id ("185"));
103 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
104 film->set_name ("frobozz");
105 film->set_interop (true);
106 film->set_audio_channels (6);
107 shared_ptr<StringTextFileContent> content (new StringTextFileContent(private_data / "Ankoemmling_short.srt"));
108 film->examine_and_add_content (content);
109 BOOST_REQUIRE (!wait_for_jobs());
111 content->only_text()->set_use (true);
112 content->only_text()->set_burn (false);
115 BOOST_REQUIRE (!wait_for_jobs());
117 check_subtitle_file (film, private_data / "Ankoemmling_short.xml");
120 /** Build a small DCP with no picture and a single subtitle overlaid onto it */
121 BOOST_AUTO_TEST_CASE (srt_subtitle_test4)
123 shared_ptr<Film> film = new_test_film ("srt_subtitle_test4");
124 film->set_container (Ratio::from_id ("185"));
125 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
126 film->set_name ("frobozz");
127 film->set_interop (false);
128 shared_ptr<StringTextFileContent> content (new StringTextFileContent("test/data/subrip2.srt"));
129 content->only_text()->set_use (true);
130 content->only_text()->set_burn (false);
131 film->examine_and_add_content (content);
132 BOOST_REQUIRE (!wait_for_jobs());
134 BOOST_REQUIRE (!wait_for_jobs());
136 /* Should be blank video with MXF subtitles */
137 check_dcp ("test/data/xml_subtitle_test", film->dir (film->dcp_name ()));
140 /** Check the subtitle XML when there are two subtitle files in the project */
141 BOOST_AUTO_TEST_CASE (srt_subtitle_test5)
143 shared_ptr<Film> film = new_test_film ("srt_subtitle_test5");
144 film->set_container (Ratio::from_id ("185"));
145 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
146 film->set_name ("frobozz");
147 film->set_interop (true);
148 film->set_sequence (false);
149 shared_ptr<StringTextFileContent> content (new StringTextFileContent("test/data/subrip2.srt"));
150 content->only_text()->set_use (true);
151 content->only_text()->set_burn (false);
152 film->examine_and_add_content (content);
153 shared_ptr<StringTextFileContent> content2 (new StringTextFileContent("test/data/subrip2.srt"));
154 content2->only_text()->set_use (true);
155 content2->only_text()->set_burn (false);
156 film->examine_and_add_content (content2);
157 BOOST_REQUIRE (!wait_for_jobs());
158 content->set_position (film, DCPTime());
159 content2->set_position (film, DCPTime());
161 BOOST_REQUIRE (!wait_for_jobs());
162 film->write_metadata ();
164 check_dcp ("test/data/xml_subtitle_test2", film->dir (film->dcp_name ()));
167 BOOST_AUTO_TEST_CASE (srt_subtitle_test6)
169 shared_ptr<Film> film = new_test_film2 ("srt_subtitle_test6");
170 film->set_interop (false);
171 shared_ptr<StringTextFileContent> content (new StringTextFileContent("test/data/frames.srt"));
172 content->only_text()->set_use (true);
173 content->only_text()->set_burn (false);
174 film->examine_and_add_content (content);
175 BOOST_REQUIRE (!wait_for_jobs ());
177 BOOST_REQUIRE (!wait_for_jobs ());
178 film->write_metadata ();
180 check_dcp ("test/data/srt_subtitle_test6", film->dir(film->dcp_name()));
184 /* XXX: this is disabled; there is some difference in font rendering
185 between the test machine and others.
188 /** Test rendering of a SubRip subtitle */
189 BOOST_AUTO_TEST_CASE (srt_subtitle_test4)
191 shared_ptr<Film> film = new_test_film ("subrip_render_test");
192 shared_ptr<StringTextFile> content (new StringTextFile("test/data/subrip.srt"));
193 content->examine (shared_ptr<Job> (), true);
194 BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds ((3 * 60) + 56.471));
196 shared_ptr<SubRipDecoder> decoder (new SubRipDecoder (content));
197 list<ContentStringText> cts = decoder->get_plain_texts (
199 ContentTime::from_seconds (109), ContentTime::from_seconds (110)
202 BOOST_CHECK_EQUAL (cts.size(), 1);
204 PositionImage image = render_text (cts.front().subs, dcp::Size (1998, 1080));
205 write_image (image.image, "build/test/subrip_render_test.png");
206 check_file ("build/test/subrip_render_test.png", "test/data/subrip_render_test.png");