Add ProRes LT export option (#2834).
[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 if (format == "prores-lt") {
69                 _format = ExportFormat::PRORES_LT;
70         } else {
71                 _format = ExportFormat::PRORES_HQ;
72         }
73
74         _mixdown_to_stereo = node->bool_child("MixdownToStereo");
75         _split_reels = node->bool_child("SplitReels");
76         _split_streams = node->bool_child("SplitStreams");
77         _x264_crf = node->number_child<int>("X264CRF");
78 }
79
80
81 void
82 ExportConfig::write(xmlpp::Element* element) const
83 {
84         string name;
85
86         switch (_format) {
87                 case ExportFormat::PRORES_4444:
88                         name = "prores-4444";
89                         break;
90                 case ExportFormat::PRORES_HQ:
91                         /* Write this but we also accept 'prores' for backwards compatibility */
92                         name = "prores-hq";
93                         break;
94                 case ExportFormat::PRORES_LT:
95                         name = "prores-lt";
96                         break;
97                 case ExportFormat::H264_AAC:
98                         name = "h264-aac";
99                         break;
100                 case ExportFormat::SUBTITLES_DCP:
101                         name = "subtitles-dcp";
102                         break;
103         }
104
105         cxml::add_text_child(element, "Format", name);
106         cxml::add_text_child(element, "MixdownToStereo", _mixdown_to_stereo ? "1" : "0");
107         cxml::add_text_child(element, "SplitReels", _split_reels ? "1" : "0");
108         cxml::add_text_child(element, "SplitStreams", _split_streams ? "1" : "0");
109         cxml::add_text_child(element, "X264CRF", dcp::raw_convert<string>(_x264_crf));
110 }
111
112
113 void
114 ExportConfig::set_format(ExportFormat format)
115 {
116         _config->maybe_set(_format, format);
117 }
118
119
120 void
121 ExportConfig::set_mixdown_to_stereo(bool mixdown)
122 {
123         _config->maybe_set(_mixdown_to_stereo, mixdown);
124 }
125
126
127 void
128 ExportConfig::set_split_reels(bool split)
129 {
130         _config->maybe_set(_split_reels, split);
131 }
132
133
134 void
135 ExportConfig::set_split_streams(bool split)
136 {
137         _config->maybe_set(_split_streams, split);
138 }
139
140
141 void
142 ExportConfig::set_x264_crf(int crf)
143 {
144         _config->maybe_set(_x264_crf, crf);
145 }