Add Prores 4444 support (#2263).
[dcpomatic.git] / src / lib / export_config.cc
1 /*
2     Copyright (C) 2022 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
22 #include "config.h"
23 #include "export_config.h"
24 #include <dcp/raw_convert.h>
25 #include <dcp/warnings.h>
26 LIBDCP_DISABLE_WARNINGS
27 #include <libxml++/libxml++.h>
28 LIBDCP_ENABLE_WARNINGS
29
30
31 using std::string;
32
33
34 ExportConfig::ExportConfig(Config* parent)
35         : _config(parent)
36 {
37
38 }
39
40
41 void
42 ExportConfig::set_defaults()
43 {
44         _format = ExportFormat::PRORES_HQ;
45         _mixdown_to_stereo = false;
46         _split_reels = false;
47         _split_streams = false;
48         _x264_crf = 23;
49 }
50
51
52 void
53 ExportConfig::read(cxml::ConstNodePtr node)
54 {
55         if (!node) {
56                 set_defaults();
57                 return;
58         }
59
60         auto const format = node->string_child("Format");
61
62         if (format == "subtitles-dcp") {
63                 _format = ExportFormat::SUBTITLES_DCP;
64         } else if (format == "h264-aac") {
65                 _format = ExportFormat::H264_AAC;
66         } else if (format == "prores-4444") {
67                 _format = ExportFormat::PRORES_4444;
68         } else {
69                 _format = ExportFormat::PRORES_HQ;
70         }
71
72         _mixdown_to_stereo = node->bool_child("MixdownToStereo");
73         _split_reels = node->bool_child("SplitReels");
74         _split_streams = node->bool_child("SplitStreams");
75         _x264_crf = node->number_child<int>("X264CRF");
76 }
77
78
79 void
80 ExportConfig::write(xmlpp::Element* node) const
81 {
82         string name;
83
84         switch (_format) {
85                 case ExportFormat::PRORES_4444:
86                         name = "prores-4444";
87                         break;
88                 case ExportFormat::PRORES_HQ:
89                         /* Write this but we also accept 'prores' for backwards compatibility */
90                         name = "prores-hq";
91                         break;
92                 case ExportFormat::H264_AAC:
93                         name = "h264-aac";
94                         break;
95                 case ExportFormat::SUBTITLES_DCP:
96                         name = "subtitles-dcp";
97                         break;
98         }
99
100         node->add_child("Format")->add_child_text(name);
101         node->add_child("MixdownToStereo")->add_child_text(_mixdown_to_stereo ? "1" : "0");
102         node->add_child("SplitReels")->add_child_text(_split_reels ? "1" : "0");
103         node->add_child("SplitStreams")->add_child_text(_split_streams ? "1" : "0");
104         node->add_child("X264CRF")->add_child_text(dcp::raw_convert<string>(_x264_crf));
105 }
106
107
108 void
109 ExportConfig::set_format(ExportFormat format)
110 {
111         _config->maybe_set(_format, format);
112 }
113
114
115 void
116 ExportConfig::set_mixdown_to_stereo(bool mixdown)
117 {
118         _config->maybe_set(_mixdown_to_stereo, mixdown);
119 }
120
121
122 void
123 ExportConfig::set_split_reels(bool split)
124 {
125         _config->maybe_set(_split_reels, split);
126 }
127
128
129 void
130 ExportConfig::set_split_streams(bool split)
131 {
132         _config->maybe_set(_split_streams, split);
133 }
134
135
136 void
137 ExportConfig::set_x264_crf(int crf)
138 {
139         _config->maybe_set(_x264_crf, crf);
140 }
141