1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
/*
Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
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 <http://www.gnu.org/licenses/>.
*/
/** @file test/burnt_subtitle_test.cc
* @brief Test the burning of subtitles into the DCP.
* @ingroup feature
*/
#include "lib/config.h"
#include "lib/content_factory.h"
#include "lib/dcp_content.h"
#include "lib/dcp_content_type.h"
#include "lib/film.h"
#include "lib/ffmpeg_film_encoder.h"
#include "lib/log_entry.h"
#include "lib/ratio.h"
#include "lib/text_content.h"
#include "test.h"
#include <dcp/dcp.h>
#include <dcp/cpl.h>
#include <dcp/reel.h>
#include <dcp/j2k_transcode.h>
#include <dcp/mono_j2k_picture_asset.h>
#include <dcp/mono_j2k_picture_asset_reader.h>
#include <dcp/mono_j2k_picture_frame.h>
#include <dcp/openjpeg_image.h>
#include <dcp/reel_picture_asset.h>
#include <dcp/reel_mono_picture_asset.h>
#include <pango/pango-utils.h>
#include <boost/test/unit_test.hpp>
using std::dynamic_pointer_cast;
using std::make_shared;
using std::map;
using std::string;
using namespace dcpomatic;
/* Some of these tests produce slightly different outputs on different platforms / OS versions.
* I'm not sure of the cause of these differences, but as it happens the tests on Ubuntu 24.04
* produce the same results as on macOS, while the Ubuntu 22.04 results are slightly different.
* Hence the hacks in this file to check for DCPOMATIC_OSX or the Ubuntu 24.04 version of Pango
* (22.04 uses Pango 1.52.1, 24.04 is 1.50.6, macOS is 1.51.0). Maybe it has nothing to do
* with Pango, of course...
*/
/** Build a small DCP with no picture and a single subtitle overlaid onto it from a SubRip file */
BOOST_AUTO_TEST_CASE (burnt_subtitle_test_subrip)
{
auto content = content_factory("test/data/subrip2.srt")[0];
auto film = new_test_film("burnt_subtitle_test_subrip", { content });
film->set_dcp_content_type(DCPContentType::from_isdcf_name("TLR"));
content->text[0]->set_use(true);
content->text[0]->set_burn(true);
make_and_verify_dcp(
film,
{ dcp::VerificationNote::Code::MISSING_CPL_METADATA }
);
#if defined(DCPOMATIC_WINDOWS)
check_dcp("test/data/windows/burnt_subtitle_test_subrip", film);
#elif defined(DCPOMATIC_OSX) || PANGO_VERSION_CHECK(1, 52, 1)
check_dcp("test/data/mac/burnt_subtitle_test_subrip", film);
#else
check_dcp("test/data/burnt_subtitle_test_subrip", film);
#endif
}
/** Build a small DCP with no picture and a single subtitle overlaid onto it from a DCP XML file */
BOOST_AUTO_TEST_CASE (burnt_subtitle_test_dcp)
{
auto content = content_factory("test/data/dcp_sub.xml")[0];
auto film = new_test_film("burnt_subtitle_test_dcp", { content });
film->set_dcp_content_type(DCPContentType::from_isdcf_name("TLR"));
film->set_name("frobozz");
content->text[0]->set_use(true);
make_and_verify_dcp(
film,
{
dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
dcp::VerificationNote::Code::MISSING_CPL_METADATA
});
check_dcp("test/data/burnt_subtitle_test_dcp", film);
}
/** Burn some subtitles into an existing DCP to check the colour conversion */
BOOST_AUTO_TEST_CASE (burnt_subtitle_test_onto_dcp)
{
auto film = new_test_film("burnt_subtitle_test_onto_dcp", { content_factory("test/data/flat_black.png")[0] });
film->set_dcp_content_type(DCPContentType::from_isdcf_name("TLR"));
make_and_verify_dcp (film);
Config::instance()->set_log_types (Config::instance()->log_types() | LogEntry::TYPE_DEBUG_ENCODE);
auto background_dcp = make_shared<DCPContent>(film->dir(film->dcp_name()));
auto sub = content_factory("test/data/subrip2.srt")[0];
auto film2 = new_test_film("burnt_subtitle_test_onto_dcp2", { background_dcp, sub });
film2->set_dcp_content_type(DCPContentType::from_isdcf_name("TLR"));
film2->set_name("frobozz");
sub->text[0]->set_burn(true);
sub->text[0]->set_effect(dcp::Effect::BORDER);
make_and_verify_dcp (film2);
BOOST_CHECK (background_dcp->position() == DCPTime());
BOOST_CHECK (sub->position() == DCPTime());
dcp::DCP dcp (film2->dir (film2->dcp_name ()));
dcp.read ();
BOOST_REQUIRE_EQUAL(dcp.cpls().size(), 1U);
BOOST_REQUIRE_EQUAL(dcp.cpls().front()->reels().size(), 1U);
BOOST_REQUIRE (dcp.cpls().front()->reels().front()->main_picture());
BOOST_REQUIRE (dcp.cpls().front()->reels().front()->main_picture()->asset());
auto pic = dynamic_pointer_cast<dcp::ReelMonoPictureAsset> (
dcp.cpls().front()->reels().front()->main_picture()
)->mono_j2k_asset();
BOOST_REQUIRE (pic);
auto frame = pic->start_read()->get_frame(12);
auto xyz = frame->xyz_image ();
BOOST_CHECK_EQUAL (xyz->size().width, 1998);
BOOST_CHECK_EQUAL (xyz->size().height, 1080);
#if defined(DCPOMATIC_WINDOWS)
check_dcp("test/data/windows/burnt_subtitle_test_onto_dcp2", film2);
#elif defined(DCPOMATIC_OSX) || PANGO_VERSION_CHECK(1, 52, 1)
check_dcp("test/data/mac/burnt_subtitle_test_onto_dcp2", film2);
#else
check_dcp("test/data/burnt_subtitle_test_onto_dcp2", film2);
#endif
}
/** Check positioning of some burnt subtitles from XML files */
BOOST_AUTO_TEST_CASE(burnt_subtitle_test_position)
{
auto check = [](string alignment)
{
auto const name = String::compose("burnt_subtitle_test_position_%1", alignment);
auto subs = content_factory(String::compose("test/data/burn_%1.xml", alignment));
auto film = new_test_film(name, subs);
subs[0]->text[0]->set_use(true);
subs[0]->text[0]->set_burn(true);
make_and_verify_dcp(
film,
{
dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
dcp::VerificationNote::Code::MISSING_CPL_METADATA
});
#if defined(DCPOMATIC_WINDOWS)
check_dcp(String::compose("test/data/windows/%1", name), film);
#elif defined(DCPOMATIC_OSX) || PANGO_VERSION_CHECK(1, 52, 1)
check_dcp(String::compose("test/data/mac/%1", name), film);
#else
check_dcp(String::compose("test/data/%1", name), film);
#endif
};
/* Should have a baseline 216 pixels from the top (0.2 * 1080) */
check("top");
/* Should have a baseline 756 pixels from the top ((0.5 + 0.2) * 1080) */
check("center");
/* Should have a baseline 864 pixels from the top ((1 - 0.2) * 1080) */
check("bottom");
}
/* Bug #2743 */
BOOST_AUTO_TEST_CASE(burn_empty_subtitle_test)
{
Cleanup cl;
auto content = content_factory("test/data/empty_sub.xml")[0];
auto film = new_test_film("burnt_empty_subtitle_test", { content });
content->text[0]->set_use(true);
auto job = make_shared<TranscodeJob>(film, TranscodeJob::ChangedBehaviour::IGNORE);
auto file = boost::filesystem::path("build") / "test" / "burnt_empty_subtitle_test.mov";
cl.add(file);
FFmpegFilmEncoder encoder(film, job, file, ExportFormat::PRORES_4444, false, false, false, 23);
encoder.go();
cl.run();
}
|