Rename DEVELOPMENT -> DEVELOP.md and add some stuff about player stress testing.
[dcpomatic.git] / test / ffmpeg_encoder_test.cc
1 /*
2     Copyright (C) 2017-2019 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 #include "lib/ffmpeg_encoder.h"
22 #include "lib/film.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"
34 #include "test.h"
35 #include <boost/test/unit_test.hpp>
36
37 using std::string;
38 using boost::shared_ptr;
39 using boost::optional;
40 using namespace dcpomatic;
41
42 static void
43 ffmpeg_content_test (int number, boost::filesystem::path content, ExportFormat format)
44 {
45         string name = "ffmpeg_encoder_";
46         string extension;
47         switch (format) {
48         case EXPORT_FORMAT_H264_AAC:
49                 name += "h264";
50                 extension = "mp4";
51                 break;
52         case EXPORT_FORMAT_PRORES:
53                 name += "prores";
54                 extension = "mov";
55                 break;
56         }
57
58         name = String::compose("%1_test%2", name, number);
59
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);
65
66         film->examine_and_add_content (c);
67         BOOST_REQUIRE (!wait_for_jobs ());
68
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>()
74 #endif
75                 );
76         encoder.go ();
77 }
78
79 /** Red / green / blue MP4 -> Prores */
80 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test1)
81 {
82         ffmpeg_content_test (1, "test/data/test.mp4", EXPORT_FORMAT_PRORES);
83 }
84
85 /** Dolby Aurora trailer VOB -> Prores */
86 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test2)
87 {
88         ffmpeg_content_test (2, TestPaths::private_data / "dolby_aurora.vob", EXPORT_FORMAT_PRORES);
89 }
90
91 /** Sintel trailer -> Prores */
92 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test3)
93 {
94         ffmpeg_content_test (3, TestPaths::private_data / "Sintel_Trailer1.480p.DivX_Plus_HD.mkv", EXPORT_FORMAT_PRORES);
95 }
96
97 /** Big Buck Bunny trailer -> Prores */
98 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test4)
99 {
100         ffmpeg_content_test (4, TestPaths::private_data / "big_buck_bunny_trailer_480p.mov", EXPORT_FORMAT_PRORES);
101 }
102
103 /** Still image -> Prores */
104 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test5)
105 {
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);
111
112         film->examine_and_add_content (c);
113         BOOST_REQUIRE (!wait_for_jobs ());
114
115         c->video->set_length (240);
116
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>()
122 #endif
123                 );
124         encoder.go ();
125 }
126
127 /** Subs -> Prores */
128 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test6)
129 {
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);
134
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();
142
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>()
147 #endif
148                                          );
149         encoder.go ();
150 }
151
152 /** Video + subs -> Prores */
153 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test7)
154 {
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);
159
160         shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
161         film->examine_and_add_content (c);
162         BOOST_REQUIRE (!wait_for_jobs ());
163
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));
170
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>()
175 #endif
176                 );
177         encoder.go ();
178 }
179
180 /** Red / green / blue MP4 -> H264 */
181 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test1)
182 {
183         ffmpeg_content_test(1, "test/data/test.mp4", EXPORT_FORMAT_H264_AAC);
184 }
185
186 /** Just subtitles -> H264 */
187 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test2)
188 {
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);
193
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();
201
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>()
206 #endif
207                 );
208         encoder.go ();
209 }
210
211 /** Video + subs -> H264 */
212 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test3)
213 {
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);
218
219         shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
220         film->examine_and_add_content (c);
221         BOOST_REQUIRE (!wait_for_jobs ());
222
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();
230
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>()
235 #endif
236                 );
237         encoder.go ();
238 }
239
240 /** Scope-in-flat DCP -> H264 */
241 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test4)
242 {
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());
246
247         film->set_container(Ratio::from_id("185"));
248
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>()
253 #endif
254                 );
255         encoder.go();
256 }
257
258 /** Test mixdown from 5.1 to stereo */
259 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test5)
260 {
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);
265
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 ());
279
280         AudioMapping map (1, MAX_DCP_AUDIO_CHANNELS);
281
282         L->set_position (film, DCPTime::from_seconds(0));
283         map.make_zero ();
284         map.set (0, 0, 1);
285         L->audio->set_mapping (map);
286         R->set_position (film, DCPTime::from_seconds(1));
287         map.make_zero ();
288         map.set (0, 1, 1);
289         R->audio->set_mapping (map);
290         C->set_position (film, DCPTime::from_seconds(2));
291         map.make_zero ();
292         map.set (0, 2, 1);
293         C->audio->set_mapping (map);
294         Lfe->set_position (film, DCPTime::from_seconds(3));
295         map.make_zero ();
296         map.set (0, 3, 1);
297         Lfe->audio->set_mapping (map);
298         Ls->set_position (film, DCPTime::from_seconds(4));
299         map.make_zero ();
300         map.set (0, 4, 1);
301         Ls->audio->set_mapping (map);
302         Rs->set_position (film, DCPTime::from_seconds(5));
303         map.make_zero ();
304         map.set (0, 5, 1);
305         Rs->audio->set_mapping (map);
306
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>()
311 #endif
312                 );
313         encoder.go ();
314
315         check_ffmpeg ("build/test/ffmpeg_encoder_h264_test5.mp4", "test/data/ffmpeg_encoder_h264_test5.mp4", 1);
316 }
317
318 /** Test export of a VF */
319 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test6)
320 {
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());
324         film->make_dcp ();
325         BOOST_REQUIRE (!wait_for_jobs());
326
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) {
336                 i->set_use (true);
337         }
338
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>()
343 #endif
344                 );
345         encoder.go ();
346 }
347
348 /** Test export of a 3D DCP in a 2D project */
349 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test7)
350 {
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);
362         film->make_dcp ();
363         BOOST_REQUIRE (!wait_for_jobs());
364
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());
369
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>()
374 #endif
375                 );
376         encoder.go ();
377 }
378