2 Copyright (C) 2017-2019 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 #include "lib/ffmpeg_encoder.h"
23 #include "lib/ffmpeg_content.h"
24 #include "lib/image_content.h"
25 #include "lib/video_content.h"
26 #include "lib/audio_content.h"
27 #include "lib/string_text_file_content.h"
28 #include "lib/ratio.h"
29 #include "lib/transcode_job.h"
30 #include "lib/dcp_content.h"
31 #include "lib/text_content.h"
32 #include "lib/compose.hpp"
33 #include "lib/content_factory.h"
35 #include <boost/test/unit_test.hpp>
38 using boost::shared_ptr;
39 using boost::optional;
40 using namespace dcpomatic;
43 ffmpeg_content_test (int number, boost::filesystem::path content, ExportFormat format)
45 string name = "ffmpeg_encoder_";
48 case EXPORT_FORMAT_H264_AAC:
52 case EXPORT_FORMAT_PRORES:
56 case EXPORT_FORMAT_H264_PCM:
57 case EXPORT_FORMAT_SUBTITLES_DCP:
58 BOOST_REQUIRE (false);
61 name = String::compose("%1_test%2", name, number);
63 shared_ptr<Film> film = new_test_film (name);
64 film->set_name (name);
65 shared_ptr<FFmpegContent> c (new FFmpegContent(content));
66 film->set_container (Ratio::from_id ("185"));
67 film->set_audio_channels (6);
69 film->examine_and_add_content (c);
70 BOOST_REQUIRE (!wait_for_jobs ());
72 film->write_metadata ();
73 shared_ptr<Job> job (new TranscodeJob (film));
74 FFmpegEncoder encoder (film, job, String::compose("build/test/%1.%2", name, extension), format, false, false, 23
75 #ifdef DCPOMATIC_VARIANT_SWAROOP
76 , optional<dcp::Key>(), optional<string>()
82 /** Red / green / blue MP4 -> Prores */
83 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test1)
85 ffmpeg_content_test (1, "test/data/test.mp4", EXPORT_FORMAT_PRORES);
88 /** Dolby Aurora trailer VOB -> Prores */
89 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test2)
91 ffmpeg_content_test (2, TestPaths::private_data / "dolby_aurora.vob", EXPORT_FORMAT_PRORES);
94 /** Sintel trailer -> Prores */
95 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test3)
97 ffmpeg_content_test (3, TestPaths::private_data / "Sintel_Trailer1.480p.DivX_Plus_HD.mkv", EXPORT_FORMAT_PRORES);
100 /** Big Buck Bunny trailer -> Prores */
101 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test4)
103 ffmpeg_content_test (4, TestPaths::private_data / "big_buck_bunny_trailer_480p.mov", EXPORT_FORMAT_PRORES);
106 /** Still image -> Prores */
107 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test5)
109 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test5");
110 film->set_name ("ffmpeg_encoder_prores_test5");
111 shared_ptr<ImageContent> c (new ImageContent(TestPaths::private_data / "bbc405.png"));
112 film->set_container (Ratio::from_id ("185"));
113 film->set_audio_channels (6);
115 film->examine_and_add_content (c);
116 BOOST_REQUIRE (!wait_for_jobs ());
118 c->video->set_length (240);
120 film->write_metadata ();
121 shared_ptr<Job> job (new TranscodeJob (film));
122 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test5.mov", EXPORT_FORMAT_PRORES, false, false, 23
123 #ifdef DCPOMATIC_VARIANT_SWAROOP
124 , optional<dcp::Key>(), optional<string>()
130 /** Subs -> Prores */
131 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test6)
133 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test6");
134 film->set_name ("ffmpeg_encoder_prores_test6");
135 film->set_container (Ratio::from_id ("185"));
136 film->set_audio_channels (6);
138 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip2.srt"));
139 film->examine_and_add_content (s);
140 BOOST_REQUIRE (!wait_for_jobs ());
141 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
142 s->only_text()->set_effect (dcp::SHADOW);
143 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
144 film->write_metadata();
146 shared_ptr<Job> job (new TranscodeJob (film));
147 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test6.mov", EXPORT_FORMAT_PRORES, false, false, 23
148 #ifdef DCPOMATIC_VARIANT_SWAROOP
149 , optional<dcp::Key>(), optional<string>()
155 /** Video + subs -> Prores */
156 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test7)
158 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test7");
159 film->set_name ("ffmpeg_encoder_prores_test7");
160 film->set_container (Ratio::from_id ("185"));
161 film->set_audio_channels (6);
163 shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
164 film->examine_and_add_content (c);
165 BOOST_REQUIRE (!wait_for_jobs ());
167 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip.srt"));
168 film->examine_and_add_content (s);
169 BOOST_REQUIRE (!wait_for_jobs ());
170 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
171 s->only_text()->set_effect (dcp::SHADOW);
172 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
174 shared_ptr<Job> job (new TranscodeJob (film));
175 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test7.mov", EXPORT_FORMAT_PRORES, false, false, 23
176 #ifdef DCPOMATIC_VARIANT_SWAROOP
177 , optional<dcp::Key>(), optional<string>()
183 /** Red / green / blue MP4 -> H264 */
184 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test1)
186 ffmpeg_content_test(1, "test/data/test.mp4", EXPORT_FORMAT_H264_AAC);
189 /** Just subtitles -> H264 */
190 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test2)
192 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_h264_test2");
193 film->set_name ("ffmpeg_encoder_h264_test2");
194 film->set_container (Ratio::from_id ("185"));
195 film->set_audio_channels (6);
197 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip2.srt"));
198 film->examine_and_add_content (s);
199 BOOST_REQUIRE (!wait_for_jobs ());
200 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
201 s->only_text()->set_effect (dcp::SHADOW);
202 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
203 film->write_metadata();
205 shared_ptr<Job> job (new TranscodeJob (film));
206 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test2.mp4", EXPORT_FORMAT_H264_AAC, false, false, 23
207 #ifdef DCPOMATIC_VARIANT_SWAROOP
208 , optional<dcp::Key>(), optional<string>()
214 /** Video + subs -> H264 */
215 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test3)
217 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_h264_test3");
218 film->set_name ("ffmpeg_encoder_h264_test3");
219 film->set_container (Ratio::from_id ("185"));
220 film->set_audio_channels (6);
222 shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
223 film->examine_and_add_content (c);
224 BOOST_REQUIRE (!wait_for_jobs ());
226 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip.srt"));
227 film->examine_and_add_content (s);
228 BOOST_REQUIRE (!wait_for_jobs ());
229 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
230 s->only_text()->set_effect (dcp::SHADOW);
231 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
232 film->write_metadata();
234 shared_ptr<Job> job (new TranscodeJob (film));
235 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test3.mp4", EXPORT_FORMAT_H264_AAC, false, false, 23
236 #ifdef DCPOMATIC_VARIANT_SWAROOP
237 , optional<dcp::Key>(), optional<string>()
243 /** Scope-in-flat DCP -> H264 */
244 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test4)
246 shared_ptr<Film> film = new_test_film2("ffmpeg_encoder_h264_test4");
247 film->examine_and_add_content(shared_ptr<DCPContent>(new DCPContent("test/data/scope_dcp")));
248 BOOST_REQUIRE(!wait_for_jobs());
250 film->set_container(Ratio::from_id("185"));
252 shared_ptr<Job> job(new TranscodeJob(film));
253 FFmpegEncoder encoder(film, job, "build/test/ffmpeg_encoder_h264_test4.mp4", EXPORT_FORMAT_H264_AAC, false, false, 23
254 #ifdef DCPOMATIC_VARIANT_SWAROOP
255 , optional<dcp::Key>(), optional<string>()
261 /** Test mixdown from 5.1 to stereo */
262 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test5)
264 shared_ptr<Film> film = new_test_film ("ffmpeg_transcoder_h264_test5");
265 film->set_name ("ffmpeg_transcoder_h264_test5");
266 film->set_container (Ratio::from_id ("185"));
267 film->set_audio_channels (6);
269 shared_ptr<FFmpegContent> L (new FFmpegContent("test/data/L.wav"));
270 film->examine_and_add_content (L);
271 shared_ptr<FFmpegContent> R (new FFmpegContent("test/data/R.wav"));
272 film->examine_and_add_content (R);
273 shared_ptr<FFmpegContent> C (new FFmpegContent("test/data/C.wav"));
274 film->examine_and_add_content (C);
275 shared_ptr<FFmpegContent> Ls (new FFmpegContent("test/data/Ls.wav"));
276 film->examine_and_add_content (Ls);
277 shared_ptr<FFmpegContent> Rs (new FFmpegContent("test/data/Rs.wav"));
278 film->examine_and_add_content (Rs);
279 shared_ptr<FFmpegContent> Lfe (new FFmpegContent("test/data/Lfe.wav"));
280 film->examine_and_add_content (Lfe);
281 BOOST_REQUIRE (!wait_for_jobs ());
283 AudioMapping map (1, MAX_DCP_AUDIO_CHANNELS);
285 L->set_position (film, DCPTime::from_seconds(0));
288 L->audio->set_mapping (map);
289 R->set_position (film, DCPTime::from_seconds(1));
292 R->audio->set_mapping (map);
293 C->set_position (film, DCPTime::from_seconds(2));
296 C->audio->set_mapping (map);
297 Lfe->set_position (film, DCPTime::from_seconds(3));
300 Lfe->audio->set_mapping (map);
301 Ls->set_position (film, DCPTime::from_seconds(4));
304 Ls->audio->set_mapping (map);
305 Rs->set_position (film, DCPTime::from_seconds(5));
308 Rs->audio->set_mapping (map);
310 shared_ptr<Job> job (new TranscodeJob (film));
311 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test5.mp4", EXPORT_FORMAT_H264_AAC, true, false, 23
312 #ifdef DCPOMATIC_VARIANT_SWAROOP
313 , optional<dcp::Key>(), optional<string>()
318 check_ffmpeg ("build/test/ffmpeg_encoder_h264_test5.mp4", "test/data/ffmpeg_encoder_h264_test5.mp4", 1);
321 /** Test export of a VF */
322 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test6)
324 shared_ptr<Film> film = new_test_film2 ("ffmpeg_encoder_h264_test6_ov");
325 film->examine_and_add_content (shared_ptr<ImageContent>(new ImageContent(TestPaths::private_data / "bbc405.png")));
326 BOOST_REQUIRE (!wait_for_jobs());
328 BOOST_REQUIRE (!wait_for_jobs());
330 shared_ptr<Film> film2 = new_test_film2 ("ffmpeg_encoder_h264_test6_vf");
331 shared_ptr<DCPContent> ov (new DCPContent("build/test/ffmpeg_encoder_h264_test6_ov/" + film->dcp_name(false)));
332 film2->examine_and_add_content (ov);
333 BOOST_REQUIRE (!wait_for_jobs());
334 ov->set_reference_video (true);
335 shared_ptr<Content> subs = content_factory("test/data/subrip.srt").front();
336 film2->examine_and_add_content (subs);
337 BOOST_REQUIRE (!wait_for_jobs());
338 BOOST_FOREACH (shared_ptr<TextContent> i, subs->text) {
342 shared_ptr<Job> job (new TranscodeJob (film2));
343 FFmpegEncoder encoder (film2, job, "build/test/ffmpeg_encoder_h264_test6_vf.mp4", EXPORT_FORMAT_H264_AAC, true, false, 23
344 #ifdef DCPOMATIC_VARIANT_SWAROOP
345 , optional<dcp::Key>(), optional<string>()
351 /** Test export of a 3D DCP in a 2D project */
352 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test7)
354 shared_ptr<Film> film = new_test_film2 ("ffmpeg_encoder_h264_test7_data");
355 shared_ptr<Content> L (shared_ptr<ImageContent>(new ImageContent(TestPaths::private_data / "bbc405.png")));
356 film->examine_and_add_content (L);
357 shared_ptr<Content> R (shared_ptr<ImageContent>(new ImageContent(TestPaths::private_data / "bbc405.png")));
358 film->examine_and_add_content (R);
359 BOOST_REQUIRE (!wait_for_jobs());
360 L->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT);
361 L->set_position (film, DCPTime());
362 R->video->set_frame_type (VIDEO_FRAME_TYPE_3D_RIGHT);
363 R->set_position (film, DCPTime());
364 film->set_three_d (true);
366 BOOST_REQUIRE (!wait_for_jobs());
368 shared_ptr<Film> film2 = new_test_film2 ("ffmpeg_encoder_h264_test7_export");
369 shared_ptr<Content> dcp (new DCPContent(film->dir(film->dcp_name())));
370 film2->examine_and_add_content (dcp);
371 BOOST_REQUIRE (!wait_for_jobs());
373 shared_ptr<Job> job (new TranscodeJob (film2));
374 FFmpegEncoder encoder (film2, job, "build/test/ffmpeg_encoder_h264_test7.mp4", EXPORT_FORMAT_H264_AAC, true, false, 23
375 #ifdef DCPOMATIC_VARIANT_SWAROOP
376 , optional<dcp::Key>(), optional<string>()
383 /** Stereo project with mixdown-to-stereo set */
384 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test8)
386 shared_ptr<Film> film = new_test_film2("ffmpeg_encoder_h264_test4");
387 film->examine_and_add_content(shared_ptr<DCPContent>(new DCPContent("test/data/scope_dcp")));
388 BOOST_REQUIRE(!wait_for_jobs());
389 film->set_audio_channels (2);
391 shared_ptr<Job> job(new TranscodeJob(film));
392 FFmpegEncoder encoder(film, job, "build/test/ffmpeg_encoder_h264_test8.mp4", EXPORT_FORMAT_H264_AAC, true, false, 23
393 #ifdef DCPOMATIC_VARIANT_SWAROOP
394 , optional<dcp::Key>(), optional<string>()
401 /** 7.1/HI/VI (i.e. 12-channel) project */
402 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test9)
404 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test9");
405 film->set_name ("ffmpeg_encoder_prores_test9");
406 shared_ptr<ImageContent> c (new ImageContent(TestPaths::private_data / "bbc405.png"));
407 film->set_container (Ratio::from_id ("185"));
408 film->set_audio_channels (12);
410 film->examine_and_add_content (c);
411 BOOST_REQUIRE (!wait_for_jobs ());
413 c->video->set_length (240);
415 film->write_metadata ();
416 shared_ptr<Job> job (new TranscodeJob (film));
417 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test9.mov", EXPORT_FORMAT_H264_AAC, false, false, 23
418 #ifdef DCPOMATIC_VARIANT_SWAROOP
419 , optional<dcp::Key>(), optional<string>()