It builds again.
[libdcp.git] / tools / dcpinfo.cc
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <iostream>
21 #include <cstdlib>
22 #include <boost/filesystem.hpp>
23 #include <getopt.h>
24 #include "dcp.h"
25 #include "exceptions.h"
26 #include "reel.h"
27 #include "sound_mxf.h"
28 #include "picture_mxf.h"
29 #include "subtitle_content.h"
30 #include "reel_picture_asset.h"
31 #include "reel_sound_asset.h"
32 #include "reel_subtitle_asset.h"
33 #include "subtitle_string.h"
34 #include "cpl.h"
35
36 using std::string;
37 using std::cerr;
38 using std::cout;
39 using std::list;
40 using boost::shared_ptr;
41 using namespace dcp;
42
43 static void
44 help (string n)
45 {
46         cerr << "Syntax: " << n << " [options] <DCP>\n"
47              << "  -s, --subtitles  list all subtitles\n";
48 }
49
50 int
51 main (int argc, char* argv[])
52 {
53         bool subtitles = false;
54         
55         int option_index = 0;
56         while (1) {
57                 static struct option long_options[] = {
58                         { "version", no_argument, 0, 'v'},
59                         { "help", no_argument, 0, 'h'},
60                         { "subtitles", no_argument, 0, 's'},
61                         { 0, 0, 0, 0 }
62                 };
63
64                 int c = getopt_long (argc, argv, "vhs", long_options, &option_index);
65
66                 if (c == -1) {
67                         break;
68                 }
69
70                 switch (c) {
71                 case 'v':
72                         cout << "dcpdiff version " << LIBDCP_VERSION << "\n";
73                         exit (EXIT_SUCCESS);
74                 case 'h':
75                         help (argv[0]);
76                         exit (EXIT_SUCCESS);
77                 case 's':
78                         subtitles = true;
79                         break;
80                 }
81         }
82
83         if (argc <= optind || argc > (optind + 1)) {
84                 help (argv[0]);
85                 exit (EXIT_FAILURE);
86         }
87
88         if (!boost::filesystem::exists (argv[optind])) {
89                 cerr << argv[0] << ": DCP " << argv[optind] << " not found.\n";
90                 exit (EXIT_FAILURE);
91         }
92
93         DCP* dcp = 0;
94         try {
95                 dcp = new DCP (argv[optind]);
96                 dcp->read ();
97         } catch (FileError& e) {
98                 cerr << "Could not read DCP " << argv[optind] << "; " << e.what() << " " << e.filename() << "\n";
99                 exit (EXIT_FAILURE);
100         }
101
102         cout << "DCP: " << argv[optind] << "\n";
103
104         list<shared_ptr<CPL> > cpls = dcp->cpls ();
105
106         for (list<shared_ptr<CPL> >::iterator i = cpls.begin(); i != cpls.end(); ++i) {
107                 cout << "  CPL: " << (*i)->annotation_text() << "\n";
108                 
109                 list<shared_ptr<Reel> > reels = (*i)->reels ();
110
111                 int R = 1;
112                 for (list<shared_ptr<Reel> >::const_iterator j = reels.begin(); j != reels.end(); ++j) {
113                         cout << "    Reel " << R << "\n";
114                         
115                         if ((*j)->main_picture()) {
116                                 cout << "      Picture:  "
117                                      << (*j)->main_picture()->mxf()->size().width
118                                      << "x"
119                                      << (*j)->main_picture()->mxf()->size().height << "\n";
120                         }
121                         if ((*j)->main_sound()) {
122                                 cout << "      Sound:    "
123                                      << (*j)->main_sound()->mxf()->channels()
124                                      << " channels at "
125                                      << (*j)->main_sound()->mxf()->sampling_rate() << "Hz\n";
126                         }
127                         if ((*j)->main_subtitle()) {
128                                 list<shared_ptr<SubtitleString> > subs = (*j)->main_subtitle()->subtitle_content()->subtitles ();
129                                 cout << "      Subtitle: " << subs.size() << " subtitles in " << (*j)->main_subtitle()->subtitle_content()->language() << "\n";
130                                 if (subtitles) {
131                                         for (list<shared_ptr<SubtitleString> >::const_iterator k = subs.begin(); k != subs.end(); ++k) {
132                                                 cout << "        " << (*k)->text() << "\n";
133                                                 cout << "          "
134                                                      << "font:" << (*k)->font() << "; "
135                                                      << "italic:" << (*k)->italic() << "; "
136                                                      << "color:" << (*k)->color() << "; "
137                                                      << "in:" << (*k)->in() << "; "
138                                                      << "out:" << (*k)->out() << "; "
139                                                      << "v_position:" << (*k)->v_position() << "; "
140                                                      << "v_align:" << (*k)->v_align() << "; "
141                                                      << "effect:" << (*k)->effect() << "; "
142                                                      << "effect_color:" << (*k)->effect_color() << "; "
143                                                      << "fade_up_time:" << (*k)->fade_up_time() << "; "
144                                                      << "fade_down_time:" << (*k)->fade_down_time() << "; "
145                                                      << "size: " << (*k)->size() << "\n";
146                                         }
147                                 }
148                         }
149                         ++R;
150                 }
151         }
152
153         return 0;
154 }