Inspect J2K data in MXFs.
[libdcp.git] / tools / dcpdiff.cc
1 #include <getopt.h>
2 #include "dcp.h"
3
4 using namespace std;
5 using namespace libdcp;
6
7 static void
8 help (string n)
9 {
10         cerr << "Syntax: " << n << " [OPTION] <DCP> <DCP>\n"
11              << "  -b, --bitwise      bitwise check\n"
12              << "  -v, --version      show libdcp version\n"
13              << "  -h, --help         show this help\n"
14              << "\n"
15              << "The <DCP>s are the DCP directories to compare.\n"
16              << "Default is to compare metadata and content ignoring timestamps\n"
17              << "and differing UUIDs.  Pass -b to perform a bitwise comparison.\n";
18 }
19
20 int
21 main (int argc, char* argv[])
22 {
23         bool bitwise = false;
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, "bvh", long_options, &option_index);
34
35                 if (c == -1) {
36                         break;
37                 }
38
39                 switch (c) {
40                 case 'b':
41                         bitwise = true;
42                         break;
43                 case 'v':
44                         cout << "dcpdiff version " << LIBDCP_VERSION << "\n";
45                         exit (EXIT_SUCCESS);
46                 case 'h':
47                         help (argv[0]);
48                         exit (EXIT_SUCCESS);
49                 }
50         }
51
52         if (argc <= optind || argc > (optind + 2)) {
53                 help (argv[0]);
54                 exit (EXIT_FAILURE);
55         }
56
57         DCP a (argv[optind]);
58         DCP b (argv[optind + 1]);
59
60         EqualityFlags flags = EqualityFlags (LIBDCP_METADATA | MXF_INSPECT);
61         if (bitwise) {
62                 flags = EqualityFlags (flags | MXF_BITWISE);
63         }
64
65         list<string> notes = a.equals (b, flags);
66         if (notes.empty ()) {
67                 cout << "DCPs identical\n";
68                 exit (EXIT_SUCCESS);
69         }
70
71         for (list<string>::iterator i = notes.begin(); i != notes.end(); ++i) {
72                 cout << "  " << *i << "\n";
73         }
74
75         exit (EXIT_FAILURE);
76 }