2 Copyright (C) 2017-2021 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/>.
22 #include "lib/ffmpeg_encoder.h"
24 #include "lib/ffmpeg_content.h"
25 #include "lib/image_content.h"
26 #include "lib/video_content.h"
27 #include "lib/audio_content.h"
28 #include "lib/string_text_file_content.h"
29 #include "lib/ratio.h"
30 #include "lib/transcode_job.h"
31 #include "lib/dcp_content.h"
32 #include "lib/text_content.h"
33 #include "lib/compose.hpp"
34 #include "lib/content_factory.h"
36 #include <boost/test/unit_test.hpp>
40 using std::shared_ptr;
41 using std::make_shared;
42 using boost::optional;
43 using namespace dcpomatic;
47 ffmpeg_content_test (int number, boost::filesystem::path content, ExportFormat format)
51 string name = "ffmpeg_encoder_";
54 case ExportFormat::H264_AAC:
58 case ExportFormat::PRORES:
62 case ExportFormat::H264_PCM:
63 case ExportFormat::SUBTITLES_DCP:
64 BOOST_REQUIRE (false);
67 name = String::compose("%1_test%2", name, number);
69 auto c = make_shared<FFmpegContent>(content);
70 shared_ptr<Film> film = new_test_film2 (name, {c}, &cl);
71 film->set_name (name);
72 film->set_audio_channels (6);
74 film->write_metadata ();
75 auto job = make_shared<TranscodeJob>(film);
76 auto file = boost::filesystem::path("build") / "test" / String::compose("%1.%2", name, extension);
78 FFmpegEncoder encoder (film, job, file, format, false, false, false, 23);
85 /** Red / green / blue MP4 -> Prores */
86 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test1)
88 ffmpeg_content_test (1, "test/data/test.mp4", ExportFormat::PRORES);
92 /** Dolby Aurora trailer VOB -> Prores */
93 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test2)
95 ffmpeg_content_test (2, TestPaths::private_data() / "dolby_aurora.vob", ExportFormat::PRORES);
99 /** Sintel trailer -> Prores */
100 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test3)
102 ffmpeg_content_test (3, TestPaths::private_data() / "Sintel_Trailer1.480p.DivX_Plus_HD.mkv", ExportFormat::PRORES);
106 /** Big Buck Bunny trailer -> Prores */
107 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test4)
109 ffmpeg_content_test (4, TestPaths::private_data() / "big_buck_bunny_trailer_480p.mov", ExportFormat::PRORES);
113 /** Still image -> Prores */
114 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test5)
116 auto film = new_test_film ("ffmpeg_encoder_prores_test5");
117 film->set_name ("ffmpeg_encoder_prores_test5");
118 auto c = make_shared<ImageContent>(TestPaths::private_data() / "bbc405.png");
119 film->set_container (Ratio::from_id ("185"));
120 film->set_audio_channels (6);
122 film->examine_and_add_content (c);
123 BOOST_REQUIRE (!wait_for_jobs ());
125 c->video->set_length (240);
127 film->write_metadata ();
128 auto job = make_shared<TranscodeJob> (film);
129 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test5.mov", ExportFormat::PRORES, false, false, false, 23);
134 /** Subs -> Prores */
135 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test6)
137 auto film = new_test_film ("ffmpeg_encoder_prores_test6");
138 film->set_name ("ffmpeg_encoder_prores_test6");
139 film->set_container (Ratio::from_id ("185"));
140 film->set_audio_channels (6);
142 auto s = make_shared<StringTextFileContent>("test/data/subrip2.srt");
143 film->examine_and_add_content (s);
144 BOOST_REQUIRE (!wait_for_jobs ());
145 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
146 s->only_text()->set_effect (dcp::Effect::SHADOW);
147 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
148 film->write_metadata();
150 auto job = make_shared<TranscodeJob> (film);
151 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test6.mov", ExportFormat::PRORES, false, false, false, 23);
156 /** Video + subs -> Prores */
157 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test7)
159 auto film = new_test_film ("ffmpeg_encoder_prores_test7");
160 film->set_name ("ffmpeg_encoder_prores_test7");
161 film->set_container (Ratio::from_id ("185"));
162 film->set_audio_channels (6);
164 auto c = make_shared<FFmpegContent>("test/data/test.mp4");
165 film->examine_and_add_content (c);
166 BOOST_REQUIRE (!wait_for_jobs ());
168 auto s = make_shared<StringTextFileContent>("test/data/subrip.srt");
169 film->examine_and_add_content (s);
170 BOOST_REQUIRE (!wait_for_jobs ());
171 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
172 s->only_text()->set_effect (dcp::Effect::SHADOW);
173 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
175 auto job = make_shared<TranscodeJob> (film);
176 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test7.mov", ExportFormat::PRORES, false, false, false, 23);
181 /** Red / green / blue MP4 -> H264 */
182 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test1)
184 ffmpeg_content_test(1, "test/data/test.mp4", ExportFormat::H264_AAC);
188 /** Just subtitles -> H264 */
189 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test2)
191 auto film = new_test_film ("ffmpeg_encoder_h264_test2");
192 film->set_name ("ffmpeg_encoder_h264_test2");
193 film->set_container (Ratio::from_id ("185"));
194 film->set_audio_channels (6);
196 auto s = make_shared<StringTextFileContent>("test/data/subrip2.srt");
197 film->examine_and_add_content (s);
198 BOOST_REQUIRE (!wait_for_jobs ());
199 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
200 s->only_text()->set_effect (dcp::Effect::SHADOW);
201 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
202 film->write_metadata();
204 auto job = make_shared<TranscodeJob> (film);
205 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test2.mp4", ExportFormat::H264_AAC, false, false, false, 23);
210 /** Video + subs -> H264 */
211 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test3)
213 auto film = new_test_film ("ffmpeg_encoder_h264_test3");
214 film->set_name ("ffmpeg_encoder_h264_test3");
215 film->set_container (Ratio::from_id ("185"));
216 film->set_audio_channels (6);
218 auto c = make_shared<FFmpegContent>("test/data/test.mp4");
219 film->examine_and_add_content (c);
220 BOOST_REQUIRE (!wait_for_jobs());
222 auto s = make_shared<StringTextFileContent>("test/data/subrip.srt");
223 film->examine_and_add_content (s);
224 BOOST_REQUIRE (!wait_for_jobs ());
225 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
226 s->only_text()->set_effect (dcp::Effect::SHADOW);
227 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
228 film->write_metadata();
230 auto job = make_shared<TranscodeJob> (film);
231 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test3.mp4", ExportFormat::H264_AAC, false, false, false, 23);
236 /** Scope-in-flat DCP -> H264 */
237 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test4)
239 auto film = new_test_film2("ffmpeg_encoder_h264_test4", {make_shared<DCPContent>("test/data/scope_dcp")});
240 BOOST_REQUIRE(!wait_for_jobs());
242 film->set_container(Ratio::from_id("185"));
244 auto job = make_shared<TranscodeJob>(film);
245 FFmpegEncoder encoder(film, job, "build/test/ffmpeg_encoder_h264_test4.mp4", ExportFormat::H264_AAC, false, false, false, 23);
250 /** Test mixdown from 5.1 to stereo */
251 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test5)
253 auto film = new_test_film ("ffmpeg_transcoder_h264_test5");
254 film->set_name ("ffmpeg_transcoder_h264_test5");
255 film->set_container (Ratio::from_id ("185"));
256 film->set_audio_channels (6);
258 auto L = make_shared<FFmpegContent>("test/data/L.wav");
259 film->examine_and_add_content (L);
260 auto R = make_shared<FFmpegContent>("test/data/R.wav");
261 film->examine_and_add_content (R);
262 auto C = make_shared<FFmpegContent>("test/data/C.wav");
263 film->examine_and_add_content (C);
264 auto Ls = make_shared<FFmpegContent>("test/data/Ls.wav");
265 film->examine_and_add_content (Ls);
266 auto Rs = make_shared<FFmpegContent>("test/data/Rs.wav");
267 film->examine_and_add_content (Rs);
268 auto Lfe = make_shared<FFmpegContent>("test/data/Lfe.wav");
269 film->examine_and_add_content (Lfe);
270 BOOST_REQUIRE (!wait_for_jobs ());
272 AudioMapping map (1, MAX_DCP_AUDIO_CHANNELS);
274 L->set_position (film, DCPTime::from_seconds(0));
277 L->audio->set_mapping (map);
278 R->set_position (film, DCPTime::from_seconds(1));
281 R->audio->set_mapping (map);
282 C->set_position (film, DCPTime::from_seconds(2));
285 C->audio->set_mapping (map);
286 Lfe->set_position (film, DCPTime::from_seconds(3));
289 Lfe->audio->set_mapping (map);
290 Ls->set_position (film, DCPTime::from_seconds(4));
293 Ls->audio->set_mapping (map);
294 Rs->set_position (film, DCPTime::from_seconds(5));
297 Rs->audio->set_mapping (map);
299 auto job = make_shared<TranscodeJob> (film);
300 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test5.mp4", ExportFormat::H264_AAC, true, false, false, 23);
303 check_ffmpeg ("build/test/ffmpeg_encoder_h264_test5.mp4", "test/data/ffmpeg_encoder_h264_test5.mp4", 1);
307 /** Test export of a VF */
308 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test6)
310 auto film = new_test_film2 ("ffmpeg_encoder_h264_test6_ov");
311 film->examine_and_add_content (make_shared<ImageContent>(TestPaths::private_data() / "bbc405.png"));
312 BOOST_REQUIRE (!wait_for_jobs());
313 make_and_verify_dcp (film);
315 auto film2 = new_test_film2 ("ffmpeg_encoder_h264_test6_vf");
316 auto ov = make_shared<DCPContent>("build/test/ffmpeg_encoder_h264_test6_ov/" + film->dcp_name(false));
317 film2->examine_and_add_content (ov);
318 BOOST_REQUIRE (!wait_for_jobs());
319 ov->set_reference_video (true);
320 auto subs = content_factory("test/data/subrip.srt").front();
321 film2->examine_and_add_content (subs);
322 BOOST_REQUIRE (!wait_for_jobs());
323 for (auto i: subs->text) {
327 auto job = make_shared<TranscodeJob> (film2);
328 FFmpegEncoder encoder (film2, job, "build/test/ffmpeg_encoder_h264_test6_vf.mp4", ExportFormat::H264_AAC, true, false, false, 23);
333 /** Test export of a 3D DCP in a 2D project */
334 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_3d_dcp_to_h264)
336 auto dcp = make_shared<DCPContent>(TestPaths::private_data() / "XMenDarkPhoenix_TLR-12-3D_F_DE-XX_DE_51_2K_TCFG_20190227_TM_IOP-3D_OV");
337 auto film2 = new_test_film2 ("ffmpeg_encoder_3d_dcp_to_h264_export", {dcp});
339 auto job = make_shared<TranscodeJob> (film2);
340 FFmpegEncoder encoder (film2, job, "build/test/ffmpeg_encoder_3d_dcp_to_h264.mp4", ExportFormat::H264_AAC, true, false, false, 23);
345 /** Test export of a 3D DCP in a 2D project */
346 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test7)
348 auto L = make_shared<ImageContent>(TestPaths::private_data() / "bbc405.png");
349 auto R = make_shared<ImageContent>(TestPaths::private_data() / "bbc405.png");
350 auto film = new_test_film2 ("ffmpeg_encoder_h264_test7_data", {L, R});
351 L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
352 L->set_position (film, DCPTime());
353 R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
354 R->set_position (film, DCPTime());
355 film->set_three_d (true);
356 make_and_verify_dcp (film);
358 auto dcp = make_shared<DCPContent>(film->dir(film->dcp_name()));
359 auto film2 = new_test_film2 ("ffmpeg_encoder_h264_test7_export", {dcp});
361 auto job = make_shared<TranscodeJob> (film2);
362 FFmpegEncoder encoder (film2, job, "build/test/ffmpeg_encoder_h264_test7.mp4", ExportFormat::H264_AAC, true, false, false, 23);
367 /** Stereo project with mixdown-to-stereo set */
368 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test8)
370 shared_ptr<Film> film = new_test_film2("ffmpeg_encoder_h264_test4");
371 film->examine_and_add_content(shared_ptr<DCPContent>(new DCPContent("test/data/scope_dcp")));
372 BOOST_REQUIRE(!wait_for_jobs());
373 film->set_audio_channels (2);
375 shared_ptr<Job> job(new TranscodeJob(film));
376 FFmpegEncoder encoder(film, job, "build/test/ffmpeg_encoder_h264_test8.mp4", ExportFormat::H264_AAC, true, false, false, 23);
381 /** 7.1/HI/VI (i.e. 12-channel) project */
382 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test9)
384 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test9");
385 film->set_name ("ffmpeg_encoder_prores_test9");
386 shared_ptr<ImageContent> c (new ImageContent(TestPaths::private_data() / "bbc405.png"));
387 film->set_container (Ratio::from_id ("185"));
388 film->set_audio_channels (12);
390 film->examine_and_add_content (c);
391 BOOST_REQUIRE (!wait_for_jobs ());
393 c->video->set_length (240);
395 film->write_metadata ();
396 shared_ptr<Job> job (new TranscodeJob (film));
397 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test9.mov", ExportFormat::H264_AAC, false, false, false, 23);