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/audio_content.h"
34 #include <dcp/version.h>
35 #include <boost/foreach.hpp>
46 using boost::shared_ptr;
47 using boost::optional;
48 using boost::dynamic_pointer_cast;
53 cerr << "Syntax: " << n << " [OPTION] <FILM>\n"
54 << " -v, --version show DCP-o-matic version\n"
55 << " -h, --help show this help\n"
56 << " -f, --flags show flags passed to C++ compiler on build\n"
57 << " -n, --no-progress do not print progress to stdout\n"
58 << " -r, --no-remote do not use any remote servers\n"
59 << " -j, --json <port> run a JSON server on the specified port\n"
60 << " -k, --keep-going keep running even when the job is complete\n"
61 << " --dump just dump a summary of the film's settings; don't encode\n"
63 << "<FILM> is the film directory.\n";
67 print_dump (shared_ptr<Film> film)
69 cout << film->dcp_name (true) << "\n"
70 << film->container()->nickname() << " at " << ((film->resolution() == RESOLUTION_2K) ? "2K" : "4K") << "\n"
71 << (film->j2k_bandwidth() / 1000000) << "Mbit/s" << "\n"
72 << "Output " << film->video_frame_rate() << "fps " << (film->three_d() ? "3D" : "2D") << " " << (film->audio_frame_rate() / 1000) << "kHz\n"
73 << (film->interop() ? "Inter-Op" : "SMPTE") << " " << (film->encrypted() ? "encrypted" : "unencrypted") << "\n";
75 BOOST_FOREACH (shared_ptr<Content> c, film->content ()) {
78 << "\tat " << c->position().seconds ()
79 << " length " << c->full_length().seconds ()
80 << " start trim " << c->trim_start().seconds ()
81 << " end trim " << c->trim_end().seconds () << "\n";
83 shared_ptr<VideoContent> video = dynamic_pointer_cast<VideoContent> (c);
85 cout << "\t" << video->video_size().width << "x" << video->video_size().height << "\n"
86 << "\t" << video->video_frame_rate() << "fps\n"
87 << "\tcrop left " << video->left_crop()
88 << " right " << video->right_crop()
89 << " top " << video->top_crop()
90 << " bottom " << video->bottom_crop() << "\n"
91 << "\tscale " << video->scale().name() << "\n";
92 if (video->colour_conversion()) {
93 if (video->colour_conversion().get().preset()) {
94 cout << "\tcolour conversion "
95 << PresetColourConversion::all()[video->colour_conversion().get().preset().get()].name
98 cout << "\tcustom colour conversion\n";
101 cout << "\tno colour conversion\n";
106 shared_ptr<AudioContent> audio = dynamic_pointer_cast<AudioContent> (c);
108 cout << "\t" << audio->audio_delay() << " delay\n"
109 << "\t" << audio->audio_gain() << " gain\n";
115 main (int argc, char* argv[])
118 bool progress = true;
119 bool no_remote = false;
120 optional<int> json_port;
121 bool keep_going = false;
124 int option_index = 0;
126 static struct option long_options[] = {
127 { "version", no_argument, 0, 'v'},
128 { "help", no_argument, 0, 'h'},
129 { "flags", no_argument, 0, 'f'},
130 { "no-progress", no_argument, 0, 'n'},
131 { "no-remote", no_argument, 0, 'r'},
132 { "json", required_argument, 0, 'j'},
133 { "keep-going", no_argument, 0, 'k' },
134 /* Just using A, B, C ... from here on */
135 { "dump", no_argument, 0, 'A' },
139 int c = getopt_long (argc, argv, "vhfnrj:kA", long_options, &option_index);
147 cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
153 cout << dcpomatic_cxx_flags << "\n";
162 json_port = atoi (optarg);
173 if (optind >= argc) {
178 film_dir = argv[optind];
181 signal_manager = new SignalManager ();
184 ServerFinder::instance()->disable ();
188 new JSONServer (json_port.get ());
191 shared_ptr<Film> film;
193 film.reset (new Film (film_dir));
194 film->read_metadata ();
195 } catch (std::exception& e) {
196 cerr << argv[0] << ": error reading film `" << film_dir << "' (" << e.what() << ")\n";
205 ContentList content = film->content ();
206 for (ContentList::const_iterator i = content.begin(); i != content.end(); ++i) {
207 vector<boost::filesystem::path> paths = (*i)->paths ();
208 for (vector<boost::filesystem::path>::const_iterator j = paths.begin(); j != paths.end(); ++j) {
209 if (!boost::filesystem::exists (*j)) {
210 cerr << argv[0] << ": content file " << *j << " not found.\n";
217 cout << "\nMaking DCP for " << film->name() << "\n";
222 bool should_stop = false;
225 while (!should_stop) {
229 list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
231 if (!first && progress) {
232 cout << "\033[" << jobs.size() << "A";
239 int finished_in_error = 0;
241 for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
243 cout << (*i)->name() << ": ";
245 if ((*i)->progress ()) {
246 cout << (*i)->status() << " \n";
248 cout << ": Running \n";
252 if (!(*i)->finished ()) {
256 if ((*i)->finished_in_error ()) {
261 if (!progress && (*i)->finished_in_error ()) {
262 /* We won't see this error if we haven't been showing progress,
265 cout << (*i)->status() << "\n";
269 if (unfinished == 0 || finished_in_error != 0) {
276 dcpomatic_sleep (3600);
280 /* This is just to stop valgrind reporting leaks due to JobManager
281 indirectly holding onto codecs.
285 ServerFinder::drop ();
287 return error ? EXIT_FAILURE : EXIT_SUCCESS;