summaryrefslogtreecommitdiff
path: root/tools/dcpinfo.cc
blob: 56d71f9934359b9f4842b6087c8a0e091544a44b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <iostream>
#include <cstdlib>
#include <boost/filesystem.hpp>
#include <getopt.h>
#include "dcp.h"
#include "exceptions.h"
#include "reel.h"
#include "sound_asset.h"
#include "picture_asset.h"
#include "subtitle_asset.h"
#include "cpl.h"

using std::string;
using std::cerr;
using std::cout;
using std::list;
using boost::shared_ptr;
using namespace libdcp;

static void
help (string n)
{
	cerr << "Syntax: " << n << " [options] <DCP>\n"
	     << "  -s, --subtitles  list all subtitles\n";
}

int
main (int argc, char* argv[])
{
	bool subtitles = false;
	
	int option_index = 0;
	while (1) {
		static struct option long_options[] = {
			{ "version", no_argument, 0, 'v'},
			{ "help", no_argument, 0, 'h'},
			{ "subtitles", no_argument, 0, 's'},
			{ 0, 0, 0, 0 }
		};

		int c = getopt_long (argc, argv, "vhs", long_options, &option_index);

		if (c == -1) {
			break;
		}

		switch (c) {
		case 'v':
			cout << "dcpdiff version " << LIBDCP_VERSION << "\n";
			exit (EXIT_SUCCESS);
		case 'h':
			help (argv[0]);
			exit (EXIT_SUCCESS);
		case 's':
			subtitles = true;
			break;
		}
	}

	if (argc <= optind || argc > (optind + 1)) {
		help (argv[0]);
		exit (EXIT_FAILURE);
	}

	if (!boost::filesystem::exists (argv[optind])) {
		cerr << argv[0] << ": DCP " << argv[optind] << " not found.\n";
		exit (EXIT_FAILURE);
	}

	DCP* dcp = 0;
	try {
		dcp = new DCP (argv[optind]);
		dcp->read (false);
	} catch (FileError& e) {
		cerr << "Could not read DCP " << argv[optind] << "; " << e.what() << " " << e.filename() << "\n";
		exit (EXIT_FAILURE);
	}

	cout << "DCP: " << argv[optind] << "\n";

	list<shared_ptr<CPL> > cpls = dcp->cpls ();

	for (list<shared_ptr<CPL> >::iterator i = cpls.begin(); i != cpls.end(); ++i) {
		cout << "  CPL: " << (*i)->name() << "\n"
		     << "    Length: " << (*i)->length() << "\n"
		     << "    Frames per second: " << (*i)->frames_per_second() << "\n";
		
		list<shared_ptr<Reel> > reels = (*i)->reels ();

		int R = 1;
		for (list<shared_ptr<Reel> >::const_iterator j = reels.begin(); j != reels.end(); ++j) {
			cout << "    Reel " << R << "\n";
			
			if ((*j)->main_picture()) {
				cout << "      Picture:  " << (*j)->main_picture()->size().width << "x" << (*j)->main_picture()->size().height << "\n";
			}
			if ((*j)->main_sound()) {
				cout << "      Sound:    " << (*j)->main_sound()->channels() << " channels at " << (*j)->main_sound()->sampling_rate() << "Hz\n";
			}
			if ((*j)->main_subtitle()) {
				list<shared_ptr<Subtitle> > subs = (*j)->main_subtitle()->subtitles ();
				cout << "      Subtitle: " << subs.size() << " subtitles in " << (*j)->main_subtitle()->language() << "\n";
				if (subtitles) {
					for (list<shared_ptr<Subtitle> >::const_iterator k = subs.begin(); k != subs.end(); ++k) {
						cout << "        " << (*k)->text() << "\n";
						cout << "          "
						     << "font:" << (*k)->font() << "; "
						     << "italic:" << (*k)->italic() << "; "
						     << "color:" << (*k)->color() << "; "
						     << "in:" << (*k)->in() << "; "
						     << "out:" << (*k)->out() << "; "
						     << "v_position:" << (*k)->v_position() << "; "
						     << "v_align:" << (*k)->v_align() << "; "
						     << "effect:" << (*k)->effect() << "; "
						     << "effect_color:" << (*k)->effect_color() << "; "
						     << "fade_up_time:" << (*k)->fade_up_time() << "; "
						     << "fade_down_time:" << (*k)->fade_down_time() << "; "
						     << "size: " << (*k)->size() << "\n";
					}
				}
			}
			++R;
		}
	}

	return 0;
}