Add a test for #1129.
[dcpomatic.git] / test / ffmpeg_encoder_test.cc
1 /*
2     Copyright (C) 2017 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/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 "test.h"
30 #include <boost/test/unit_test.hpp>
31
32 using boost::shared_ptr;
33
34 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_basic_test_mov)
35 {
36         shared_ptr<Film> film = new_test_film ("ffmpeg_transcoder_basic_test_mov");
37         film->set_name ("ffmpeg_transcoder_basic_test");
38         shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/test.mp4"));
39         film->set_container (Ratio::from_id ("185"));
40         film->set_audio_channels (6);
41
42         film->examine_and_add_content (c);
43         BOOST_REQUIRE (!wait_for_jobs ());
44
45         shared_ptr<Job> job (new TranscodeJob (film));
46         FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_basic_test.mov", FFmpegEncoder::FORMAT_PRORES, false);
47         encoder.go ();
48 }
49
50 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_basic_test_mp4)
51 {
52         shared_ptr<Film> film = new_test_film ("ffmpeg_transcoder_basic_test_mp4");
53         film->set_name ("ffmpeg_transcoder_basic_test");
54         shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/test.mp4"));
55         film->set_container (Ratio::from_id ("185"));
56         film->set_audio_channels (6);
57
58         film->examine_and_add_content (c);
59         BOOST_REQUIRE (!wait_for_jobs ());
60
61         shared_ptr<Job> job (new TranscodeJob (film));
62         FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_basic_test.mp4", FFmpegEncoder::FORMAT_H264, false);
63         encoder.go ();
64 }
65
66 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_basic_test_subs)
67 {
68         shared_ptr<Film> film = new_test_film ("ffmpeg_transcoder_basic_test_subs");
69         film->set_name ("ffmpeg_transcoder_basic_test");
70         film->set_container (Ratio::from_id ("185"));
71         film->set_audio_channels (6);
72
73         shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/test.mp4"));
74         film->examine_and_add_content (c);
75         BOOST_REQUIRE (!wait_for_jobs ());
76
77         shared_ptr<TextSubtitleContent> s (new TextSubtitleContent (film, "test/data/subrip.srt"));
78         film->examine_and_add_content (s);
79         BOOST_REQUIRE (!wait_for_jobs ());
80
81         shared_ptr<Job> job (new TranscodeJob (film));
82         FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_basic_test_subs.mp4", FFmpegEncoder::FORMAT_H264, false);
83         encoder.go ();
84 }
85
86 /** Test a bug with export of scope-in-flat DCP content */
87 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_bug_test_scope)
88 {
89         shared_ptr<Film> film = new_test_film2("ffmpeg_encoder_bug_test_scope");
90         film->examine_and_add_content(shared_ptr<DCPContent>(new DCPContent(film, "test/data/scope_dcp")));
91         BOOST_REQUIRE(!wait_for_jobs());
92
93         film->set_container(Ratio::from_id("185"));
94
95         shared_ptr<Job> job(new TranscodeJob(film));
96         FFmpegEncoder encoder(film, job, "build/test/ffmpeg_encoder_bug_test_scope.mp4", FFmpegEncoder::FORMAT_H264, false);
97         encoder.go();
98 }
99
100 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_basic_test_mixdown)
101 {
102         shared_ptr<Film> film = new_test_film ("ffmpeg_transcoder_basic_test_mixdown");
103         film->set_name ("ffmpeg_transcoder_basic_test");
104         film->set_container (Ratio::from_id ("185"));
105         film->set_audio_channels (6);
106
107         shared_ptr<FFmpegContent> L (new FFmpegContent (film, "test/data/L.wav"));
108         film->examine_and_add_content (L);
109         shared_ptr<FFmpegContent> R (new FFmpegContent (film, "test/data/R.wav"));
110         film->examine_and_add_content (R);
111         shared_ptr<FFmpegContent> C (new FFmpegContent (film, "test/data/C.wav"));
112         film->examine_and_add_content (C);
113         shared_ptr<FFmpegContent> Ls (new FFmpegContent (film, "test/data/Ls.wav"));
114         film->examine_and_add_content (Ls);
115         shared_ptr<FFmpegContent> Rs (new FFmpegContent (film, "test/data/Rs.wav"));
116         film->examine_and_add_content (Rs);
117         shared_ptr<FFmpegContent> Lfe (new FFmpegContent (film, "test/data/Lfe.wav"));
118         film->examine_and_add_content (Lfe);
119         BOOST_REQUIRE (!wait_for_jobs ());
120
121         AudioMapping map (1, MAX_DCP_AUDIO_CHANNELS);
122
123         L->set_position (DCPTime::from_seconds (0));
124         map.make_zero ();
125         map.set (0, 0, 1);
126         L->audio->set_mapping (map);
127         R->set_position (DCPTime::from_seconds (1));
128         map.make_zero ();
129         map.set (0, 1, 1);
130         R->audio->set_mapping (map);
131         C->set_position (DCPTime::from_seconds (2));
132         map.make_zero ();
133         map.set (0, 2, 1);
134         C->audio->set_mapping (map);
135         Lfe->set_position (DCPTime::from_seconds (3));
136         map.make_zero ();
137         map.set (0, 3, 1);
138         Lfe->audio->set_mapping (map);
139         Ls->set_position (DCPTime::from_seconds (4));
140         map.make_zero ();
141         map.set (0, 4, 1);
142         Ls->audio->set_mapping (map);
143         Rs->set_position (DCPTime::from_seconds (5));
144         map.make_zero ();
145         map.set (0, 5, 1);
146         Rs->audio->set_mapping (map);
147
148         shared_ptr<Job> job (new TranscodeJob (film));
149         FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_basic_test_mixdown.mp4", FFmpegEncoder::FORMAT_H264, true);
150         encoder.go ();
151
152         /* Skip the first video packet when checking as it contains x264 options which can vary between machines
153            (e.g. number of threads used for encoding).
154         */
155         check_ffmpeg ("build/test/ffmpeg_encoder_basic_test_mixdown.mp4", "test/data/ffmpeg_encoder_basic_test_mixdown.mp4");
156 }