2 Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
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.
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.
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.
21 #include "lib/filter.h"
22 #include "lib/transcode_job.h"
23 #include "lib/job_manager.h"
25 #include "lib/version.h"
26 #include "lib/cross.h"
27 #include "lib/config.h"
29 #include "lib/signal_manager.h"
30 #include "lib/server_finder.h"
31 #include "lib/json_server.h"
32 #include "lib/ratio.h"
33 #include "lib/video_content.h"
34 #include "lib/audio_content.h"
35 #include <dcp/version.h>
36 #include <boost/foreach.hpp>
48 using boost::shared_ptr;
49 using boost::optional;
50 using boost::dynamic_pointer_cast;
55 cerr << "Syntax: " << n << " [OPTION] [<FILM>]\n"
56 << " -v, --version show DCP-o-matic version\n"
57 << " -h, --help show this help\n"
58 << " -f, --flags show flags passed to C++ compiler on build\n"
59 << " -n, --no-progress do not print progress to stdout\n"
60 << " -r, --no-remote do not use any remote servers\n"
61 << " -j, --json <port> run a JSON server on the specified port\n"
62 << " -k, --keep-going keep running even when the job is complete\n"
63 << " -s, --servers just display a list of encoding servers that DCP-o-matic is configured to use; don't encode\n"
64 << " --dump just dump a summary of the film's settings; don't encode\n"
66 << "<FILM> is the film directory.\n";
70 print_dump (shared_ptr<Film> film)
72 cout << film->dcp_name (true) << "\n"
73 << film->container()->nickname() << " at " << ((film->resolution() == RESOLUTION_2K) ? "2K" : "4K") << "\n"
74 << (film->j2k_bandwidth() / 1000000) << "Mbit/s" << "\n"
75 << "Output " << film->video_frame_rate() << "fps " << (film->three_d() ? "3D" : "2D") << " " << (film->audio_frame_rate() / 1000) << "kHz\n"
76 << (film->interop() ? "Inter-Op" : "SMPTE") << " " << (film->encrypted() ? "encrypted" : "unencrypted") << "\n";
78 BOOST_FOREACH (shared_ptr<Content> c, film->content ()) {
81 << "\tat " << c->position().seconds ()
82 << " length " << c->full_length().seconds ()
83 << " start trim " << c->trim_start().seconds ()
84 << " end trim " << c->trim_end().seconds () << "\n";
86 shared_ptr<VideoContent> video = dynamic_pointer_cast<VideoContent> (c);
88 cout << "\t" << video->video_size().width << "x" << video->video_size().height << "\n"
89 << "\t" << video->video_frame_rate() << "fps\n"
90 << "\tcrop left " << video->left_crop()
91 << " right " << video->right_crop()
92 << " top " << video->top_crop()
93 << " bottom " << video->bottom_crop() << "\n"
94 << "\tscale " << video->scale().name() << "\n";
95 if (video->colour_conversion()) {
96 if (video->colour_conversion().get().preset()) {
97 cout << "\tcolour conversion "
98 << PresetColourConversion::all()[video->colour_conversion().get().preset().get()].name
101 cout << "\tcustom colour conversion\n";
104 cout << "\tno colour conversion\n";
109 shared_ptr<AudioContent> audio = dynamic_pointer_cast<AudioContent> (c);
111 cout << "\t" << audio->audio_delay() << " delay\n"
112 << "\t" << audio->audio_gain() << " gain\n";
122 list<ServerDescription> servers = ServerFinder::instance()->servers ();
124 if (Config::instance()->use_any_servers ()) {
125 if (servers.empty ()) {
126 cout << "No encoding servers found.\n";
129 cout << std::left << setw(24) << "Host" << " Threads\n";
131 BOOST_FOREACH (ServerDescription const & i, servers) {
132 cout << std::left << setw(24) << i.host_name() << " " << i.threads() << "\n";
137 vector<string> configured_servers = Config::instance()->servers();
138 if (configured_servers.empty()) {
139 cout << "No configured servers, and DCP-o-matic is not set to search for any server.\n";
142 cout << std::left << setw(24) << "Host" << " Status Threads\n";
144 BOOST_FOREACH (string const & i, Config::instance()->servers()) {
145 cout << std::left << setw(24) << i << " ";
146 optional<int> threads;
147 BOOST_FOREACH (ServerDescription const & j, servers) {
148 if (i == j.host_name()) {
149 threads = j.threads();
152 if (static_cast<bool>(threads)) {
153 cout << "UP " << threads.get() << "\n";
165 for (int i = 0; i < N; ++i) {
166 cout << "\033[1A\033[2K";
173 main (int argc, char* argv[])
176 bool progress = true;
177 bool no_remote = false;
178 optional<int> json_port;
179 bool keep_going = false;
181 bool servers = false;
183 int option_index = 0;
185 static struct option long_options[] = {
186 { "version", no_argument, 0, 'v'},
187 { "help", no_argument, 0, 'h'},
188 { "flags", no_argument, 0, 'f'},
189 { "no-progress", no_argument, 0, 'n'},
190 { "no-remote", no_argument, 0, 'r'},
191 { "json", required_argument, 0, 'j'},
192 { "keep-going", no_argument, 0, 'k' },
193 { "servers", no_argument, 0, 's' },
194 /* Just using A, B, C ... from here on */
195 { "dump", no_argument, 0, 'A' },
199 int c = getopt_long (argc, argv, "vhfnrj:kAs", long_options, &option_index);
207 cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
213 cout << dcpomatic_cxx_flags << "\n";
222 json_port = atoi (optarg);
241 if (optind >= argc) {
246 film_dir = argv[optind];
248 dcpomatic_setup_path_encoding ();
250 signal_manager = new SignalManager ();
253 ServerFinder::instance()->disable ();
257 new JSONServer (json_port.get ());
260 shared_ptr<Film> film;
262 film.reset (new Film (film_dir));
263 film->read_metadata ();
264 } catch (std::exception& e) {
265 cerr << argv[0] << ": error reading film `" << film_dir << "' (" << e.what() << ")\n";
274 ContentList content = film->content ();
275 for (ContentList::const_iterator i = content.begin(); i != content.end(); ++i) {
276 vector<boost::filesystem::path> paths = (*i)->paths ();
277 for (vector<boost::filesystem::path>::const_iterator j = paths.begin(); j != paths.end(); ++j) {
278 if (!boost::filesystem::exists (*j)) {
279 cerr << argv[0] << ": content file " << *j << " not found.\n";
286 cout << "\nMaking DCP for " << film->name() << "\n";
291 bool should_stop = false;
294 while (!should_stop) {
298 list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
300 if (!first && progress) {
301 for (size_t i = 0; i < jobs.size(); ++i) {
302 cout << "\033[1A\033[2K";
310 int finished_in_error = 0;
312 for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
314 cout << (*i)->name() << ": ";
316 if ((*i)->progress ()) {
317 cout << (*i)->status() << " \n";
319 cout << ": Running \n";
323 if (!(*i)->finished ()) {
327 if ((*i)->finished_in_error ()) {
332 if (!progress && (*i)->finished_in_error ()) {
333 /* We won't see this error if we haven't been showing progress,
336 cout << (*i)->status() << "\n";
340 if (unfinished == 0 || finished_in_error != 0) {
347 dcpomatic_sleep (3600);
351 /* This is just to stop valgrind reporting leaks due to JobManager
352 indirectly holding onto codecs.
356 ServerFinder::drop ();
358 return error ? EXIT_FAILURE : EXIT_SUCCESS;