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;
41 ffmpeg_content_test (int number, boost::filesystem::path content, ExportFormat format)
43 string name = "ffmpeg_encoder_";
46 case EXPORT_FORMAT_H264:
50 case EXPORT_FORMAT_PRORES:
56 name = String::compose("%1_test%2", name, number);
58 shared_ptr<Film> film = new_test_film (name);
59 film->set_name (name);
60 shared_ptr<FFmpegContent> c (new FFmpegContent(content));
61 film->set_container (Ratio::from_id ("185"));
62 film->set_audio_channels (6);
64 film->examine_and_add_content (c);
65 BOOST_REQUIRE (!wait_for_jobs ());
67 film->write_metadata ();
68 shared_ptr<Job> job (new TranscodeJob (film));
69 FFmpegEncoder encoder (film, job, String::compose("build/test/%1.%2", name, extension), format, false, false, 23);
73 /** Red / green / blue MP4 -> Prores */
74 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test1)
76 ffmpeg_content_test (1, "test/data/test.mp4", EXPORT_FORMAT_PRORES);
79 /** Dolby Aurora trailer VOB -> Prores */
80 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test2)
82 ffmpeg_content_test (2, private_data / "dolby_aurora.vob", EXPORT_FORMAT_PRORES);
85 /** Sintel trailer -> Prores */
86 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test3)
88 ffmpeg_content_test (3, private_data / "Sintel_Trailer1.480p.DivX_Plus_HD.mkv", EXPORT_FORMAT_PRORES);
91 /** Big Buck Bunny trailer -> Prores */
92 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test4)
94 ffmpeg_content_test (4, private_data / "big_buck_bunny_trailer_480p.mov", EXPORT_FORMAT_PRORES);
97 /** Still image -> Prores */
98 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test5)
100 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test5");
101 film->set_name ("ffmpeg_encoder_prores_test5");
102 shared_ptr<ImageContent> c (new ImageContent(private_data / "bbc405.png"));
103 film->set_container (Ratio::from_id ("185"));
104 film->set_audio_channels (6);
106 film->examine_and_add_content (c);
107 BOOST_REQUIRE (!wait_for_jobs ());
109 c->video->set_length (240);
111 film->write_metadata ();
112 shared_ptr<Job> job (new TranscodeJob (film));
113 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test5.mov", EXPORT_FORMAT_PRORES, false, false, 23);
117 /** Subs -> Prores */
118 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test6)
120 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test6");
121 film->set_name ("ffmpeg_encoder_prores_test6");
122 film->set_container (Ratio::from_id ("185"));
123 film->set_audio_channels (6);
125 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip2.srt"));
126 film->examine_and_add_content (s);
127 BOOST_REQUIRE (!wait_for_jobs ());
128 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
129 s->only_text()->set_effect (dcp::SHADOW);
130 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
131 film->write_metadata();
133 shared_ptr<Job> job (new TranscodeJob (film));
134 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test6.mov", EXPORT_FORMAT_PRORES, false, false, 23);
138 /** Video + subs -> Prores */
139 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test7)
141 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test7");
142 film->set_name ("ffmpeg_encoder_prores_test7");
143 film->set_container (Ratio::from_id ("185"));
144 film->set_audio_channels (6);
146 shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
147 film->examine_and_add_content (c);
148 BOOST_REQUIRE (!wait_for_jobs ());
150 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip.srt"));
151 film->examine_and_add_content (s);
152 BOOST_REQUIRE (!wait_for_jobs ());
153 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
154 s->only_text()->set_effect (dcp::SHADOW);
155 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
157 shared_ptr<Job> job (new TranscodeJob (film));
158 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test7.mov", EXPORT_FORMAT_PRORES, false, false, 23);
162 /** Red / green / blue MP4 -> H264 */
163 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test1)
165 ffmpeg_content_test(1, "test/data/test.mp4", EXPORT_FORMAT_H264);
168 /** Just subtitles -> H264 */
169 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test2)
171 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_h264_test2");
172 film->set_name ("ffmpeg_encoder_h264_test2");
173 film->set_container (Ratio::from_id ("185"));
174 film->set_audio_channels (6);
176 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip2.srt"));
177 film->examine_and_add_content (s);
178 BOOST_REQUIRE (!wait_for_jobs ());
179 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
180 s->only_text()->set_effect (dcp::SHADOW);
181 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
182 film->write_metadata();
184 shared_ptr<Job> job (new TranscodeJob (film));
185 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test2.mp4", EXPORT_FORMAT_H264, false, false, 23);
189 /** Video + subs -> H264 */
190 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test3)
192 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_h264_test3");
193 film->set_name ("ffmpeg_encoder_h264_test3");
194 film->set_container (Ratio::from_id ("185"));
195 film->set_audio_channels (6);
197 shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
198 film->examine_and_add_content (c);
199 BOOST_REQUIRE (!wait_for_jobs ());
201 shared_ptr<StringTextFileContent> s (new StringTextFileContent("test/data/subrip.srt"));
202 film->examine_and_add_content (s);
203 BOOST_REQUIRE (!wait_for_jobs ());
204 s->only_text()->set_colour (dcp::Colour (255, 255, 0));
205 s->only_text()->set_effect (dcp::SHADOW);
206 s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
207 film->write_metadata();
209 shared_ptr<Job> job (new TranscodeJob (film));
210 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test3.mp4", EXPORT_FORMAT_H264, false, false, 23);
214 /** Scope-in-flat DCP -> H264 */
215 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test4)
217 shared_ptr<Film> film = new_test_film2("ffmpeg_encoder_h264_test4");
218 film->examine_and_add_content(shared_ptr<DCPContent>(new DCPContent("test/data/scope_dcp")));
219 BOOST_REQUIRE(!wait_for_jobs());
221 film->set_container(Ratio::from_id("185"));
223 shared_ptr<Job> job(new TranscodeJob(film));
224 FFmpegEncoder encoder(film, job, "build/test/ffmpeg_encoder_h264_test4.mp4", EXPORT_FORMAT_H264, false, false, 23);
228 /** Test mixdown from 5.1 to stereo */
229 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test5)
231 shared_ptr<Film> film = new_test_film ("ffmpeg_transcoder_h264_test5");
232 film->set_name ("ffmpeg_transcoder_h264_test5");
233 film->set_container (Ratio::from_id ("185"));
234 film->set_audio_channels (6);
236 shared_ptr<FFmpegContent> L (new FFmpegContent("test/data/L.wav"));
237 film->examine_and_add_content (L);
238 shared_ptr<FFmpegContent> R (new FFmpegContent("test/data/R.wav"));
239 film->examine_and_add_content (R);
240 shared_ptr<FFmpegContent> C (new FFmpegContent("test/data/C.wav"));
241 film->examine_and_add_content (C);
242 shared_ptr<FFmpegContent> Ls (new FFmpegContent("test/data/Ls.wav"));
243 film->examine_and_add_content (Ls);
244 shared_ptr<FFmpegContent> Rs (new FFmpegContent("test/data/Rs.wav"));
245 film->examine_and_add_content (Rs);
246 shared_ptr<FFmpegContent> Lfe (new FFmpegContent("test/data/Lfe.wav"));
247 film->examine_and_add_content (Lfe);
248 BOOST_REQUIRE (!wait_for_jobs ());
250 AudioMapping map (1, MAX_DCP_AUDIO_CHANNELS);
252 L->set_position (film, DCPTime::from_seconds(0));
255 L->audio->set_mapping (map);
256 R->set_position (film, DCPTime::from_seconds(1));
259 R->audio->set_mapping (map);
260 C->set_position (film, DCPTime::from_seconds(2));
263 C->audio->set_mapping (map);
264 Lfe->set_position (film, DCPTime::from_seconds(3));
267 Lfe->audio->set_mapping (map);
268 Ls->set_position (film, DCPTime::from_seconds(4));
271 Ls->audio->set_mapping (map);
272 Rs->set_position (film, DCPTime::from_seconds(5));
275 Rs->audio->set_mapping (map);
277 shared_ptr<Job> job (new TranscodeJob (film));
278 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test5.mp4", EXPORT_FORMAT_H264, true, false, 23);
281 check_ffmpeg ("build/test/ffmpeg_encoder_h264_test5.mp4", "test/data/ffmpeg_encoder_h264_test5.mp4", 1);
284 /** Test export of a VF */
285 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test6)
287 shared_ptr<Film> film = new_test_film2 ("ffmpeg_encoder_h264_test6_ov");
288 film->examine_and_add_content (shared_ptr<ImageContent>(new ImageContent(private_data / "bbc405.png")));
289 BOOST_REQUIRE (!wait_for_jobs());
291 BOOST_REQUIRE (!wait_for_jobs());
293 shared_ptr<Film> film2 = new_test_film2 ("ffmpeg_encoder_h264_test6_vf");
294 shared_ptr<DCPContent> ov (new DCPContent("build/test/ffmpeg_encoder_h264_test6_ov/" + film->dcp_name(false)));
295 film2->examine_and_add_content (ov);
296 BOOST_REQUIRE (!wait_for_jobs());
297 ov->set_reference_video (true);
298 shared_ptr<Content> subs = content_factory("test/data/subrip.srt").front();
299 film2->examine_and_add_content (subs);
300 BOOST_REQUIRE (!wait_for_jobs());
301 BOOST_FOREACH (shared_ptr<TextContent> i, subs->text) {
305 shared_ptr<Job> job (new TranscodeJob (film2));
306 FFmpegEncoder encoder (film2, job, "build/test/ffmpeg_encoder_h264_test6_vf.mp4", EXPORT_FORMAT_H264, true, false, 23);