Basics of export of multiple reels to multiple files.
[dcpomatic.git] / test / ffmpeg_encoder_test.cc
1 /*
2     Copyright (C) 2017-2018 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 "test.h"
34 #include <boost/test/unit_test.hpp>
35
36 using std::string;
37 using boost::shared_ptr;
38
39 static void
40 ffmpeg_content_test (int number, boost::filesystem::path content, ExportFormat format)
41 {
42         string name = "ffmpeg_encoder_";
43         string extension;
44         switch (format) {
45         case EXPORT_FORMAT_H264:
46                 name += "h264";
47                 extension = "mp4";
48                 break;
49         case EXPORT_FORMAT_PRORES:
50                 name += "prores";
51                 extension = "mov";
52                 break;
53         }
54
55         name = String::compose("%1_test%2", name, number);
56
57         shared_ptr<Film> film = new_test_film (name);
58         film->set_name (name);
59         shared_ptr<FFmpegContent> c (new FFmpegContent (film, content));
60         film->set_container (Ratio::from_id ("185"));
61         film->set_audio_channels (6);
62
63         film->examine_and_add_content (c);
64         BOOST_REQUIRE (!wait_for_jobs ());
65
66         film->write_metadata ();
67         shared_ptr<Job> job (new TranscodeJob (film));
68         FFmpegEncoder encoder (film, job, String::compose("build/test/%1.%2", name, extension), format, false, false, 23);
69         encoder.go ();
70 }
71
72 /** Red / green / blue MP4 -> Prores */
73 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test1)
74 {
75         ffmpeg_content_test (1, "test/data/test.mp4", EXPORT_FORMAT_PRORES);
76 }
77
78 /** Dolby Aurora trailer VOB -> Prores */
79 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test2)
80 {
81         ffmpeg_content_test (2, private_data / "dolby_aurora.vob", EXPORT_FORMAT_PRORES);
82 }
83
84 /** Sintel trailer -> Prores */
85 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test3)
86 {
87         ffmpeg_content_test (3, private_data / "Sintel_Trailer1.480p.DivX_Plus_HD.mkv", EXPORT_FORMAT_PRORES);
88 }
89
90 /** Big Buck Bunny trailer -> Prores */
91 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test4)
92 {
93         ffmpeg_content_test (4, private_data / "big_buck_bunny_trailer_480p.mov", EXPORT_FORMAT_PRORES);
94 }
95
96 /** Still image -> Prores */
97 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test5)
98 {
99         shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test5");
100         film->set_name ("ffmpeg_encoder_prores_test5");
101         shared_ptr<ImageContent> c (new ImageContent (film, private_data / "bbc405.png"));
102         film->set_container (Ratio::from_id ("185"));
103         film->set_audio_channels (6);
104
105         film->examine_and_add_content (c);
106         BOOST_REQUIRE (!wait_for_jobs ());
107
108         c->video->set_length (240);
109
110         film->write_metadata ();
111         shared_ptr<Job> job (new TranscodeJob (film));
112         FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test5.mov", EXPORT_FORMAT_PRORES, false, false, 23);
113         encoder.go ();
114 }
115
116 /** Subs -> Prores */
117 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test6)
118 {
119         shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test6");
120         film->set_name ("ffmpeg_encoder_prores_test6");
121         film->set_container (Ratio::from_id ("185"));
122         film->set_audio_channels (6);
123
124         shared_ptr<StringTextFileContent> s (new StringTextFileContent (film, "test/data/subrip2.srt"));
125         film->examine_and_add_content (s);
126         BOOST_REQUIRE (!wait_for_jobs ());
127         s->only_text()->set_colour (dcp::Colour (255, 255, 0));
128         s->only_text()->set_effect (dcp::SHADOW);
129         s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
130         film->write_metadata();
131
132         shared_ptr<Job> job (new TranscodeJob (film));
133         FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test6.mov", EXPORT_FORMAT_PRORES, false, false, 23);
134         encoder.go ();
135 }
136
137 /** Video + subs -> Prores */
138 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test7)
139 {
140         shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test7");
141         film->set_name ("ffmpeg_encoder_prores_test7");
142         film->set_container (Ratio::from_id ("185"));
143         film->set_audio_channels (6);
144
145         shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/test.mp4"));
146         film->examine_and_add_content (c);
147         BOOST_REQUIRE (!wait_for_jobs ());
148
149         shared_ptr<StringTextFileContent> s (new StringTextFileContent (film, "test/data/subrip.srt"));
150         film->examine_and_add_content (s);
151         BOOST_REQUIRE (!wait_for_jobs ());
152         s->only_text()->set_colour (dcp::Colour (255, 255, 0));
153         s->only_text()->set_effect (dcp::SHADOW);
154         s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
155
156         shared_ptr<Job> job (new TranscodeJob (film));
157         FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test7.mov", EXPORT_FORMAT_PRORES, false, false, 23);
158         encoder.go ();
159 }
160
161 /** Red / green / blue MP4 -> H264 */
162 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test1)
163 {
164         ffmpeg_content_test(1, "test/data/test.mp4", EXPORT_FORMAT_H264);
165 }
166
167 /** Just subtitles -> H264 */
168 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test2)
169 {
170         shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_h264_test2");
171         film->set_name ("ffmpeg_encoder_h264_test2");
172         film->set_container (Ratio::from_id ("185"));
173         film->set_audio_channels (6);
174
175         shared_ptr<StringTextFileContent> s (new StringTextFileContent (film, "test/data/subrip2.srt"));
176         film->examine_and_add_content (s);
177         BOOST_REQUIRE (!wait_for_jobs ());
178         s->only_text()->set_colour (dcp::Colour (255, 255, 0));
179         s->only_text()->set_effect (dcp::SHADOW);
180         s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
181         film->write_metadata();
182
183         shared_ptr<Job> job (new TranscodeJob (film));
184         FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test2.mp4", EXPORT_FORMAT_H264, false, false, 23);
185         encoder.go ();
186 }
187
188 /** Video + subs -> H264 */
189 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test3)
190 {
191         shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_h264_test3");
192         film->set_name ("ffmpeg_encoder_h264_test3");
193         film->set_container (Ratio::from_id ("185"));
194         film->set_audio_channels (6);
195
196         shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/test.mp4"));
197         film->examine_and_add_content (c);
198         BOOST_REQUIRE (!wait_for_jobs ());
199
200         shared_ptr<StringTextFileContent> s (new StringTextFileContent (film, "test/data/subrip.srt"));
201         film->examine_and_add_content (s);
202         BOOST_REQUIRE (!wait_for_jobs ());
203         s->only_text()->set_colour (dcp::Colour (255, 255, 0));
204         s->only_text()->set_effect (dcp::SHADOW);
205         s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
206         film->write_metadata();
207
208         shared_ptr<Job> job (new TranscodeJob (film));
209         FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test3.mp4", EXPORT_FORMAT_H264, false, false, 23);
210         encoder.go ();
211 }
212
213 /** Scope-in-flat DCP -> H264 */
214 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test4)
215 {
216         shared_ptr<Film> film = new_test_film2("ffmpeg_encoder_h264_test4");
217         film->examine_and_add_content(shared_ptr<DCPContent>(new DCPContent(film, "test/data/scope_dcp")));
218         BOOST_REQUIRE(!wait_for_jobs());
219
220         film->set_container(Ratio::from_id("185"));
221
222         shared_ptr<Job> job(new TranscodeJob(film));
223         FFmpegEncoder encoder(film, job, "build/test/ffmpeg_encoder_h264_test4.mp4", EXPORT_FORMAT_H264, false, false, 23);
224         encoder.go();
225 }
226
227 /** Test mixdown from 5.1 to stereo */
228 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test5)
229 {
230         shared_ptr<Film> film = new_test_film ("ffmpeg_transcoder_h264_test5");
231         film->set_name ("ffmpeg_transcoder_h264_test5");
232         film->set_container (Ratio::from_id ("185"));
233         film->set_audio_channels (6);
234
235         shared_ptr<FFmpegContent> L (new FFmpegContent (film, "test/data/L.wav"));
236         film->examine_and_add_content (L);
237         shared_ptr<FFmpegContent> R (new FFmpegContent (film, "test/data/R.wav"));
238         film->examine_and_add_content (R);
239         shared_ptr<FFmpegContent> C (new FFmpegContent (film, "test/data/C.wav"));
240         film->examine_and_add_content (C);
241         shared_ptr<FFmpegContent> Ls (new FFmpegContent (film, "test/data/Ls.wav"));
242         film->examine_and_add_content (Ls);
243         shared_ptr<FFmpegContent> Rs (new FFmpegContent (film, "test/data/Rs.wav"));
244         film->examine_and_add_content (Rs);
245         shared_ptr<FFmpegContent> Lfe (new FFmpegContent (film, "test/data/Lfe.wav"));
246         film->examine_and_add_content (Lfe);
247         BOOST_REQUIRE (!wait_for_jobs ());
248
249         AudioMapping map (1, MAX_DCP_AUDIO_CHANNELS);
250
251         L->set_position (DCPTime::from_seconds (0));
252         map.make_zero ();
253         map.set (0, 0, 1);
254         L->audio->set_mapping (map);
255         R->set_position (DCPTime::from_seconds (1));
256         map.make_zero ();
257         map.set (0, 1, 1);
258         R->audio->set_mapping (map);
259         C->set_position (DCPTime::from_seconds (2));
260         map.make_zero ();
261         map.set (0, 2, 1);
262         C->audio->set_mapping (map);
263         Lfe->set_position (DCPTime::from_seconds (3));
264         map.make_zero ();
265         map.set (0, 3, 1);
266         Lfe->audio->set_mapping (map);
267         Ls->set_position (DCPTime::from_seconds (4));
268         map.make_zero ();
269         map.set (0, 4, 1);
270         Ls->audio->set_mapping (map);
271         Rs->set_position (DCPTime::from_seconds (5));
272         map.make_zero ();
273         map.set (0, 5, 1);
274         Rs->audio->set_mapping (map);
275
276         shared_ptr<Job> job (new TranscodeJob (film));
277         FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test5.mp4", EXPORT_FORMAT_H264, true, false, 23);
278         encoder.go ();
279
280         check_ffmpeg ("build/test/ffmpeg_encoder_h264_test5.mp4", "test/data/ffmpeg_encoder_h264_test5.mp4", 1);
281 }