2 Copyright (C) 2017 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/audio_content.h"
25 #include "lib/text_subtitle_content.h"
26 #include "lib/ratio.h"
27 #include "lib/transcode_job.h"
28 #include "lib/dcp_content.h"
29 #include "lib/subtitle_content.h"
31 #include <boost/test/unit_test.hpp>
33 using boost::shared_ptr;
35 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_basic_test_mov)
37 shared_ptr<Film> film = new_test_film ("ffmpeg_transcoder_basic_test_mov");
38 film->set_name ("ffmpeg_transcoder_basic_test");
39 shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/test.mp4"));
40 film->set_container (Ratio::from_id ("185"));
41 film->set_audio_channels (6);
43 film->examine_and_add_content (c);
44 BOOST_REQUIRE (!wait_for_jobs ());
46 shared_ptr<Job> job (new TranscodeJob (film));
47 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_basic_test.mov", FFmpegEncoder::FORMAT_PRORES, false);
51 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_basic_test_mp4)
53 shared_ptr<Film> film = new_test_film ("ffmpeg_transcoder_basic_test_mp4");
54 film->set_name ("ffmpeg_transcoder_basic_test");
55 shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/test.mp4"));
56 film->set_container (Ratio::from_id ("185"));
57 film->set_audio_channels (6);
59 film->examine_and_add_content (c);
60 BOOST_REQUIRE (!wait_for_jobs ());
62 shared_ptr<Job> job (new TranscodeJob (film));
63 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_basic_test.mp4", FFmpegEncoder::FORMAT_H264, false);
67 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_basic_test_subs_h264)
69 shared_ptr<Film> film = new_test_film ("ffmpeg_transcoder_basic_test_subs_h264");
70 film->set_name ("ffmpeg_transcoder_basic_test");
71 film->set_container (Ratio::from_id ("185"));
72 film->set_audio_channels (6);
74 shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/test.mp4"));
75 film->examine_and_add_content (c);
76 BOOST_REQUIRE (!wait_for_jobs ());
78 shared_ptr<TextSubtitleContent> s (new TextSubtitleContent (film, "test/data/subrip.srt"));
79 film->examine_and_add_content (s);
80 BOOST_REQUIRE (!wait_for_jobs ());
81 s->subtitle->set_colour (dcp::Colour (255, 255, 0));
82 s->subtitle->set_shadow (true);
83 s->subtitle->set_effect_colour (dcp::Colour (0, 255, 255));
85 shared_ptr<Job> job (new TranscodeJob (film));
86 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_basic_test_subs.mp4", FFmpegEncoder::FORMAT_H264, false);
90 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_basic_test_subs_prores)
92 shared_ptr<Film> film = new_test_film ("ffmpeg_transcoder_basic_test_subs_prores");
93 film->set_name ("ffmpeg_transcoder_basic_test");
94 film->set_container (Ratio::from_id ("185"));
95 film->set_audio_channels (6);
97 shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/test.mp4"));
98 film->examine_and_add_content (c);
99 BOOST_REQUIRE (!wait_for_jobs ());
101 shared_ptr<TextSubtitleContent> s (new TextSubtitleContent (film, "test/data/subrip.srt"));
102 film->examine_and_add_content (s);
103 BOOST_REQUIRE (!wait_for_jobs ());
104 s->subtitle->set_colour (dcp::Colour (255, 255, 0));
105 s->subtitle->set_shadow (true);
106 s->subtitle->set_effect_colour (dcp::Colour (0, 255, 255));
108 shared_ptr<Job> job (new TranscodeJob (film));
109 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_basic_test_subs.mov", FFmpegEncoder::FORMAT_PRORES, false);
113 /** Test a bug with export of scope-in-flat DCP content */
114 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_bug_test_scope)
116 shared_ptr<Film> film = new_test_film2("ffmpeg_encoder_bug_test_scope");
117 film->examine_and_add_content(shared_ptr<DCPContent>(new DCPContent(film, "test/data/scope_dcp")));
118 BOOST_REQUIRE(!wait_for_jobs());
120 film->set_container(Ratio::from_id("185"));
122 shared_ptr<Job> job(new TranscodeJob(film));
123 FFmpegEncoder encoder(film, job, "build/test/ffmpeg_encoder_bug_test_scope.mp4", FFmpegEncoder::FORMAT_H264, false);
127 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_basic_test_mixdown)
129 shared_ptr<Film> film = new_test_film ("ffmpeg_transcoder_basic_test_mixdown");
130 film->set_name ("ffmpeg_transcoder_basic_test");
131 film->set_container (Ratio::from_id ("185"));
132 film->set_audio_channels (6);
134 shared_ptr<FFmpegContent> L (new FFmpegContent (film, "test/data/L.wav"));
135 film->examine_and_add_content (L);
136 shared_ptr<FFmpegContent> R (new FFmpegContent (film, "test/data/R.wav"));
137 film->examine_and_add_content (R);
138 shared_ptr<FFmpegContent> C (new FFmpegContent (film, "test/data/C.wav"));
139 film->examine_and_add_content (C);
140 shared_ptr<FFmpegContent> Ls (new FFmpegContent (film, "test/data/Ls.wav"));
141 film->examine_and_add_content (Ls);
142 shared_ptr<FFmpegContent> Rs (new FFmpegContent (film, "test/data/Rs.wav"));
143 film->examine_and_add_content (Rs);
144 shared_ptr<FFmpegContent> Lfe (new FFmpegContent (film, "test/data/Lfe.wav"));
145 film->examine_and_add_content (Lfe);
146 BOOST_REQUIRE (!wait_for_jobs ());
148 AudioMapping map (1, MAX_DCP_AUDIO_CHANNELS);
150 L->set_position (DCPTime::from_seconds (0));
153 L->audio->set_mapping (map);
154 R->set_position (DCPTime::from_seconds (1));
157 R->audio->set_mapping (map);
158 C->set_position (DCPTime::from_seconds (2));
161 C->audio->set_mapping (map);
162 Lfe->set_position (DCPTime::from_seconds (3));
165 Lfe->audio->set_mapping (map);
166 Ls->set_position (DCPTime::from_seconds (4));
169 Ls->audio->set_mapping (map);
170 Rs->set_position (DCPTime::from_seconds (5));
173 Rs->audio->set_mapping (map);
175 shared_ptr<Job> job (new TranscodeJob (film));
176 FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_basic_test_mixdown.mp4", FFmpegEncoder::FORMAT_H264, true);
179 /* Skip the first video packet when checking as it contains x264 options which can vary between machines
180 (e.g. number of threads used for encoding).
182 check_ffmpeg ("build/test/ffmpeg_encoder_basic_test_mixdown.mp4", "test/data/ffmpeg_encoder_basic_test_mixdown.mp4");