2 Copyright (C) 2017-2018 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/video_content.h"
25 #include "lib/audio_content.h"
26 #include "lib/text_subtitle_content.h"
27 #include "lib/ratio.h"
28 #include "lib/transcode_job.h"
29 #include "lib/dcp_content.h"
30 #include "lib/subtitle_content.h"
31 #include "lib/compose.hpp"
33 #include <boost/test/unit_test.hpp>
36 using boost::shared_ptr;
39 ffmpeg_content_test (int number, boost::filesystem::path content, FFmpegEncoder::Format format)
41 string name = "ffmpeg_encoder_";
44 case FFmpegEncoder::FORMAT_H264:
48 case FFmpegEncoder::FORMAT_PRORES:
54 name = String::compose("%1_test%2", name, number);
56 shared_ptr<Film> film = new_test_film (name);
57 film->set_name (name);
58 shared_ptr<FFmpegContent> c (new FFmpegContent (film, content));
59 film->set_container (Ratio::from_id ("185"));
60 film->set_audio_channels (6);
62 film->examine_and_add_content (c);
63 BOOST_REQUIRE (!wait_for_jobs ());
65 shared_ptr<Job> job (new TranscodeJob (film));
66 FFmpegEncoder encoder (film, job, String::compose("build/test/%1.%2", name, extension), format, false);
70 /** Red / green / blue MP4 -> Prores */
71 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test1)
73 ffmpeg_content_test (1, "test/data/test.mp4", FFmpegEncoder::FORMAT_PRORES);
76 /** Dolby Aurora trailer VOB -> Prores */
77 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test2)
79 ffmpeg_content_test (2, private_data / "dolby_aurora.vob", FFmpegEncoder::FORMAT_PRORES);
82 /** Sintel trailer -> Prores */
83 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test3)
85 ffmpeg_content_test (3, private_data / "Sintel_Trailer1.480p.DivX_Plus_HD.mkv", FFmpegEncoder::FORMAT_PRORES);
88 /** Big Buck Bunny trailer -> Prores */
89 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test4)
91 ffmpeg_content_test (4, private_data / "big_buck_bunny_trailer_480p.mov", FFmpegEncoder::FORMAT_PRORES);
94 /** Still image -> Prores */
95 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test5)
97 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test5");
98 film->set_name ("ffmpeg_encoder_prores_test5");
99 shared_ptr<FFmpegContent> c (new FFmpegContent (film, private_data / "bbc405.png"));
100 film->set_container (Ratio::from_id ("185"));
101 film->set_audio_channels (6);
103 film->examine_and_add_content (c);
104 BOOST_REQUIRE (!wait_for_jobs ());
106 c->video->set_length (240);
108 shared_ptr<Job> job (new TranscodeJob (film));
109 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test5.mov", FFmpegEncoder::FORMAT_PRORES, false);
113 /** Subs -> Prores */
114 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test6)
116 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test6");
117 film->set_name ("ffmpeg_encoder_prores_test6");
118 film->set_container (Ratio::from_id ("185"));
119 film->set_audio_channels (6);
121 shared_ptr<TextSubtitleContent> s (new TextSubtitleContent (film, "test/data/subrip2.srt"));
122 film->examine_and_add_content (s);
123 BOOST_REQUIRE (!wait_for_jobs ());
124 s->subtitle->set_colour (dcp::Colour (255, 255, 0));
125 s->subtitle->set_effect (dcp::SHADOW);
126 s->subtitle->set_effect_colour (dcp::Colour (0, 255, 255));
127 film->write_metadata();
129 shared_ptr<Job> job (new TranscodeJob (film));
130 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test6.mov", FFmpegEncoder::FORMAT_PRORES, false);
134 /** Video + subs -> Prores */
135 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test7)
137 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test7");
138 film->set_name ("ffmpeg_encoder_prores_test7");
139 film->set_container (Ratio::from_id ("185"));
140 film->set_audio_channels (6);
142 shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/test.mp4"));
143 film->examine_and_add_content (c);
144 BOOST_REQUIRE (!wait_for_jobs ());
146 shared_ptr<TextSubtitleContent> s (new TextSubtitleContent (film, "test/data/subrip.srt"));
147 film->examine_and_add_content (s);
148 BOOST_REQUIRE (!wait_for_jobs ());
149 s->subtitle->set_colour (dcp::Colour (255, 255, 0));
150 s->subtitle->set_effect (dcp::SHADOW);
151 s->subtitle->set_effect_colour (dcp::Colour (0, 255, 255));
153 shared_ptr<Job> job (new TranscodeJob (film));
154 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test7.mov", FFmpegEncoder::FORMAT_PRORES, false);
158 /** Red / green / blue MP4 -> H264 */
159 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test1)
161 ffmpeg_content_test(1, "test/data/test.mp4", FFmpegEncoder::FORMAT_H264);
164 /** Just subtitles -> H264 */
165 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test2)
167 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_h264_test2");
168 film->set_name ("ffmpeg_encoder_h264_test2");
169 film->set_container (Ratio::from_id ("185"));
170 film->set_audio_channels (6);
172 shared_ptr<TextSubtitleContent> s (new TextSubtitleContent (film, "test/data/subrip2.srt"));
173 film->examine_and_add_content (s);
174 BOOST_REQUIRE (!wait_for_jobs ());
175 s->subtitle->set_colour (dcp::Colour (255, 255, 0));
176 s->subtitle->set_effect (dcp::SHADOW);
177 s->subtitle->set_effect_colour (dcp::Colour (0, 255, 255));
178 film->write_metadata();
180 shared_ptr<Job> job (new TranscodeJob (film));
181 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test2.mp4", FFmpegEncoder::FORMAT_H264, false);
185 /** Video + subs -> H264 */
186 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test3)
188 shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_h264_test3");
189 film->set_name ("ffmpeg_encoder_h264_test3");
190 film->set_container (Ratio::from_id ("185"));
191 film->set_audio_channels (6);
193 shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/test.mp4"));
194 film->examine_and_add_content (c);
195 BOOST_REQUIRE (!wait_for_jobs ());
197 shared_ptr<TextSubtitleContent> s (new TextSubtitleContent (film, "test/data/subrip.srt"));
198 film->examine_and_add_content (s);
199 BOOST_REQUIRE (!wait_for_jobs ());
200 s->subtitle->set_colour (dcp::Colour (255, 255, 0));
201 s->subtitle->set_effect (dcp::SHADOW);
202 s->subtitle->set_effect_colour (dcp::Colour (0, 255, 255));
203 film->write_metadata();
205 shared_ptr<Job> job (new TranscodeJob (film));
206 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test3.mp4", FFmpegEncoder::FORMAT_H264, false);
210 /** Scope-in-flat DCP -> H264 */
211 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test4)
213 shared_ptr<Film> film = new_test_film2("ffmpeg_encoder_h264_test4");
214 film->examine_and_add_content(shared_ptr<DCPContent>(new DCPContent(film, "test/data/scope_dcp")));
215 BOOST_REQUIRE(!wait_for_jobs());
217 film->set_container(Ratio::from_id("185"));
219 shared_ptr<Job> job(new TranscodeJob(film));
220 FFmpegEncoder encoder(film, job, "build/test/ffmpeg_encoder_h264_test4.mp4", FFmpegEncoder::FORMAT_H264, false);
224 /** Test mixdown from 5.1 to stereo */
225 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test5)
227 shared_ptr<Film> film = new_test_film ("ffmpeg_transcoder_h264_test5");
228 film->set_name ("ffmpeg_transcoder_h264_test5");
229 film->set_container (Ratio::from_id ("185"));
230 film->set_audio_channels (6);
232 shared_ptr<FFmpegContent> L (new FFmpegContent (film, "test/data/L.wav"));
233 film->examine_and_add_content (L);
234 shared_ptr<FFmpegContent> R (new FFmpegContent (film, "test/data/R.wav"));
235 film->examine_and_add_content (R);
236 shared_ptr<FFmpegContent> C (new FFmpegContent (film, "test/data/C.wav"));
237 film->examine_and_add_content (C);
238 shared_ptr<FFmpegContent> Ls (new FFmpegContent (film, "test/data/Ls.wav"));
239 film->examine_and_add_content (Ls);
240 shared_ptr<FFmpegContent> Rs (new FFmpegContent (film, "test/data/Rs.wav"));
241 film->examine_and_add_content (Rs);
242 shared_ptr<FFmpegContent> Lfe (new FFmpegContent (film, "test/data/Lfe.wav"));
243 film->examine_and_add_content (Lfe);
244 BOOST_REQUIRE (!wait_for_jobs ());
246 AudioMapping map (1, MAX_DCP_AUDIO_CHANNELS);
248 L->set_position (DCPTime::from_seconds (0));
251 L->audio->set_mapping (map);
252 R->set_position (DCPTime::from_seconds (1));
255 R->audio->set_mapping (map);
256 C->set_position (DCPTime::from_seconds (2));
259 C->audio->set_mapping (map);
260 Lfe->set_position (DCPTime::from_seconds (3));
263 Lfe->audio->set_mapping (map);
264 Ls->set_position (DCPTime::from_seconds (4));
267 Ls->audio->set_mapping (map);
268 Rs->set_position (DCPTime::from_seconds (5));
271 Rs->audio->set_mapping (map);
273 shared_ptr<Job> job (new TranscodeJob (film));
274 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test5.mp4", FFmpegEncoder::FORMAT_H264, true);
277 check_ffmpeg ("build/test/ffmpeg_encoder_h264_test5.mp4", "test/data/ffmpeg_encoder_h264_test5.mp4", 1);