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"
37 #include "sound_asset.h"
38 #include "picture_asset.h"
39 #include "subtitle_asset.h"
40 #include "reel_picture_asset.h"
41 #include "reel_sound_asset.h"
42 #include "reel_subtitle_asset.h"
43 #include "subtitle_string.h"
44 #include "interop_subtitle_asset.h"
45 #include "smpte_subtitle_asset.h"
49 #include <boost/filesystem.hpp>
50 #include <boost/foreach.hpp>
58 using boost::shared_ptr;
59 using boost::dynamic_pointer_cast;
65 cerr << "Syntax: " << n << " [options] [<DCP>] [<CPL>]\n"
66 << " -s, --subtitles list all subtitles\n"
67 << " -k, --keep-going carry on in the event of errors, if possible\n"
68 << " --ignore-missing-assets ignore missing asset files\n";
72 main_picture (shared_ptr<Reel> reel)
74 if (reel->main_picture()) {
75 cout << " Picture ID: " << reel->main_picture()->id()
76 << " entry " << reel->main_picture()->entry_point()
77 << " duration " << reel->main_picture()->duration()
78 << " intrinsic " << reel->main_picture()->intrinsic_duration() << "\n";
79 if (reel->main_picture()->asset()) {
81 << reel->main_picture()->asset()->size().width
83 << reel->main_picture()->asset()->size().height << "\n";
89 main_sound (shared_ptr<Reel> reel)
91 if (reel->main_sound()) {
92 cout << " Sound ID: " << reel->main_sound()->id()
93 << " entry " << reel->main_picture()->entry_point()
94 << " duration " << reel->main_picture()->duration()
95 << " intrinsic " << reel->main_picture()->intrinsic_duration() << "\n";
96 if (reel->main_sound()->asset()) {
98 << reel->main_sound()->asset()->channels()
100 << reel->main_sound()->asset()->sampling_rate() << "Hz\n";
106 main_subtitle (shared_ptr<Reel> reel, bool list_subtitles)
108 if (!reel->main_subtitle()) {
112 cout << " Subtitle ID: " << reel->main_subtitle()->id() << "\n";
114 list<SubtitleString> subs = reel->main_subtitle()->asset()->subtitles ();
115 cout << " Subtitle: " << subs.size() << " subtitles";
116 shared_ptr<InteropSubtitleAsset> iop = dynamic_pointer_cast<InteropSubtitleAsset> (reel->main_subtitle()->asset());
118 cout << " in " << iop->language() << "\n";
120 shared_ptr<SMPTESubtitleAsset> smpte = dynamic_pointer_cast<SMPTESubtitleAsset> (reel->main_subtitle()->asset());
121 if (smpte && smpte->language ()) {
122 cout << " in " << smpte->language().get() << "\n";
124 if (list_subtitles) {
125 BOOST_FOREACH (SubtitleString const& k, subs) {
132 main (int argc, char* argv[])
134 bool subtitles = false;
135 bool keep_going = false;
136 bool ignore_missing_assets = false;
138 int option_index = 0;
140 static struct option long_options[] = {
141 { "version", no_argument, 0, 'v' },
142 { "help", no_argument, 0, 'h' },
143 { "subtitles", no_argument, 0, 's' },
144 { "keep-going", no_argument, 0, 'k' },
145 { "ignore-missing-assets", no_argument, 0, 'A' },
149 int c = getopt_long (argc, argv, "vhskA", long_options, &option_index);
157 cout << "libdcp version " << LIBDCP_VERSION << "\n";
169 ignore_missing_assets = true;
174 if (argc <= optind || argc > (optind + 1)) {
179 if (!boost::filesystem::exists (argv[optind])) {
180 cerr << argv[0] << ": DCP or CPL " << argv[optind] << " not found.\n";
184 list<shared_ptr<CPL> > cpls;
185 if (boost::filesystem::is_directory(argv[optind])) {
187 DCP::ReadErrors errors;
189 dcp = new DCP (argv[optind]);
190 dcp->read (keep_going, &errors);
191 } catch (FileError& e) {
192 cerr << "Could not read DCP " << argv[optind] << "; " << e.what() << "\n";
194 } catch (DCPReadError& e) {
195 cerr << "Could not read DCP " << argv[optind] << "; " << e.what() << "\n";
199 cout << "DCP: " << boost::filesystem::path(argv[optind]).string() << "\n";
201 dcp::filter_errors (errors, ignore_missing_assets);
202 for (DCP::ReadErrors::const_iterator i = errors.begin(); i != errors.end(); ++i) {
203 cerr << "Error: " << (*i)->what() << "\n";
208 cpls.push_back (shared_ptr<CPL>(new CPL(boost::filesystem::path(argv[optind]))));
210 ignore_missing_assets = true;
213 BOOST_FOREACH (shared_ptr<CPL> i, cpls) {
214 cout << " CPL: " << i->annotation_text() << "\n";
217 BOOST_FOREACH (shared_ptr<Reel> j, i->reels()) {
218 cout << " Reel " << R << "\n";
222 } catch (UnresolvedRefError& e) {
224 if (!ignore_missing_assets) {
225 cerr << e.what() << " (for main picture)\n";
234 } catch (UnresolvedRefError& e) {
236 if (!ignore_missing_assets) {
237 cerr << e.what() << " (for main sound)\n";
245 main_subtitle (j, subtitles);
246 } catch (UnresolvedRefError& e) {
248 if (!ignore_missing_assets) {
249 cerr << e.what() << " (for main subtitle)\n";