Tweaks to dcpinfo.
[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], false);
62         } catch (FileError& e) {
63                 cerr << "Could not read DCP " << argv[optind] << "; " << e.what() << " " << e.filename() << "\n";
64                 exit (EXIT_FAILURE);
65         }
66
67         cout << "DCP: " << argv[optind] << "\n"
68              << "\tLength: " << dcp->length() << "\n"
69              << "\tFrames per second: " << dcp->frames_per_second() << "\n";
70
71         list<shared_ptr<const Reel> > reels = dcp->reels ();
72
73         int R = 1;
74         for (list<shared_ptr<const Reel> >::const_iterator i = reels.begin(); i != reels.end(); ++i) {
75                 cout << "Reel " << R << "\n";
76                 if ((*i)->main_picture()) {
77                         cout << "\tPicture:  " << (*i)->main_picture()->width() << "x" << (*i)->main_picture()->height() << "\n";
78                 }
79                 if ((*i)->main_sound()) {
80                         cout << "\tSound:    " << (*i)->main_sound()->channels() << " channels at " << (*i)->main_sound()->sampling_rate() << "Hz\n";
81                 }
82                 if ((*i)->main_subtitle()) {
83                         cout << "\tSubtitle: " << (*i)->main_subtitle()->subtitles().size() << " subtitles in " << (*i)->main_subtitle()->language() << "\n";
84                 }
85                 ++R;
86         }
87
88         return 0;
89 }