swaroop: clear out viewer when deselecting playlist.
[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 namespace dcpomatic;
40
41 static void
42 ffmpeg_content_test (int number, boost::filesystem::path content, ExportFormat format)
43 {
44         string name = "ffmpeg_encoder_";
45         string extension;
46         switch (format) {
47         case EXPORT_FORMAT_H264:
48                 name += "h264";
49                 extension = "mp4";
50                 break;
51         case EXPORT_FORMAT_PRORES:
52                 name += "prores";
53                 extension = "mov";
54                 break;
55         }
56
57         name = String::compose("%1_test%2", name, number);
58
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);
64
65         film->examine_and_add_content (c);
66         BOOST_REQUIRE (!wait_for_jobs ());
67
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);
71         encoder.go ();
72 }
73
74 /** Red / green / blue MP4 -> Prores */
75 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test1)
76 {
77         ffmpeg_content_test (1, "test/data/test.mp4", EXPORT_FORMAT_PRORES);
78 }
79
80 /** Dolby Aurora trailer VOB -> Prores */
81 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test2)
82 {
83         ffmpeg_content_test (2, private_data / "dolby_aurora.vob", EXPORT_FORMAT_PRORES);
84 }
85
86 /** Sintel trailer -> Prores */
87 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test3)
88 {
89         ffmpeg_content_test (3, private_data / "Sintel_Trailer1.480p.DivX_Plus_HD.mkv", EXPORT_FORMAT_PRORES);
90 }
91
92 /** Big Buck Bunny trailer -> Prores */
93 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test4)
94 {
95         ffmpeg_content_test (4, private_data / "big_buck_bunny_trailer_480p.mov", EXPORT_FORMAT_PRORES);
96 }
97
98 /** Still image -> Prores */
99 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test5)
100 {
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);
106
107         film->examine_and_add_content (c);
108         BOOST_REQUIRE (!wait_for_jobs ());
109
110         c->video->set_length (240);
111
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);
115         encoder.go ();
116 }
117
118 /** Subs -> Prores */
119 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test6)
120 {
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);
125
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();
133
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);
136         encoder.go ();
137 }
138
139 /** Video + subs -> Prores */
140 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test7)
141 {
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);
146
147         shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
148         film->examine_and_add_content (c);
149         BOOST_REQUIRE (!wait_for_jobs ());
150
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));
157
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);
160         encoder.go ();
161 }
162
163 /** Red / green / blue MP4 -> H264 */
164 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test1)
165 {
166         ffmpeg_content_test(1, "test/data/test.mp4", EXPORT_FORMAT_H264);
167 }
168
169 /** Just subtitles -> H264 */
170 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test2)
171 {
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);
176
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();
184
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);
187         encoder.go ();
188 }
189
190 /** Video + subs -> H264 */
191 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test3)
192 {
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);
197
198         shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
199         film->examine_and_add_content (c);
200         BOOST_REQUIRE (!wait_for_jobs ());
201
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();
209
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);
212         encoder.go ();
213 }
214
215 /** Scope-in-flat DCP -> H264 */
216 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test4)
217 {
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());
221
222         film->set_container(Ratio::from_id("185"));
223
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);
226         encoder.go();
227 }
228
229 /** Test mixdown from 5.1 to stereo */
230 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test5)
231 {
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);
236
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 ());
250
251         AudioMapping map (1, MAX_DCP_AUDIO_CHANNELS);
252
253         L->set_position (film, DCPTime::from_seconds(0));
254         map.make_zero ();
255         map.set (0, 0, 1);
256         L->audio->set_mapping (map);
257         R->set_position (film, DCPTime::from_seconds(1));
258         map.make_zero ();
259         map.set (0, 1, 1);
260         R->audio->set_mapping (map);
261         C->set_position (film, DCPTime::from_seconds(2));
262         map.make_zero ();
263         map.set (0, 2, 1);
264         C->audio->set_mapping (map);
265         Lfe->set_position (film, DCPTime::from_seconds(3));
266         map.make_zero ();
267         map.set (0, 3, 1);
268         Lfe->audio->set_mapping (map);
269         Ls->set_position (film, DCPTime::from_seconds(4));
270         map.make_zero ();
271         map.set (0, 4, 1);
272         Ls->audio->set_mapping (map);
273         Rs->set_position (film, DCPTime::from_seconds(5));
274         map.make_zero ();
275         map.set (0, 5, 1);
276         Rs->audio->set_mapping (map);
277
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);
280         encoder.go ();
281
282         check_ffmpeg ("build/test/ffmpeg_encoder_h264_test5.mp4", "test/data/ffmpeg_encoder_h264_test5.mp4", 1);
283 }
284
285 /** Test export of a VF */
286 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test6)
287 {
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());
291         film->make_dcp ();
292         BOOST_REQUIRE (!wait_for_jobs());
293
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) {
303                 i->set_use (true);
304         }
305
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);
308         encoder.go ();
309 }