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/>.
21 #include "exceptions.h"
23 #include "sound_asset.h"
24 #include "picture_asset.h"
25 #include "subtitle_asset.h"
26 #include "reel_picture_asset.h"
27 #include "reel_sound_asset.h"
28 #include "reel_subtitle_asset.h"
29 #include "subtitle_string.h"
30 #include "interop_subtitle_asset.h"
31 #include "smpte_subtitle_asset.h"
35 #include <boost/filesystem.hpp>
36 #include <boost/foreach.hpp>
44 using boost::shared_ptr;
45 using boost::dynamic_pointer_cast;
51 cerr << "Syntax: " << n << " [options] <DCP>\n"
52 << " -s, --subtitles list all subtitles\n"
53 << " -k, --keep-going carry on in the event of errors, if possible\n"
54 << " --ignore-missing-assets ignore missing asset files\n";
58 main_picture (shared_ptr<Reel> reel)
60 if (reel->main_picture() && reel->main_picture()->asset()) {
62 << reel->main_picture()->asset()->size().width
64 << reel->main_picture()->asset()->size().height << "\n";
69 main_sound (shared_ptr<Reel> reel)
71 if (reel->main_sound() && reel->main_sound()->asset()) {
73 << reel->main_sound()->asset()->channels()
75 << reel->main_sound()->asset()->sampling_rate() << "Hz\n";
80 main_subtitle (shared_ptr<Reel> reel, bool list_subtitles)
82 if (!reel->main_subtitle()) {
86 list<SubtitleString> subs = reel->main_subtitle()->asset()->subtitles ();
87 cout << " Subtitle: " << subs.size() << " subtitles";
88 shared_ptr<InteropSubtitleAsset> iop = dynamic_pointer_cast<InteropSubtitleAsset> (reel->main_subtitle()->asset());
90 cout << " in " << iop->language() << "\n";
92 shared_ptr<SMPTESubtitleAsset> smpte = dynamic_pointer_cast<SMPTESubtitleAsset> (reel->main_subtitle()->asset());
93 if (smpte && smpte->language ()) {
94 cout << " in " << smpte->language().get() << "\n";
97 BOOST_FOREACH (SubtitleString const& k, subs) {
104 main (int argc, char* argv[])
106 bool subtitles = false;
107 bool keep_going = false;
108 bool ignore_missing_assets = false;
110 int option_index = 0;
112 static struct option long_options[] = {
113 { "version", no_argument, 0, 'v' },
114 { "help", no_argument, 0, 'h' },
115 { "subtitles", no_argument, 0, 's' },
116 { "keep-going", no_argument, 0, 'k' },
117 { "ignore-missing-assets", no_argument, 0, 'A' },
121 int c = getopt_long (argc, argv, "vhskA", long_options, &option_index);
129 cout << "dcpdiff version " << LIBDCP_VERSION << "\n";
141 ignore_missing_assets = true;
146 if (argc <= optind || argc > (optind + 1)) {
151 if (!boost::filesystem::exists (argv[optind])) {
152 cerr << argv[0] << ": DCP " << argv[optind] << " not found.\n";
157 DCP::ReadErrors errors;
159 dcp = new DCP (argv[optind]);
160 dcp->read (keep_going, &errors);
161 } catch (FileError& e) {
162 cerr << "Could not read DCP " << argv[optind] << "; " << e.what() << "\n";
164 } catch (DCPReadError& e) {
165 cerr << "Could not read DCP " << argv[optind] << "; " << e.what() << "\n";
169 cout << "DCP: " << boost::filesystem::path(argv[optind]).filename().string() << "\n";
171 dcp::filter_errors (errors, ignore_missing_assets);
172 for (DCP::ReadErrors::const_iterator i = errors.begin(); i != errors.end(); ++i) {
173 cerr << "Error: " << (*i)->what() << "\n";
176 list<shared_ptr<CPL> > cpls = dcp->cpls ();
178 for (list<shared_ptr<CPL> >::iterator i = cpls.begin(); i != cpls.end(); ++i) {
179 cout << " CPL: " << (*i)->annotation_text() << "\n";
181 list<shared_ptr<Reel> > reels = (*i)->reels ();
184 for (list<shared_ptr<Reel> >::const_iterator j = reels.begin(); j != reels.end(); ++j) {
185 cout << " Reel " << R << "\n";
189 } catch (UnresolvedRefError& e) {
191 if (!ignore_missing_assets) {
192 cerr << e.what() << " (for main picture)\n";
201 } catch (UnresolvedRefError& e) {
203 if (!ignore_missing_assets) {
204 cerr << e.what() << " (for main sound)\n";
212 main_subtitle (*j, subtitles);
213 } catch (UnresolvedRefError& e) {
215 if (!ignore_missing_assets) {
216 cerr << e.what() << " (for main subtitle)\n";