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, false, 23);
78 /** Red / green / blue MP4 -> Prores */
79 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test1)
81 ffmpeg_content_test (1, "test/data/test.mp4", EXPORT_FORMAT_PRORES);
84 /** Dolby Aurora trailer VOB -> Prores */
85 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test2)
87 ffmpeg_content_test (2, TestPaths::private_data() / "dolby_aurora.vob", EXPORT_FORMAT_PRORES);
90 /** Sintel trailer -> Prores */
91 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test3)
93 ffmpeg_content_test (3, TestPaths::private_data() / "Sintel_Trailer1.480p.DivX_Plus_HD.mkv", EXPORT_FORMAT_PRORES);
96 /** Big Buck Bunny trailer -> Prores */
97 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test4)
99 ffmpeg_content_test (4, TestPaths::private_data() / "big_buck_bunny_trailer_480p.mov", EXPORT_FORMAT_PRORES);
102 /** Still image -> Prores */
103 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test5)
105 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test5");
106 film->set_name ("ffmpeg_encoder_prores_test5");
107 shared_ptr<ImageContent> c (new ImageContent(TestPaths::private_data() / "bbc405.png"));
108 film->set_container (Ratio::from_id ("185"));
109 film->set_audio_channels (6);
111 film->examine_and_add_content (c);
112 BOOST_REQUIRE (!wait_for_jobs ());
114 c->video->set_length (240);
116 film->write_metadata ();
117 shared_ptr<Job> job (new TranscodeJob (film));
118 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test5.mov", EXPORT_FORMAT_PRORES, false, false, false, 23);
122 /** Subs -> Prores */
123 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test6)
125 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test6");
126 film->set_name ("ffmpeg_encoder_prores_test6");
127 film->set_container (Ratio::from_id ("185"));
128 film->set_audio_channels (6);
130 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip2.srt"));
131 film->examine_and_add_content (s);
132 BOOST_REQUIRE (!wait_for_jobs ());
133 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
134 s->only_text()->set_effect (dcp::SHADOW);
135 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
136 film->write_metadata();
138 shared_ptr<Job> job (new TranscodeJob (film));
139 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test6.mov", EXPORT_FORMAT_PRORES, false, false, false, 23);
143 /** Video + subs -> Prores */
144 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test7)
146 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test7");
147 film->set_name ("ffmpeg_encoder_prores_test7");
148 film->set_container (Ratio::from_id ("185"));
149 film->set_audio_channels (6);
151 shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
152 film->examine_and_add_content (c);
153 BOOST_REQUIRE (!wait_for_jobs ());
155 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip.srt"));
156 film->examine_and_add_content (s);
157 BOOST_REQUIRE (!wait_for_jobs ());
158 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
159 s->only_text()->set_effect (dcp::SHADOW);
160 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
162 shared_ptr<Job> job (new TranscodeJob (film));
163 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test7.mov", EXPORT_FORMAT_PRORES, false, false, false, 23);
167 /** Red / green / blue MP4 -> H264 */
168 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test1)
170 ffmpeg_content_test(1, "test/data/test.mp4", EXPORT_FORMAT_H264_AAC);
173 /** Just subtitles -> H264 */
174 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test2)
176 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_h264_test2");
177 film->set_name ("ffmpeg_encoder_h264_test2");
178 film->set_container (Ratio::from_id ("185"));
179 film->set_audio_channels (6);
181 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip2.srt"));
182 film->examine_and_add_content (s);
183 BOOST_REQUIRE (!wait_for_jobs ());
184 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
185 s->only_text()->set_effect (dcp::SHADOW);
186 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
187 film->write_metadata();
189 shared_ptr<Job> job (new TranscodeJob (film));
190 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test2.mp4", EXPORT_FORMAT_H264_AAC, false, false, false, 23);
194 /** Video + subs -> H264 */
195 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test3)
197 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_h264_test3");
198 film->set_name ("ffmpeg_encoder_h264_test3");
199 film->set_container (Ratio::from_id ("185"));
200 film->set_audio_channels (6);
202 shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
203 film->examine_and_add_content (c);
204 BOOST_REQUIRE (!wait_for_jobs ());
206 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip.srt"));
207 film->examine_and_add_content (s);
208 BOOST_REQUIRE (!wait_for_jobs ());
209 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
210 s->only_text()->set_effect (dcp::SHADOW);
211 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
212 film->write_metadata();
214 shared_ptr<Job> job (new TranscodeJob (film));
215 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test3.mp4", EXPORT_FORMAT_H264_AAC, false, false, false, 23);
219 /** Scope-in-flat DCP -> H264 */
220 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test4)
222 shared_ptr<Film> film = new_test_film2("ffmpeg_encoder_h264_test4");
223 film->examine_and_add_content(shared_ptr<DCPContent>(new DCPContent("test/data/scope_dcp")));
224 BOOST_REQUIRE(!wait_for_jobs());
226 film->set_container(Ratio::from_id("185"));
228 shared_ptr<Job> job(new TranscodeJob(film));
229 FFmpegEncoder encoder(film, job, "build/test/ffmpeg_encoder_h264_test4.mp4", EXPORT_FORMAT_H264_AAC, false, false, false, 23);
233 /** Test mixdown from 5.1 to stereo */
234 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test5)
236 shared_ptr<Film> film = new_test_film ("ffmpeg_transcoder_h264_test5");
237 film->set_name ("ffmpeg_transcoder_h264_test5");
238 film->set_container (Ratio::from_id ("185"));
239 film->set_audio_channels (6);
241 shared_ptr<FFmpegContent> L (new FFmpegContent("test/data/L.wav"));
242 film->examine_and_add_content (L);
243 shared_ptr<FFmpegContent> R (new FFmpegContent("test/data/R.wav"));
244 film->examine_and_add_content (R);
245 shared_ptr<FFmpegContent> C (new FFmpegContent("test/data/C.wav"));
246 film->examine_and_add_content (C);
247 shared_ptr<FFmpegContent> Ls (new FFmpegContent("test/data/Ls.wav"));
248 film->examine_and_add_content (Ls);
249 shared_ptr<FFmpegContent> Rs (new FFmpegContent("test/data/Rs.wav"));
250 film->examine_and_add_content (Rs);
251 shared_ptr<FFmpegContent> Lfe (new FFmpegContent("test/data/Lfe.wav"));
252 film->examine_and_add_content (Lfe);
253 BOOST_REQUIRE (!wait_for_jobs ());
255 AudioMapping map (1, MAX_DCP_AUDIO_CHANNELS);
257 L->set_position (film, DCPTime::from_seconds(0));
260 L->audio->set_mapping (map);
261 R->set_position (film, DCPTime::from_seconds(1));
264 R->audio->set_mapping (map);
265 C->set_position (film, DCPTime::from_seconds(2));
268 C->audio->set_mapping (map);
269 Lfe->set_position (film, DCPTime::from_seconds(3));
272 Lfe->audio->set_mapping (map);
273 Ls->set_position (film, DCPTime::from_seconds(4));
276 Ls->audio->set_mapping (map);
277 Rs->set_position (film, DCPTime::from_seconds(5));
280 Rs->audio->set_mapping (map);
282 shared_ptr<Job> job (new TranscodeJob (film));
283 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test5.mp4", EXPORT_FORMAT_H264_AAC, true, false, false, 23);
286 check_ffmpeg ("build/test/ffmpeg_encoder_h264_test5.mp4", "test/data/ffmpeg_encoder_h264_test5.mp4", 1);
289 /** Test export of a VF */
290 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test6)
292 shared_ptr<Film> film = new_test_film2 ("ffmpeg_encoder_h264_test6_ov");
293 film->examine_and_add_content (shared_ptr<ImageContent>(new ImageContent(TestPaths::private_data() / "bbc405.png")));
294 BOOST_REQUIRE (!wait_for_jobs());
296 BOOST_REQUIRE (!wait_for_jobs());
298 shared_ptr<Film> film2 = new_test_film2 ("ffmpeg_encoder_h264_test6_vf");
299 shared_ptr<DCPContent> ov (new DCPContent("build/test/ffmpeg_encoder_h264_test6_ov/" + film->dcp_name(false)));
300 film2->examine_and_add_content (ov);
301 BOOST_REQUIRE (!wait_for_jobs());
302 ov->set_reference_video (true);
303 shared_ptr<Content> subs = content_factory("test/data/subrip.srt").front();
304 film2->examine_and_add_content (subs);
305 BOOST_REQUIRE (!wait_for_jobs());
306 BOOST_FOREACH (shared_ptr<TextContent> i, subs->text) {
310 shared_ptr<Job> job (new TranscodeJob (film2));
311 FFmpegEncoder encoder (film2, job, "build/test/ffmpeg_encoder_h264_test6_vf.mp4", EXPORT_FORMAT_H264_AAC, true, false, false, 23);
315 /** Test export of a 3D DCP in a 2D project */
316 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test7)
318 shared_ptr<Film> film = new_test_film2 ("ffmpeg_encoder_h264_test7_data");
319 shared_ptr<Content> L (shared_ptr<ImageContent>(new ImageContent(TestPaths::private_data() / "bbc405.png")));
320 film->examine_and_add_content (L);
321 shared_ptr<Content> R (shared_ptr<ImageContent>(new ImageContent(TestPaths::private_data() / "bbc405.png")));
322 film->examine_and_add_content (R);
323 BOOST_REQUIRE (!wait_for_jobs());
324 L->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT);
325 L->set_position (film, DCPTime());
326 R->video->set_frame_type (VIDEO_FRAME_TYPE_3D_RIGHT);
327 R->set_position (film, DCPTime());
328 film->set_three_d (true);
330 BOOST_REQUIRE (!wait_for_jobs());
332 shared_ptr<Film> film2 = new_test_film2 ("ffmpeg_encoder_h264_test7_export");
333 shared_ptr<Content> dcp (new DCPContent(film->dir(film->dcp_name())));
334 film2->examine_and_add_content (dcp);
335 BOOST_REQUIRE (!wait_for_jobs());
337 shared_ptr<Job> job (new TranscodeJob (film2));
338 FFmpegEncoder encoder (film2, job, "build/test/ffmpeg_encoder_h264_test7.mp4", EXPORT_FORMAT_H264_AAC, true, false, false, 23);
343 /** Stereo project with mixdown-to-stereo set */
344 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test8)
346 shared_ptr<Film> film = new_test_film2("ffmpeg_encoder_h264_test4");
347 film->examine_and_add_content(shared_ptr<DCPContent>(new DCPContent("test/data/scope_dcp")));
348 BOOST_REQUIRE(!wait_for_jobs());
349 film->set_audio_channels (2);
351 shared_ptr<Job> job(new TranscodeJob(film));
352 FFmpegEncoder encoder(film, job, "build/test/ffmpeg_encoder_h264_test8.mp4", EXPORT_FORMAT_H264_AAC, true, false, false, 23);
357 /** 7.1/HI/VI (i.e. 12-channel) project */
358 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test9)
360 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test9");
361 film->set_name ("ffmpeg_encoder_prores_test9");
362 shared_ptr<ImageContent> c (new ImageContent(TestPaths::private_data() / "bbc405.png"));
363 film->set_container (Ratio::from_id ("185"));
364 film->set_audio_channels (12);
366 film->examine_and_add_content (c);
367 BOOST_REQUIRE (!wait_for_jobs ());
369 c->video->set_length (240);
371 film->write_metadata ();
372 shared_ptr<Job> job (new TranscodeJob (film));
373 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test9.mov", EXPORT_FORMAT_H264_AAC, false, false, false, 23);