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