2 Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp 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 libdcp 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 libdcp. If not, see <http://www.gnu.org/licenses/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
35 #include "exceptions.h"
39 #include <boost/optional.hpp>
41 #include <boost/filesystem.hpp>
49 using std::shared_ptr;
51 using boost::optional;
52 using std::dynamic_pointer_cast;
53 #if BOOST_VERSION >= 106100
54 using namespace boost::placeholders;
58 static bool verbose = false;
63 cerr << "Syntax: " << n << " [OPTION] <DCP> <DCP>\n"
64 << " -V, --version show libdcp version\n"
65 << " -h, --help show this help\n"
66 << " -v, --verbose be verbose\n"
67 << " --cpl-annotation-texts allow differing CPL annotation texts\n"
68 << " --reel-annotation-texts allow differing reel annotation texts\n"
69 << " -a, --annotation-texts allow different CPL and reel annotation texts\n"
70 << " -d, --issue-dates allow different issue dates\n"
71 << " -m, --mean-pixel maximum allowed mean pixel error (default 5)\n"
72 << " -s, --std-dev-pixel maximum allowed standard deviation of pixel error (default 5)\n"
73 << " --key hexadecimal key to use to decrypt MXFs\n"
74 << " --ignore-missing-assets ignore missing asset files\n"
75 << " --export-differing-subtitles export the first pair of differing image subtitles to the current working directory\n"
77 << "The <DCP>s are the DCP directories to compare.\n"
78 << "Comparison is of metadata and content, ignoring timestamps\n"
79 << "and differing UUIDs.\n";
83 note (NoteType t, string n)
85 if (t == NoteType::ERROR || verbose) {
86 cout << " " << n << "\n";
93 load_dcp (boost::filesystem::path path, bool ignore_missing_assets, optional<string> key)
98 vector<dcp::VerificationNote> notes;
100 filter_notes (notes, ignore_missing_assets);
101 for (auto i: notes) {
102 cerr << dcp::note_to_string(i) << "\n";
106 auto assets = dcp->assets ();
107 for (auto i: assets) {
108 auto mxf = dynamic_pointer_cast<MXF>(i);
110 mxf->set_key (Key (key.get ()));
115 } catch (FileError& e) {
116 cerr << "Could not read DCP " << path.string() << "; " << e.what() << " " << e.filename() << "\n";
124 main (int argc, char* argv[])
128 EqualityOptions options;
129 options.max_mean_pixel_error = 5;
130 options.max_std_dev_pixel_error = 5;
131 options.reel_hashes_can_differ = true;
132 options.reel_annotation_texts_can_differ = false;
133 bool ignore_missing_assets = false;
134 optional<string> key;
136 int option_index = 0;
138 static struct option long_options[] = {
139 { "version", no_argument, 0, 'V'},
140 { "help", no_argument, 0, 'h'},
141 { "verbose", no_argument, 0, 'v'},
142 { "mean-pixel", required_argument, 0, 'm'},
143 { "std-dev-pixel", required_argument, 0, 's'},
144 { "annotation-texts", no_argument, 0, 'a'},
145 { "issue-dates", no_argument, 0, 'd'},
146 /* From here we're using random capital letters for the short option */
147 { "ignore-missing-assets", no_argument, 0, 'A'},
148 { "cpl-annotation-texts", no_argument, 0, 'C'},
149 { "key", required_argument, 0, 'D'},
150 { "reel-annotation-texts", no_argument, 0, 'E'},
151 { "export-differing-subtitles", no_argument, 0, 'F' },
155 int c = getopt_long (argc, argv, "Vhvm:s:adACD:EF", long_options, &option_index);
163 cout << "dcpdiff version " << LIBDCP_VERSION << "\n";
172 options.max_mean_pixel_error = atof (optarg);
175 options.max_std_dev_pixel_error = atof (optarg);
178 options.cpl_annotation_texts_can_differ = options.reel_annotation_texts_can_differ = true;
181 options.issue_dates_can_differ = true;
184 ignore_missing_assets = true;
188 options.cpl_annotation_texts_can_differ = true;
191 key = string (optarg);
194 options.reel_annotation_texts_can_differ = true;
197 options.export_differing_subtitles = true;
202 if (argc <= (optind + 1) || argc > (optind + 2)) {
207 if (!boost::filesystem::exists (argv[optind])) {
208 cerr << argv[0] << ": DCP " << argv[optind] << " not found.\n";
212 if (!boost::filesystem::exists (argv[optind + 1])) {
213 cerr << argv[0] << ": DCP " << argv[optind + 1] << " not found.\n";
217 DCP* a = load_dcp (argv[optind], ignore_missing_assets, key);
218 DCP* b = load_dcp (argv[optind + 1], ignore_missing_assets, key);
220 /* I think this is just below the LSB at 16-bits (ie the 8th most significant bit at 24-bit) */
221 options.max_audio_sample_error = 255;
223 bool const equals = a->equals (*b, options, boost::bind (note, _1, _2));
225 exit (equals ? EXIT_SUCCESS : EXIT_FAILURE);