Somewhat hacky rearrangement to support multiple CPLs per DCP.
[libdcp.git] / tools / dcpinfo.cc
1 #include <iostream>
2 #include <cstdlib>
3 #include <boost/filesystem.hpp>
4 #include <getopt.h>
5 #include "dcp.h"
6 #include "exceptions.h"
7 #include "reel.h"
8 #include "sound_asset.h"
9 #include "picture_asset.h"
10 #include "subtitle_asset.h"
11
12 using namespace std;
13 using namespace boost;
14 using namespace libdcp;
15
16 static void
17 help (string n)
18 {
19         cerr << "Syntax: " << n << " <DCP>\n";
20 }
21
22 int
23 main (int argc, char* argv[])
24 {
25         int option_index = 0;
26         while (1) {
27                 static struct option long_options[] = {
28                         { "version", no_argument, 0, 'v'},
29                         { "help", no_argument, 0, 'h'},
30                         { 0, 0, 0, 0 }
31                 };
32
33                 int c = getopt_long (argc, argv, "vh", long_options, &option_index);
34
35                 if (c == -1) {
36                         break;
37                 }
38
39                 switch (c) {
40                 case 'v':
41                         cout << "dcpdiff version " << LIBDCP_VERSION << "\n";
42                         exit (EXIT_SUCCESS);
43                 case 'h':
44                         help (argv[0]);
45                         exit (EXIT_SUCCESS);
46                 }
47         }
48
49         if (argc <= optind || argc > (optind + 1)) {
50                 help (argv[0]);
51                 exit (EXIT_FAILURE);
52         }
53
54         if (!filesystem::exists (argv[optind])) {
55                 cerr << argv[0] << ": DCP " << argv[optind] << " not found.\n";
56                 exit (EXIT_FAILURE);
57         }
58
59         DCP* dcp = 0;
60         try {
61                 dcp = new DCP (argv[optind]);
62                 dcp->read (false);
63         } catch (FileError& e) {
64                 cerr << "Could not read DCP " << argv[optind] << "; " << e.what() << " " << e.filename() << "\n";
65                 exit (EXIT_FAILURE);
66         }
67
68         cout << "DCP: " << argv[optind] << "\n";
69
70         list<shared_ptr<const CPL> > cpls = dcp->cpls ();
71
72         for (list<shared_ptr<const CPL> >::iterator i = cpls.begin(); i != cpls.end(); ++i) {
73                 cout << "  CPL: " << (*i)->name() << "\n"
74                      << "    Length: " << (*i)->length() << "\n"
75                      << "    Frames per second: " << (*i)->frames_per_second() << "\n";
76                 
77                 list<shared_ptr<const Reel> > reels = (*i)->reels ();
78
79                 int R = 1;
80                 for (list<shared_ptr<const Reel> >::const_iterator j = reels.begin(); j != reels.end(); ++j) {
81                         cout << "    Reel " << R << "\n";
82                         
83                         if ((*j)->main_picture()) {
84                                 cout << "      Picture:  " << (*j)->main_picture()->width() << "x" << (*j)->main_picture()->height() << "\n";
85                         }
86                         if ((*j)->main_sound()) {
87                                 cout << "      Sound:    " << (*j)->main_sound()->channels() << " channels at " << (*j)->main_sound()->sampling_rate() << "Hz\n";
88                         }
89                         if ((*j)->main_subtitle()) {
90                                 cout << "      Subtitle: " << (*j)->main_subtitle()->subtitles().size() << " subtitles in " << (*j)->main_subtitle()->language() << "\n";
91                         }
92                         ++R;
93                 }
94         }
95
96         return 0;
97 }