Add no-remote option to makedcp.
[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 #include "cross.h"
36 #include "config.h"
37 #include "log.h"
38
39 using namespace std;
40 using namespace boost;
41
42 static void
43 help (string n)
44 {
45         cerr << "Syntax: " << n << " [OPTION] <FILM>\n"
46              << "  -v, --version      show DVD-o-matic version\n"
47              << "  -h, --help         show this help\n"
48              << "  -d, --deps         list DVD-o-matic dependency details and quit\n"
49              << "  -c, --config       list configuration settings that affect output and quit\n"
50              << "  -t, --test         run in test mode (repeatable UUID generation, timestamps etc.)\n"
51              << "  -n, --no-progress  do not print progress to stdout\n"
52              << "  -r, --no-remote    do not use any remote servers\n"
53              << "\n"
54              << "<FILM> is the film directory.\n";
55 }
56
57 int
58 main (int argc, char* argv[])
59 {
60         string film_dir;
61         bool test_mode = false;
62         bool progress = true;
63         bool no_remote = false;
64         int log_level = 1;
65
66         int option_index = 0;
67         while (1) {
68                 static struct option long_options[] = {
69                         { "version", no_argument, 0, 'v'},
70                         { "help", no_argument, 0, 'h'},
71                         { "deps", no_argument, 0, 'd'},
72                         { "config", no_argument, 0, 'c'},
73                         { "test", no_argument, 0, 't'},
74                         { "no-progress", no_argument, 0, 'n'},
75                         { "no-remote", no_argument, 0, 'r'},
76                         { "log-level", required_argument, 0, 'l' },
77                         { 0, 0, 0, 0 }
78                 };
79
80                 int c = getopt_long (argc, argv, "vhdctnrl:", long_options, &option_index);
81
82                 if (c == -1) {
83                         break;
84                 }
85
86                 switch (c) {
87                 case 'v':
88                         cout << "dvdomatic version " << dvdomatic_version << " " << dvdomatic_git_commit << "\n";
89                         exit (EXIT_SUCCESS);
90                 case 'h':
91                         help (argv[0]);
92                         exit (EXIT_SUCCESS);
93                 case 'd':
94                         cout << dependency_version_summary () << "\n";
95                         exit (EXIT_SUCCESS);
96                 case 't':
97                         test_mode = true;
98                         break;
99                 case 'n':
100                         progress = false;
101                         break;
102                 case 'r':
103                         no_remote = true;
104                         break;
105                 case 'c':
106                         cout << "Colour LUT " << colour_lut_index_to_name (Config::instance()->colour_lut_index()) << "; "
107                              << "J2K bandwidth " << Config::instance()->j2k_bandwidth() << "; ";
108 #ifdef DVDOMATIC_DEBUG
109                         cout << "built in debug mode\n";
110 #else
111                         cout << "built in optimised mode\n";
112 #endif                  
113                         exit (EXIT_SUCCESS);
114                 case 'l':
115                         log_level = atoi (optarg);
116                         break;
117                 }
118         }
119
120         if (optind >= argc) {
121                 help (argv[0]);
122                 exit (EXIT_FAILURE);
123         }
124
125         film_dir = argv[optind];
126                         
127         dvdomatic_setup ();
128
129         if (no_remote) {
130                 Config::instance()->set_servers (vector<ServerDescription*> ());
131         }
132
133         cout << "DVD-o-matic " << dvdomatic_version << " git " << dvdomatic_git_commit;
134         char buf[256];
135         if (gethostname (buf, 256) == 0) {
136                 cout << " on " << buf;
137         }
138         cout << "\n";
139
140         if (test_mode) {
141                 libdcp::enable_test_mode ();
142                 cout << dependency_version_summary() << "\n";
143         }
144
145         Film* film = 0;
146         try {
147                 film = new Film (film_dir, true);
148         } catch (std::exception& e) {
149                 cerr << argv[0] << ": error reading film `" << film_dir << "' (" << e.what() << ")\n";
150                 exit (EXIT_FAILURE);
151         }
152
153         film->log()->set_level ((Log::Level) log_level);
154
155         cout << "\nMaking ";
156         if (film->dcp_ab()) {
157                 cout << "A/B ";
158         }
159         cout << "DCP for " << film->name() << "\n";
160         cout << "Test mode: " << (test_mode ? "yes" : "no") << "\n";
161         cout << "Content: " << film->content() << "\n";
162         pair<string, string> const f = Filter::ffmpeg_strings (film->filters ());
163         cout << "Filters: " << f.first << " " << f.second << "\n";
164
165         film->make_dcp (true);
166
167         bool all_done = false;
168         bool first = true;
169         while (!all_done) {
170
171                 dvdomatic_sleep (5);
172
173                 list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
174
175                 if (!first && progress) {
176                         cout << "\033[" << jobs.size() << "A";
177                         cout.flush ();
178                 }
179
180                 first = false;
181                 
182                 all_done = true;
183                 for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
184                         if (progress) {
185                                 cout << (*i)->name() << ": ";
186                                 
187                                 float const p = (*i)->overall_progress ();
188                                 
189                                 if (p >= 0) {
190                                         cout << (*i)->status() << "                         \n";
191                                 } else {
192                                         cout << ": Running           \n";
193                                 }
194                         }
195                         
196                         if (!(*i)->finished ()) {
197                                 all_done = false;
198                         }
199
200                         if (!progress && (*i)->finished_in_error ()) {
201                                 /* We won't see this error if we haven't been showing progress,
202                                    so show it now.
203                                 */
204                                 cout << (*i)->status() << "\n";
205                         }
206                 }
207         }
208
209         return 0;
210 }
211
212