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