2 Copyright (C) 2012-2017 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "lib/filter.h"
23 #include "lib/transcode_job.h"
24 #include "lib/job_manager.h"
26 #include "lib/version.h"
27 #include "lib/cross.h"
28 #include "lib/config.h"
30 #include "lib/signal_manager.h"
31 #include "lib/encode_server_finder.h"
32 #include "lib/json_server.h"
33 #include "lib/ratio.h"
34 #include "lib/video_content.h"
35 #include "lib/audio_content.h"
36 #include <dcp/version.h>
37 #include <boost/foreach.hpp>
49 using boost::shared_ptr;
50 using boost::optional;
51 using boost::dynamic_pointer_cast;
56 cerr << "Syntax: " << n << " [OPTION] [<FILM>]\n"
57 << " -v, --version show DCP-o-matic version\n"
58 << " -h, --help show this help\n"
59 << " -f, --flags show flags passed to C++ compiler on build\n"
60 << " -n, --no-progress do not print progress to stdout\n"
61 << " -r, --no-remote do not use any remote servers\n"
62 << " -t, --threads specify number of local encoding threads (overriding configuration)\n"
63 << " -j, --json <port> run a JSON server on the specified port\n"
64 << " -k, --keep-going keep running even when the job is complete\n"
65 << " -s, --servers <file> specify servers to use in a text file\n"
66 << " -l, --list-servers just display a list of encoding servers that DCP-o-matic is configured to use; don't encode\n"
67 << " -d, --dcp-path echo DCP's path to stdout on successful completion (implies -n)\n"
68 << " -c, --config <dir> directory containing config.xml and cinemas.xml\n"
69 << " --dump just dump a summary of the film's settings; don't encode\n"
71 << "<FILM> is the film directory.\n";
75 print_dump (shared_ptr<Film> film)
77 cout << film->dcp_name (true) << "\n"
78 << film->container()->container_nickname() << " at " << ((film->resolution() == RESOLUTION_2K) ? "2K" : "4K") << "\n"
79 << (film->j2k_bandwidth() / 1000000) << "Mbit/s" << "\n"
80 << "Output " << film->video_frame_rate() << "fps " << (film->three_d() ? "3D" : "2D") << " " << (film->audio_frame_rate() / 1000) << "kHz\n"
81 << (film->interop() ? "Inter-Op" : "SMPTE") << " " << (film->encrypted() ? "encrypted" : "unencrypted") << "\n";
83 BOOST_FOREACH (shared_ptr<Content> c, film->content ()) {
86 << "\tat " << c->position().seconds ()
87 << " length " << c->full_length().seconds ()
88 << " start trim " << c->trim_start().seconds ()
89 << " end trim " << c->trim_end().seconds () << "\n";
92 cout << "\t" << c->video->size().width << "x" << c->video->size().height << "\n"
93 << "\t" << c->active_video_frame_rate() << "fps\n"
94 << "\tcrop left " << c->video->left_crop()
95 << " right " << c->video->right_crop()
96 << " top " << c->video->top_crop()
97 << " bottom " << c->video->bottom_crop() << "\n"
98 << "\tscale " << c->video->scale().name() << "\n";
99 if (c->video->colour_conversion()) {
100 if (c->video->colour_conversion().get().preset()) {
101 cout << "\tcolour conversion "
102 << PresetColourConversion::all()[c->video->colour_conversion().get().preset().get()].name
105 cout << "\tcustom colour conversion\n";
108 cout << "\tno colour conversion\n";
114 cout << "\t" << c->audio->delay() << " delay\n"
115 << "\t" << c->audio->gain() << " gain\n";
125 list<EncodeServerDescription> servers = EncodeServerFinder::instance()->servers();
127 /* This is a bit fiddly because we want to list configured servers that are down as well
128 as all those (configured and found by broadcast) that are up.
131 if (servers.empty() && Config::instance()->servers().empty()) {
132 cout << "No encoding servers found or configured.\n";
135 cout << std::left << setw(24) << "Host" << " Status Threads\n";
138 /* Report the state of configured servers */
139 BOOST_FOREACH (string i, Config::instance()->servers()) {
140 cout << std::left << setw(24) << i << " ";
142 /* See if this server is on the active list; if so, remove it and note
143 the number of threads it is offering.
145 optional<int> threads;
146 list<EncodeServerDescription>::iterator j = servers.begin ();
147 while (j != servers.end ()) {
148 if (i == j->host_name() && j->current_link_version()) {
149 threads = j->threads();
150 list<EncodeServerDescription>::iterator tmp = j;
158 if (static_cast<bool>(threads)) {
159 cout << "UP " << threads.get() << "\n";
166 /* Now report any left that have been found by broadcast */
167 BOOST_FOREACH (EncodeServerDescription const & i, servers) {
168 if (i.current_link_version()) {
169 cout << std::left << setw(24) << i.host_name() << " UP " << i.threads() << "\n";
171 cout << std::left << setw(24) << i.host_name() << " bad version\n";
179 for (int i = 0; i < N; ++i) {
180 cout << "\033[1A\033[2K";
187 main (int argc, char* argv[])
189 boost::filesystem::path film_dir;
190 bool progress = true;
191 bool no_remote = false;
192 optional<int> threads;
193 optional<int> json_port;
194 bool keep_going = false;
196 optional<boost::filesystem::path> servers;
197 bool list_servers_ = false;
198 bool dcp_path = false;
199 optional<boost::filesystem::path> config;
201 int option_index = 0;
203 static struct option long_options[] = {
204 { "version", no_argument, 0, 'v'},
205 { "help", no_argument, 0, 'h'},
206 { "flags", no_argument, 0, 'f'},
207 { "no-progress", no_argument, 0, 'n'},
208 { "no-remote", no_argument, 0, 'r'},
209 { "threads", required_argument, 0, 't'},
210 { "json", required_argument, 0, 'j'},
211 { "keep-going", no_argument, 0, 'k' },
212 { "servers", required_argument, 0, 's' },
213 { "list-servers", no_argument, 0, 'l' },
214 { "dcp-path", no_argument, 0, 'd' },
215 { "config", required_argument, 0, 'c' },
216 /* Just using A, B, C ... from here on */
217 { "dump", no_argument, 0, 'A' },
221 int c = getopt_long (argc, argv, "vhfnrt:j:kAs:ldc:", long_options, &option_index);
229 cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
235 cout << dcpomatic_cxx_flags << "\n";
244 threads = atoi (optarg);
247 json_port = atoi (optarg);
259 list_servers_ = true;
272 Config::override_path = *config;
276 FILE* f = fopen_boost (*servers, "r");
278 cerr << "Could not open servers list file " << *servers << "\n";
281 vector<string> servers;
284 if (fscanf (f, "%s.127", buffer) == 1) {
285 servers.push_back (buffer);
289 Config::instance()->set_servers (servers);
297 if (optind >= argc) {
302 film_dir = argv[optind];
304 dcpomatic_setup_path_encoding ();
306 signal_manager = new SignalManager ();
309 EncodeServerFinder::instance()->stop ();
313 new JSONServer (json_port.get ());
317 Config::instance()->set_master_encoding_threads (threads.get ());
320 shared_ptr<Film> film;
322 film.reset (new Film (film_dir));
323 film->read_metadata ();
324 } catch (std::exception& e) {
325 cerr << argv[0] << ": error reading film `" << film_dir.string() << "' (" << e.what() << ")\n";
334 ContentList content = film->content ();
335 for (ContentList::const_iterator i = content.begin(); i != content.end(); ++i) {
336 vector<boost::filesystem::path> paths = (*i)->paths ();
337 for (vector<boost::filesystem::path>::const_iterator j = paths.begin(); j != paths.end(); ++j) {
338 if (!boost::filesystem::exists (*j)) {
339 cerr << argv[0] << ": content file " << *j << " not found.\n";
346 cout << "\nMaking DCP for " << film->name() << "\n";
351 bool should_stop = false;
354 while (!should_stop) {
358 list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
360 if (!first && progress) {
361 for (size_t i = 0; i < jobs.size(); ++i) {
362 cout << "\033[1A\033[2K";
370 int finished_in_error = 0;
372 BOOST_FOREACH (shared_ptr<Job> i, jobs) {
375 if (!i->sub_name().empty()) {
376 cout << "; " << i->sub_name();
380 if (i->progress ()) {
381 cout << i->status() << " \n";
383 cout << ": Running \n";
387 if (!i->finished ()) {
391 if (i->finished_in_error ()) {
396 if (!progress && i->finished_in_error ()) {
397 /* We won't see this error if we haven't been showing progress,
400 cout << i->status() << "\n";
404 if (unfinished == 0 || finished_in_error != 0) {
411 dcpomatic_sleep (3600);
415 /* This is just to stop valgrind reporting leaks due to JobManager
416 indirectly holding onto codecs.
420 EncodeServerFinder::drop ();
422 if (dcp_path && !error) {
423 cout << film->dir (film->dcp_name (false)).string() << "\n";
426 return error ? EXIT_FAILURE : EXIT_SUCCESS;