2 Copyright (C) 2012-2015 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 just display a list of encoding servers that DCP-o-matic is configured to use; don't encode\n"
66 << " -d, --dcp-path echo DCP's path to stdout on successful completion (implies -n)\n"
67 << " --dump just dump a summary of the film's settings; don't encode\n"
69 << "<FILM> is the film directory.\n";
73 print_dump (shared_ptr<Film> film)
75 cout << film->dcp_name (true) << "\n"
76 << film->container()->nickname() << " at " << ((film->resolution() == RESOLUTION_2K) ? "2K" : "4K") << "\n"
77 << (film->j2k_bandwidth() / 1000000) << "Mbit/s" << "\n"
78 << "Output " << film->video_frame_rate() << "fps " << (film->three_d() ? "3D" : "2D") << " " << (film->audio_frame_rate() / 1000) << "kHz\n"
79 << (film->interop() ? "Inter-Op" : "SMPTE") << " " << (film->encrypted() ? "encrypted" : "unencrypted") << "\n";
81 BOOST_FOREACH (shared_ptr<Content> c, film->content ()) {
84 << "\tat " << c->position().seconds ()
85 << " length " << c->full_length().seconds ()
86 << " start trim " << c->trim_start().seconds ()
87 << " end trim " << c->trim_end().seconds () << "\n";
90 cout << "\t" << c->video->size().width << "x" << c->video->size().height << "\n"
91 << "\t" << c->active_video_frame_rate() << "fps\n"
92 << "\tcrop left " << c->video->left_crop()
93 << " right " << c->video->right_crop()
94 << " top " << c->video->top_crop()
95 << " bottom " << c->video->bottom_crop() << "\n"
96 << "\tscale " << c->video->scale().name() << "\n";
97 if (c->video->colour_conversion()) {
98 if (c->video->colour_conversion().get().preset()) {
99 cout << "\tcolour conversion "
100 << PresetColourConversion::all()[c->video->colour_conversion().get().preset().get()].name
103 cout << "\tcustom colour conversion\n";
106 cout << "\tno colour conversion\n";
112 cout << "\t" << c->audio->delay() << " delay\n"
113 << "\t" << c->audio->gain() << " gain\n";
123 list<EncodeServerDescription> servers = EncodeServerFinder::instance()->servers ();
125 if (Config::instance()->use_any_servers ()) {
126 if (servers.empty ()) {
127 cout << "No encoding servers found.\n";
130 cout << std::left << setw(24) << "Host" << " Threads\n";
132 BOOST_FOREACH (EncodeServerDescription const & i, servers) {
133 cout << std::left << setw(24) << i.host_name() << " " << i.threads() << "\n";
138 vector<string> configured_servers = Config::instance()->servers();
139 if (configured_servers.empty()) {
140 cout << "No configured servers, and DCP-o-matic is not set to search for any server.\n";
143 cout << std::left << setw(24) << "Host" << " Status Threads\n";
145 BOOST_FOREACH (string const & i, Config::instance()->servers()) {
146 cout << std::left << setw(24) << i << " ";
147 optional<int> threads;
148 BOOST_FOREACH (EncodeServerDescription const & j, servers) {
149 if (i == j.host_name()) {
150 threads = j.threads();
153 if (static_cast<bool>(threads)) {
154 cout << "UP " << threads.get() << "\n";
166 for (int i = 0; i < N; ++i) {
167 cout << "\033[1A\033[2K";
174 main (int argc, char* argv[])
176 boost::filesystem::path film_dir;
177 bool progress = true;
178 bool no_remote = false;
179 optional<int> threads;
180 optional<int> json_port;
181 bool keep_going = false;
183 bool servers = false;
184 bool dcp_path = false;
186 int option_index = 0;
188 static struct option long_options[] = {
189 { "version", no_argument, 0, 'v'},
190 { "help", no_argument, 0, 'h'},
191 { "flags", no_argument, 0, 'f'},
192 { "no-progress", no_argument, 0, 'n'},
193 { "no-remote", no_argument, 0, 'r'},
194 { "threads", required_argument, 0, 't'},
195 { "json", required_argument, 0, 'j'},
196 { "keep-going", no_argument, 0, 'k' },
197 { "servers", no_argument, 0, 's' },
198 { "dcp-path", no_argument, 0, 'd' },
199 /* Just using A, B, C ... from here on */
200 { "dump", no_argument, 0, 'A' },
204 int c = getopt_long (argc, argv, "vhfnrt:j:kAsd", long_options, &option_index);
212 cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
218 cout << dcpomatic_cxx_flags << "\n";
227 threads = atoi (optarg);
230 json_port = atoi (optarg);
253 if (optind >= argc) {
258 film_dir = argv[optind];
260 dcpomatic_setup_path_encoding ();
262 signal_manager = new SignalManager ();
265 EncodeServerFinder::instance()->stop ();
269 new JSONServer (json_port.get ());
273 Config::instance()->set_num_local_encoding_threads (threads.get ());
276 shared_ptr<Film> film;
278 film.reset (new Film (film_dir));
279 film->read_metadata ();
280 } catch (std::exception& e) {
281 cerr << argv[0] << ": error reading film `" << film_dir.string() << "' (" << e.what() << ")\n";
290 ContentList content = film->content ();
291 for (ContentList::const_iterator i = content.begin(); i != content.end(); ++i) {
292 vector<boost::filesystem::path> paths = (*i)->paths ();
293 for (vector<boost::filesystem::path>::const_iterator j = paths.begin(); j != paths.end(); ++j) {
294 if (!boost::filesystem::exists (*j)) {
295 cerr << argv[0] << ": content file " << *j << " not found.\n";
302 cout << "\nMaking DCP for " << film->name() << "\n";
307 bool should_stop = false;
310 while (!should_stop) {
314 list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
316 if (!first && progress) {
317 for (size_t i = 0; i < jobs.size(); ++i) {
318 cout << "\033[1A\033[2K";
326 int finished_in_error = 0;
328 BOOST_FOREACH (shared_ptr<Job> i, jobs) {
331 if (!i->sub_name().empty()) {
332 cout << "; " << i->sub_name();
336 if (i->progress ()) {
337 cout << i->status() << " \n";
339 cout << ": Running \n";
343 if (!i->finished ()) {
347 if (i->finished_in_error ()) {
352 if (!progress && i->finished_in_error ()) {
353 /* We won't see this error if we haven't been showing progress,
356 cout << i->status() << "\n";
360 if (unfinished == 0 || finished_in_error != 0) {
367 dcpomatic_sleep (3600);
371 /* This is just to stop valgrind reporting leaks due to JobManager
372 indirectly holding onto codecs.
376 EncodeServerFinder::drop ();
378 if (dcp_path && !error) {
379 cout << film->dir (film->dcp_name (false)).string() << "\n";
382 return error ? EXIT_FAILURE : EXIT_SUCCESS;