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/encode_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 << " -d, --dcp-path echo DCP's path to stdout on successful completion (implies -n)\n"
65 << " --dump just dump a summary of the film's settings; don't encode\n"
67 << "<FILM> is the film directory.\n";
71 print_dump (shared_ptr<Film> film)
73 cout << film->dcp_name (true) << "\n"
74 << film->container()->nickname() << " at " << ((film->resolution() == RESOLUTION_2K) ? "2K" : "4K") << "\n"
75 << (film->j2k_bandwidth() / 1000000) << "Mbit/s" << "\n"
76 << "Output " << film->video_frame_rate() << "fps " << (film->three_d() ? "3D" : "2D") << " " << (film->audio_frame_rate() / 1000) << "kHz\n"
77 << (film->interop() ? "Inter-Op" : "SMPTE") << " " << (film->encrypted() ? "encrypted" : "unencrypted") << "\n";
79 BOOST_FOREACH (shared_ptr<Content> c, film->content ()) {
82 << "\tat " << c->position().seconds ()
83 << " length " << c->full_length().seconds ()
84 << " start trim " << c->trim_start().seconds ()
85 << " end trim " << c->trim_end().seconds () << "\n";
87 shared_ptr<VideoContent> video = dynamic_pointer_cast<VideoContent> (c);
89 cout << "\t" << video->video_size().width << "x" << video->video_size().height << "\n"
90 << "\t" << video->video_frame_rate() << "fps\n"
91 << "\tcrop left " << video->left_crop()
92 << " right " << video->right_crop()
93 << " top " << video->top_crop()
94 << " bottom " << video->bottom_crop() << "\n"
95 << "\tscale " << video->scale().name() << "\n";
96 if (video->colour_conversion()) {
97 if (video->colour_conversion().get().preset()) {
98 cout << "\tcolour conversion "
99 << PresetColourConversion::all()[video->colour_conversion().get().preset().get()].name
102 cout << "\tcustom colour conversion\n";
105 cout << "\tno colour conversion\n";
110 shared_ptr<AudioContent> audio = dynamic_pointer_cast<AudioContent> (c);
112 cout << "\t" << audio->audio_delay() << " delay\n"
113 << "\t" << audio->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[])
177 bool progress = true;
178 bool no_remote = false;
179 optional<int> json_port;
180 bool keep_going = false;
182 bool servers = false;
183 bool dcp_path = false;
185 int option_index = 0;
187 static struct option long_options[] = {
188 { "version", no_argument, 0, 'v'},
189 { "help", no_argument, 0, 'h'},
190 { "flags", no_argument, 0, 'f'},
191 { "no-progress", no_argument, 0, 'n'},
192 { "no-remote", no_argument, 0, 'r'},
193 { "json", required_argument, 0, 'j'},
194 { "keep-going", no_argument, 0, 'k' },
195 { "servers", no_argument, 0, 's' },
196 { "dcp-path", no_argument, 0, 'd' },
197 /* Just using A, B, C ... from here on */
198 { "dump", no_argument, 0, 'A' },
202 int c = getopt_long (argc, argv, "vhfnrj:kAsd", long_options, &option_index);
210 cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
216 cout << dcpomatic_cxx_flags << "\n";
225 json_port = atoi (optarg);
248 if (optind >= argc) {
253 film_dir = argv[optind];
255 dcpomatic_setup_path_encoding ();
257 signal_manager = new SignalManager ();
260 EncodeServerFinder::instance()->disable ();
264 new JSONServer (json_port.get ());
267 shared_ptr<Film> film;
269 film.reset (new Film (film_dir));
270 film->read_metadata ();
271 } catch (std::exception& e) {
272 cerr << argv[0] << ": error reading film `" << film_dir << "' (" << e.what() << ")\n";
281 ContentList content = film->content ();
282 for (ContentList::const_iterator i = content.begin(); i != content.end(); ++i) {
283 vector<boost::filesystem::path> paths = (*i)->paths ();
284 for (vector<boost::filesystem::path>::const_iterator j = paths.begin(); j != paths.end(); ++j) {
285 if (!boost::filesystem::exists (*j)) {
286 cerr << argv[0] << ": content file " << *j << " not found.\n";
293 cout << "\nMaking DCP for " << film->name() << "\n";
298 bool should_stop = false;
301 while (!should_stop) {
305 list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
307 if (!first && progress) {
308 for (size_t i = 0; i < jobs.size(); ++i) {
309 cout << "\033[1A\033[2K";
317 int finished_in_error = 0;
319 for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
321 cout << (*i)->name() << ": ";
323 if ((*i)->progress ()) {
324 cout << (*i)->status() << " \n";
326 cout << ": Running \n";
330 if (!(*i)->finished ()) {
334 if ((*i)->finished_in_error ()) {
339 if (!progress && (*i)->finished_in_error ()) {
340 /* We won't see this error if we haven't been showing progress,
343 cout << (*i)->status() << "\n";
347 if (unfinished == 0 || finished_in_error != 0) {
354 dcpomatic_sleep (3600);
358 /* This is just to stop valgrind reporting leaks due to JobManager
359 indirectly holding onto codecs.
363 EncodeServerFinder::drop ();
365 if (dcp_path && !error) {
366 cout << film->dir (film->dcp_name (false)).string() << "\n";
369 return error ? EXIT_FAILURE : EXIT_SUCCESS;