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 namespace dcpomatic;
42 ffmpeg_content_test (int number, boost::filesystem::path content, ExportFormat format)
44 string name = "ffmpeg_encoder_";
47 case EXPORT_FORMAT_H264:
51 case EXPORT_FORMAT_PRORES:
57 name = String::compose("%1_test%2", name, number);
59 shared_ptr<Film> film = new_test_film (name);
60 film->set_name (name);
61 shared_ptr<FFmpegContent> c (new FFmpegContent(content));
62 film->set_container (Ratio::from_id ("185"));
63 film->set_audio_channels (6);
65 film->examine_and_add_content (c);
66 BOOST_REQUIRE (!wait_for_jobs ());
68 film->write_metadata ();
69 shared_ptr<Job> job (new TranscodeJob (film));
70 FFmpegEncoder encoder (film, job, String::compose("build/test/%1.%2", name, extension), format, false, false, 23);
74 /** Red / green / blue MP4 -> Prores */
75 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test1)
77 ffmpeg_content_test (1, "test/data/test.mp4", EXPORT_FORMAT_PRORES);
80 /** Dolby Aurora trailer VOB -> Prores */
81 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test2)
83 ffmpeg_content_test (2, private_data / "dolby_aurora.vob", EXPORT_FORMAT_PRORES);
86 /** Sintel trailer -> Prores */
87 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test3)
89 ffmpeg_content_test (3, private_data / "Sintel_Trailer1.480p.DivX_Plus_HD.mkv", EXPORT_FORMAT_PRORES);
92 /** Big Buck Bunny trailer -> Prores */
93 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test4)
95 ffmpeg_content_test (4, private_data / "big_buck_bunny_trailer_480p.mov", EXPORT_FORMAT_PRORES);
98 /** Still image -> Prores */
99 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test5)
101 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test5");
102 film->set_name ("ffmpeg_encoder_prores_test5");
103 shared_ptr<ImageContent> c (new ImageContent(private_data / "bbc405.png"));
104 film->set_container (Ratio::from_id ("185"));
105 film->set_audio_channels (6);
107 film->examine_and_add_content (c);
108 BOOST_REQUIRE (!wait_for_jobs ());
110 c->video->set_length (240);
112 film->write_metadata ();
113 shared_ptr<Job> job (new TranscodeJob (film));
114 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test5.mov", EXPORT_FORMAT_PRORES, false, false, 23);
118 /** Subs -> Prores */
119 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test6)
121 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test6");
122 film->set_name ("ffmpeg_encoder_prores_test6");
123 film->set_container (Ratio::from_id ("185"));
124 film->set_audio_channels (6);
126 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip2.srt"));
127 film->examine_and_add_content (s);
128 BOOST_REQUIRE (!wait_for_jobs ());
129 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
130 s->only_text()->set_effect (dcp::SHADOW);
131 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
132 film->write_metadata();
134 shared_ptr<Job> job (new TranscodeJob (film));
135 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test6.mov", EXPORT_FORMAT_PRORES, false, false, 23);
139 /** Video + subs -> Prores */
140 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test7)
142 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test7");
143 film->set_name ("ffmpeg_encoder_prores_test7");
144 film->set_container (Ratio::from_id ("185"));
145 film->set_audio_channels (6);
147 shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
148 film->examine_and_add_content (c);
149 BOOST_REQUIRE (!wait_for_jobs ());
151 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip.srt"));
152 film->examine_and_add_content (s);
153 BOOST_REQUIRE (!wait_for_jobs ());
154 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
155 s->only_text()->set_effect (dcp::SHADOW);
156 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
158 shared_ptr<Job> job (new TranscodeJob (film));
159 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test7.mov", EXPORT_FORMAT_PRORES, false, false, 23);
163 /** Red / green / blue MP4 -> H264 */
164 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test1)
166 ffmpeg_content_test(1, "test/data/test.mp4", EXPORT_FORMAT_H264);
169 /** Just subtitles -> H264 */
170 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test2)
172 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_h264_test2");
173 film->set_name ("ffmpeg_encoder_h264_test2");
174 film->set_container (Ratio::from_id ("185"));
175 film->set_audio_channels (6);
177 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip2.srt"));
178 film->examine_and_add_content (s);
179 BOOST_REQUIRE (!wait_for_jobs ());
180 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
181 s->only_text()->set_effect (dcp::SHADOW);
182 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
183 film->write_metadata();
185 shared_ptr<Job> job (new TranscodeJob (film));
186 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test2.mp4", EXPORT_FORMAT_H264, false, false, 23);
190 /** Video + subs -> H264 */
191 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test3)
193 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_h264_test3");
194 film->set_name ("ffmpeg_encoder_h264_test3");
195 film->set_container (Ratio::from_id ("185"));
196 film->set_audio_channels (6);
198 shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
199 film->examine_and_add_content (c);
200 BOOST_REQUIRE (!wait_for_jobs ());
202 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip.srt"));
203 film->examine_and_add_content (s);
204 BOOST_REQUIRE (!wait_for_jobs ());
205 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
206 s->only_text()->set_effect (dcp::SHADOW);
207 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
208 film->write_metadata();
210 shared_ptr<Job> job (new TranscodeJob (film));
211 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test3.mp4", EXPORT_FORMAT_H264, false, false, 23);
215 /** Scope-in-flat DCP -> H264 */
216 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test4)
218 shared_ptr<Film> film = new_test_film2("ffmpeg_encoder_h264_test4");
219 film->examine_and_add_content(shared_ptr<DCPContent>(new DCPContent("test/data/scope_dcp")));
220 BOOST_REQUIRE(!wait_for_jobs());
222 film->set_container(Ratio::from_id("185"));
224 shared_ptr<Job> job(new TranscodeJob(film));
225 FFmpegEncoder encoder(film, job, "build/test/ffmpeg_encoder_h264_test4.mp4", EXPORT_FORMAT_H264, false, false, 23);
229 /** Test mixdown from 5.1 to stereo */
230 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test5)
232 shared_ptr<Film> film = new_test_film ("ffmpeg_transcoder_h264_test5");
233 film->set_name ("ffmpeg_transcoder_h264_test5");
234 film->set_container (Ratio::from_id ("185"));
235 film->set_audio_channels (6);
237 shared_ptr<FFmpegContent> L (new FFmpegContent("test/data/L.wav"));
238 film->examine_and_add_content (L);
239 shared_ptr<FFmpegContent> R (new FFmpegContent("test/data/R.wav"));
240 film->examine_and_add_content (R);
241 shared_ptr<FFmpegContent> C (new FFmpegContent("test/data/C.wav"));
242 film->examine_and_add_content (C);
243 shared_ptr<FFmpegContent> Ls (new FFmpegContent("test/data/Ls.wav"));
244 film->examine_and_add_content (Ls);
245 shared_ptr<FFmpegContent> Rs (new FFmpegContent("test/data/Rs.wav"));
246 film->examine_and_add_content (Rs);
247 shared_ptr<FFmpegContent> Lfe (new FFmpegContent("test/data/Lfe.wav"));
248 film->examine_and_add_content (Lfe);
249 BOOST_REQUIRE (!wait_for_jobs ());
251 AudioMapping map (1, MAX_DCP_AUDIO_CHANNELS);
253 L->set_position (film, DCPTime::from_seconds(0));
256 L->audio->set_mapping (map);
257 R->set_position (film, DCPTime::from_seconds(1));
260 R->audio->set_mapping (map);
261 C->set_position (film, DCPTime::from_seconds(2));
264 C->audio->set_mapping (map);
265 Lfe->set_position (film, DCPTime::from_seconds(3));
268 Lfe->audio->set_mapping (map);
269 Ls->set_position (film, DCPTime::from_seconds(4));
272 Ls->audio->set_mapping (map);
273 Rs->set_position (film, DCPTime::from_seconds(5));
276 Rs->audio->set_mapping (map);
278 shared_ptr<Job> job (new TranscodeJob (film));
279 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test5.mp4", EXPORT_FORMAT_H264, true, false, 23);
282 check_ffmpeg ("build/test/ffmpeg_encoder_h264_test5.mp4", "test/data/ffmpeg_encoder_h264_test5.mp4", 1);
285 /** Test export of a VF */
286 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test6)
288 shared_ptr<Film> film = new_test_film2 ("ffmpeg_encoder_h264_test6_ov");
289 film->examine_and_add_content (shared_ptr<ImageContent>(new ImageContent(private_data / "bbc405.png")));
290 BOOST_REQUIRE (!wait_for_jobs());
292 BOOST_REQUIRE (!wait_for_jobs());
294 shared_ptr<Film> film2 = new_test_film2 ("ffmpeg_encoder_h264_test6_vf");
295 shared_ptr<DCPContent> ov (new DCPContent("build/test/ffmpeg_encoder_h264_test6_ov/" + film->dcp_name(false)));
296 film2->examine_and_add_content (ov);
297 BOOST_REQUIRE (!wait_for_jobs());
298 ov->set_reference_video (true);
299 shared_ptr<Content> subs = content_factory("test/data/subrip.srt").front();
300 film2->examine_and_add_content (subs);
301 BOOST_REQUIRE (!wait_for_jobs());
302 BOOST_FOREACH (shared_ptr<TextContent> i, subs->text) {
306 shared_ptr<Job> job (new TranscodeJob (film2));
307 FFmpegEncoder encoder (film2, job, "build/test/ffmpeg_encoder_h264_test6_vf.mp4", EXPORT_FORMAT_H264, true, false, 23);