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:
58 name = String::compose("%1_test%2", name, number);
60 shared_ptr<Film> film = new_test_film (name);
61 film->set_name (name);
62 shared_ptr<FFmpegContent> c (new FFmpegContent(content));
63 film->set_container (Ratio::from_id ("185"));
64 film->set_audio_channels (6);
66 film->examine_and_add_content (c);
67 BOOST_REQUIRE (!wait_for_jobs ());
69 film->write_metadata ();
70 shared_ptr<Job> job (new TranscodeJob (film));
71 FFmpegEncoder encoder (film, job, String::compose("build/test/%1.%2", name, extension), format, false, false, 23
72 #ifdef DCPOMATIC_VARIANT_SWAROOP
73 , optional<dcp::Key>(), optional<string>()
79 /** Red / green / blue MP4 -> Prores */
80 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test1)
82 ffmpeg_content_test (1, "test/data/test.mp4", EXPORT_FORMAT_PRORES);
85 /** Dolby Aurora trailer VOB -> Prores */
86 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test2)
88 ffmpeg_content_test (2, TestPaths::private_data / "dolby_aurora.vob", EXPORT_FORMAT_PRORES);
91 /** Sintel trailer -> Prores */
92 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test3)
94 ffmpeg_content_test (3, TestPaths::private_data / "Sintel_Trailer1.480p.DivX_Plus_HD.mkv", EXPORT_FORMAT_PRORES);
97 /** Big Buck Bunny trailer -> Prores */
98 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test4)
100 ffmpeg_content_test (4, TestPaths::private_data / "big_buck_bunny_trailer_480p.mov", EXPORT_FORMAT_PRORES);
103 /** Still image -> Prores */
104 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test5)
106 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test5");
107 film->set_name ("ffmpeg_encoder_prores_test5");
108 shared_ptr<ImageContent> c (new ImageContent(TestPaths::private_data / "bbc405.png"));
109 film->set_container (Ratio::from_id ("185"));
110 film->set_audio_channels (6);
112 film->examine_and_add_content (c);
113 BOOST_REQUIRE (!wait_for_jobs ());
115 c->video->set_length (240);
117 film->write_metadata ();
118 shared_ptr<Job> job (new TranscodeJob (film));
119 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test5.mov", EXPORT_FORMAT_PRORES, false, false, 23
120 #ifdef DCPOMATIC_VARIANT_SWAROOP
121 , optional<dcp::Key>(), optional<string>()
127 /** Subs -> Prores */
128 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test6)
130 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test6");
131 film->set_name ("ffmpeg_encoder_prores_test6");
132 film->set_container (Ratio::from_id ("185"));
133 film->set_audio_channels (6);
135 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip2.srt"));
136 film->examine_and_add_content (s);
137 BOOST_REQUIRE (!wait_for_jobs ());
138 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
139 s->only_text()->set_effect (dcp::SHADOW);
140 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
141 film->write_metadata();
143 shared_ptr<Job> job (new TranscodeJob (film));
144 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test6.mov", EXPORT_FORMAT_PRORES, false, false, 23
145 #ifdef DCPOMATIC_VARIANT_SWAROOP
146 , optional<dcp::Key>(), optional<string>()
152 /** Video + subs -> Prores */
153 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test7)
155 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test7");
156 film->set_name ("ffmpeg_encoder_prores_test7");
157 film->set_container (Ratio::from_id ("185"));
158 film->set_audio_channels (6);
160 shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
161 film->examine_and_add_content (c);
162 BOOST_REQUIRE (!wait_for_jobs ());
164 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip.srt"));
165 film->examine_and_add_content (s);
166 BOOST_REQUIRE (!wait_for_jobs ());
167 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
168 s->only_text()->set_effect (dcp::SHADOW);
169 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
171 shared_ptr<Job> job (new TranscodeJob (film));
172 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test7.mov", EXPORT_FORMAT_PRORES, false, false, 23
173 #ifdef DCPOMATIC_VARIANT_SWAROOP
174 , optional<dcp::Key>(), optional<string>()
180 /** Red / green / blue MP4 -> H264 */
181 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test1)
183 ffmpeg_content_test(1, "test/data/test.mp4", EXPORT_FORMAT_H264_AAC);
186 /** Just subtitles -> H264 */
187 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test2)
189 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_h264_test2");
190 film->set_name ("ffmpeg_encoder_h264_test2");
191 film->set_container (Ratio::from_id ("185"));
192 film->set_audio_channels (6);
194 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip2.srt"));
195 film->examine_and_add_content (s);
196 BOOST_REQUIRE (!wait_for_jobs ());
197 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
198 s->only_text()->set_effect (dcp::SHADOW);
199 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
200 film->write_metadata();
202 shared_ptr<Job> job (new TranscodeJob (film));
203 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test2.mp4", EXPORT_FORMAT_H264_AAC, false, false, 23
204 #ifdef DCPOMATIC_VARIANT_SWAROOP
205 , optional<dcp::Key>(), optional<string>()
211 /** Video + subs -> H264 */
212 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test3)
214 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_h264_test3");
215 film->set_name ("ffmpeg_encoder_h264_test3");
216 film->set_container (Ratio::from_id ("185"));
217 film->set_audio_channels (6);
219 shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
220 film->examine_and_add_content (c);
221 BOOST_REQUIRE (!wait_for_jobs ());
223 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip.srt"));
224 film->examine_and_add_content (s);
225 BOOST_REQUIRE (!wait_for_jobs ());
226 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
227 s->only_text()->set_effect (dcp::SHADOW);
228 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
229 film->write_metadata();
231 shared_ptr<Job> job (new TranscodeJob (film));
232 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test3.mp4", EXPORT_FORMAT_H264_AAC, false, false, 23
233 #ifdef DCPOMATIC_VARIANT_SWAROOP
234 , optional<dcp::Key>(), optional<string>()
240 /** Scope-in-flat DCP -> H264 */
241 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test4)
243 shared_ptr<Film> film = new_test_film2("ffmpeg_encoder_h264_test4");
244 film->examine_and_add_content(shared_ptr<DCPContent>(new DCPContent("test/data/scope_dcp")));
245 BOOST_REQUIRE(!wait_for_jobs());
247 film->set_container(Ratio::from_id("185"));
249 shared_ptr<Job> job(new TranscodeJob(film));
250 FFmpegEncoder encoder(film, job, "build/test/ffmpeg_encoder_h264_test4.mp4", EXPORT_FORMAT_H264_AAC, false, false, 23
251 #ifdef DCPOMATIC_VARIANT_SWAROOP
252 , optional<dcp::Key>(), optional<string>()
258 /** Test mixdown from 5.1 to stereo */
259 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test5)
261 shared_ptr<Film> film = new_test_film ("ffmpeg_transcoder_h264_test5");
262 film->set_name ("ffmpeg_transcoder_h264_test5");
263 film->set_container (Ratio::from_id ("185"));
264 film->set_audio_channels (6);
266 shared_ptr<FFmpegContent> L (new FFmpegContent("test/data/L.wav"));
267 film->examine_and_add_content (L);
268 shared_ptr<FFmpegContent> R (new FFmpegContent("test/data/R.wav"));
269 film->examine_and_add_content (R);
270 shared_ptr<FFmpegContent> C (new FFmpegContent("test/data/C.wav"));
271 film->examine_and_add_content (C);
272 shared_ptr<FFmpegContent> Ls (new FFmpegContent("test/data/Ls.wav"));
273 film->examine_and_add_content (Ls);
274 shared_ptr<FFmpegContent> Rs (new FFmpegContent("test/data/Rs.wav"));
275 film->examine_and_add_content (Rs);
276 shared_ptr<FFmpegContent> Lfe (new FFmpegContent("test/data/Lfe.wav"));
277 film->examine_and_add_content (Lfe);
278 BOOST_REQUIRE (!wait_for_jobs ());
280 AudioMapping map (1, MAX_DCP_AUDIO_CHANNELS);
282 L->set_position (film, DCPTime::from_seconds(0));
285 L->audio->set_mapping (map);
286 R->set_position (film, DCPTime::from_seconds(1));
289 R->audio->set_mapping (map);
290 C->set_position (film, DCPTime::from_seconds(2));
293 C->audio->set_mapping (map);
294 Lfe->set_position (film, DCPTime::from_seconds(3));
297 Lfe->audio->set_mapping (map);
298 Ls->set_position (film, DCPTime::from_seconds(4));
301 Ls->audio->set_mapping (map);
302 Rs->set_position (film, DCPTime::from_seconds(5));
305 Rs->audio->set_mapping (map);
307 shared_ptr<Job> job (new TranscodeJob (film));
308 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test5.mp4", EXPORT_FORMAT_H264_AAC, true, false, 23
309 #ifdef DCPOMATIC_VARIANT_SWAROOP
310 , optional<dcp::Key>(), optional<string>()
315 check_ffmpeg ("build/test/ffmpeg_encoder_h264_test5.mp4", "test/data/ffmpeg_encoder_h264_test5.mp4", 1);
318 /** Test export of a VF */
319 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test6)
321 shared_ptr<Film> film = new_test_film2 ("ffmpeg_encoder_h264_test6_ov");
322 film->examine_and_add_content (shared_ptr<ImageContent>(new ImageContent(TestPaths::private_data / "bbc405.png")));
323 BOOST_REQUIRE (!wait_for_jobs());
325 BOOST_REQUIRE (!wait_for_jobs());
327 shared_ptr<Film> film2 = new_test_film2 ("ffmpeg_encoder_h264_test6_vf");
328 shared_ptr<DCPContent> ov (new DCPContent("build/test/ffmpeg_encoder_h264_test6_ov/" + film->dcp_name(false)));
329 film2->examine_and_add_content (ov);
330 BOOST_REQUIRE (!wait_for_jobs());
331 ov->set_reference_video (true);
332 shared_ptr<Content> subs = content_factory("test/data/subrip.srt").front();
333 film2->examine_and_add_content (subs);
334 BOOST_REQUIRE (!wait_for_jobs());
335 BOOST_FOREACH (shared_ptr<TextContent> i, subs->text) {
339 shared_ptr<Job> job (new TranscodeJob (film2));
340 FFmpegEncoder encoder (film2, job, "build/test/ffmpeg_encoder_h264_test6_vf.mp4", EXPORT_FORMAT_H264_AAC, true, false, 23
341 #ifdef DCPOMATIC_VARIANT_SWAROOP
342 , optional<dcp::Key>(), optional<string>()
348 /** Test export of a 3D DCP in a 2D project */
349 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test7)
351 shared_ptr<Film> film = new_test_film2 ("ffmpeg_encoder_h264_test7_data");
352 shared_ptr<Content> L (shared_ptr<ImageContent>(new ImageContent(TestPaths::private_data / "bbc405.png")));
353 film->examine_and_add_content (L);
354 shared_ptr<Content> R (shared_ptr<ImageContent>(new ImageContent(TestPaths::private_data / "bbc405.png")));
355 film->examine_and_add_content (R);
356 BOOST_REQUIRE (!wait_for_jobs());
357 L->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT);
358 L->set_position (film, DCPTime());
359 R->video->set_frame_type (VIDEO_FRAME_TYPE_3D_RIGHT);
360 R->set_position (film, DCPTime());
361 film->set_three_d (true);
363 BOOST_REQUIRE (!wait_for_jobs());
365 shared_ptr<Film> film2 = new_test_film2 ("ffmpeg_encoder_h264_test7_export");
366 shared_ptr<Content> dcp (new DCPContent(film->dir(film->dcp_name())));
367 film2->examine_and_add_content (dcp);
368 BOOST_REQUIRE (!wait_for_jobs());
370 shared_ptr<Job> job (new TranscodeJob (film2));
371 FFmpegEncoder encoder (film2, job, "build/test/ffmpeg_encoder_h264_test7.mp4", EXPORT_FORMAT_H264_AAC, true, false, 23
372 #ifdef DCPOMATIC_VARIANT_SWAROOP
373 , optional<dcp::Key>(), optional<string>()
380 /** Stereo project with mixdown-to-stereo set */
381 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test8)
383 shared_ptr<Film> film = new_test_film2("ffmpeg_encoder_h264_test4");
384 film->examine_and_add_content(shared_ptr<DCPContent>(new DCPContent("test/data/scope_dcp")));
385 BOOST_REQUIRE(!wait_for_jobs());
386 film->set_audio_channels (2);
388 shared_ptr<Job> job(new TranscodeJob(film));
389 FFmpegEncoder encoder(film, job, "build/test/ffmpeg_encoder_h264_test8.mp4", EXPORT_FORMAT_H264_AAC, true, false, 23
390 #ifdef DCPOMATIC_VARIANT_SWAROOP
391 , optional<dcp::Key>(), optional<string>()