Add versioning; tweak libdcp version reporting; make makedcp more useful for testing.
[dcpomatic.git] / src / tools / makedcp.cc
1 /*
2     Copyright (C) 2012 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 <iomanip>
22 #include <getopt.h>
23 #include <libdcp/test_mode.h>
24 #include <libdcp/version.h>
25 #include "format.h"
26 #include "film.h"
27 #include "filter.h"
28 #include "transcode_job.h"
29 #include "make_dcp_job.h"
30 #include "job_manager.h"
31 #include "ab_transcode_job.h"
32 #include "util.h"
33 #include "scaler.h"
34 #include "version.h"
35
36 using namespace std;
37 using namespace boost;
38
39 static void
40 help (string n)
41 {
42         cerr << "Syntax: " << n << " [OPTION] <FILM>\n"
43              << "  -h, --help         show this help\n"
44              << "  -d, --deps         list DVD-o-matic dependency details and quit\n"
45              << "  -t, --test         run in test mode (repeatable UUID generation and timestamps)\n"
46              << "  -n, --no-progress  do not print progress to stdout\n"
47              << "\n"
48              << "<FILM> is the film directory.\n";
49 }
50
51 int
52 main (int argc, char* argv[])
53 {
54         string film_dir;
55         bool test_mode = false;
56         bool progress = true;
57
58         int option_index = 0;
59         while (1) {
60                 static struct option long_options[] = {
61                         { "help", no_argument, 0, 'h'},
62                         { "deps", no_argument, 0, 'd'},
63                         { "test", no_argument, 0, 't'},
64                         { "no-progress", no_argument, 0, 'n'},
65                         { 0, 0, 0, 0 }
66                 };
67
68                 int c = getopt_long (argc, argv, "hdtn", long_options, &option_index);
69
70                 if (c == -1) {
71                         break;
72                 }
73
74                 switch (c) {
75                 case 'h':
76                         help (argv[0]);
77                         exit (EXIT_SUCCESS);
78                 case 'd':
79                         cout << dependency_version_summary () << "\n";
80                         exit (EXIT_SUCCESS);
81                 case 't':
82                         test_mode = true;
83                         break;
84                 case 'n':
85                         progress = false;
86                         break;
87                 }
88         }
89
90         if (optind >= argc) {
91                 help (argv[0]);
92                 exit (EXIT_FAILURE);
93         }
94
95         film_dir = argv[optind];
96                         
97         dvdomatic_setup ();
98
99         cout << "DVD-o-matic " << dvdomatic_version << " git " << dvdomatic_git_commit;
100         char buf[256];
101         if (gethostname (buf, 256) == 0) {
102                 cout << " on " << buf;
103         }
104         cout << "\n";
105
106         if (test_mode) {
107                 libdcp::enable_test_mode ();
108                 cout << dependency_version_summary() << "\n";
109         }
110
111         Film* film = 0;
112         try {
113                 film = new Film (film_dir, true);
114         } catch (std::exception& e) {
115                 cerr << argv[0] << ": error reading film `" << film_dir << "' (" << e.what() << ")\n";
116                 exit (EXIT_FAILURE);
117         }
118
119         cout << "\nMaking ";
120         if (film->dcp_ab ()) {
121                 cout << "A/B ";
122         }
123         cout << "DCP for " << film->name() << "\n";
124         cout << "Test mode: " << (test_mode ? "yes" : "no") << "\n";
125         cout << "Content: " << film->content() << "\n";
126         pair<string, string> const f = Filter::ffmpeg_strings (film->filters ());
127         cout << "Filters: " << f.first << " " << f.second << "\n";
128
129         film->make_dcp (true);
130
131         list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
132
133         bool all_done = false;
134         bool first = true;
135         while (!all_done) {
136                 
137                 sleep (5);
138
139                 if (!first && progress) {
140                         cout << "\033[" << jobs.size() << "A";
141                         cout.flush ();
142                 }
143
144                 first = false;
145                 
146                 all_done = true;
147                 for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
148                         if (progress) {
149                                 cout << (*i)->name() << ": ";
150                                 
151                                 float const p = (*i)->overall_progress ();
152                                 
153                                 if (p >= 0) {
154                                         cout << (*i)->status() << "                         \n";
155                                 } else {
156                                         cout << ": Running           \n";
157                                 }
158                         }
159                         
160                         if (!(*i)->finished ()) {
161                                 all_done = false;
162                         }
163                 }
164         }
165
166         return 0;
167 }
168
169