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>
47 using boost::shared_ptr;
48 using boost::optional;
49 using boost::dynamic_pointer_cast;
54 cerr << "Syntax: " << n << " [OPTION] <FILM>\n"
55 << " -v, --version show DCP-o-matic version\n"
56 << " -h, --help show this help\n"
57 << " -f, --flags show flags passed to C++ compiler on build\n"
58 << " -n, --no-progress do not print progress to stdout\n"
59 << " -r, --no-remote do not use any remote servers\n"
60 << " -j, --json <port> run a JSON server on the specified port\n"
61 << " -k, --keep-going keep running even when the job is complete\n"
62 << " --dump just dump a summary of the film's settings; don't encode\n"
64 << "<FILM> is the film directory.\n";
68 print_dump (shared_ptr<Film> film)
70 cout << film->dcp_name (true) << "\n"
71 << film->container()->nickname() << " at " << ((film->resolution() == RESOLUTION_2K) ? "2K" : "4K") << "\n"
72 << (film->j2k_bandwidth() / 1000000) << "Mbit/s" << "\n"
73 << "Output " << film->video_frame_rate() << "fps " << (film->three_d() ? "3D" : "2D") << " " << (film->audio_frame_rate() / 1000) << "kHz\n"
74 << (film->interop() ? "Inter-Op" : "SMPTE") << " " << (film->encrypted() ? "encrypted" : "unencrypted") << "\n";
76 BOOST_FOREACH (shared_ptr<Content> c, film->content ()) {
79 << "\tat " << c->position().seconds ()
80 << " length " << c->full_length().seconds ()
81 << " start trim " << c->trim_start().seconds ()
82 << " end trim " << c->trim_end().seconds () << "\n";
84 shared_ptr<VideoContent> video = dynamic_pointer_cast<VideoContent> (c);
86 cout << "\t" << video->video_size().width << "x" << video->video_size().height << "\n"
87 << "\t" << video->video_frame_rate() << "fps\n"
88 << "\tcrop left " << video->left_crop()
89 << " right " << video->right_crop()
90 << " top " << video->top_crop()
91 << " bottom " << video->bottom_crop() << "\n"
92 << "\tscale " << video->scale().name() << "\n";
93 if (video->colour_conversion()) {
94 if (video->colour_conversion().get().preset()) {
95 cout << "\tcolour conversion "
96 << PresetColourConversion::all()[video->colour_conversion().get().preset().get()].name
99 cout << "\tcustom colour conversion\n";
102 cout << "\tno colour conversion\n";
107 shared_ptr<AudioContent> audio = dynamic_pointer_cast<AudioContent> (c);
109 cout << "\t" << audio->audio_delay() << " delay\n"
110 << "\t" << audio->audio_gain() << " gain\n";
116 main (int argc, char* argv[])
119 bool progress = true;
120 bool no_remote = false;
121 optional<int> json_port;
122 bool keep_going = false;
125 int option_index = 0;
127 static struct option long_options[] = {
128 { "version", no_argument, 0, 'v'},
129 { "help", no_argument, 0, 'h'},
130 { "flags", no_argument, 0, 'f'},
131 { "no-progress", no_argument, 0, 'n'},
132 { "no-remote", no_argument, 0, 'r'},
133 { "json", required_argument, 0, 'j'},
134 { "keep-going", no_argument, 0, 'k' },
135 /* Just using A, B, C ... from here on */
136 { "dump", no_argument, 0, 'A' },
140 int c = getopt_long (argc, argv, "vhfnrj:kA", long_options, &option_index);
148 cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
154 cout << dcpomatic_cxx_flags << "\n";
163 json_port = atoi (optarg);
174 if (optind >= argc) {
179 film_dir = argv[optind];
181 dcpomatic_setup_path_encoding ();
183 signal_manager = new SignalManager ();
186 ServerFinder::instance()->disable ();
190 new JSONServer (json_port.get ());
193 shared_ptr<Film> film;
195 film.reset (new Film (film_dir));
196 film->read_metadata ();
197 } catch (std::exception& e) {
198 cerr << argv[0] << ": error reading film `" << film_dir << "' (" << e.what() << ")\n";
207 ContentList content = film->content ();
208 for (ContentList::const_iterator i = content.begin(); i != content.end(); ++i) {
209 vector<boost::filesystem::path> paths = (*i)->paths ();
210 for (vector<boost::filesystem::path>::const_iterator j = paths.begin(); j != paths.end(); ++j) {
211 if (!boost::filesystem::exists (*j)) {
212 cerr << argv[0] << ": content file " << *j << " not found.\n";
219 cout << "\nMaking DCP for " << film->name() << "\n";
224 bool should_stop = false;
227 while (!should_stop) {
231 list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
233 if (!first && progress) {
234 cout << "\033[" << jobs.size() << "A";
241 int finished_in_error = 0;
243 for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
245 cout << (*i)->name() << ": ";
247 if ((*i)->progress ()) {
248 cout << (*i)->status() << " \n";
250 cout << ": Running \n";
254 if (!(*i)->finished ()) {
258 if ((*i)->finished_in_error ()) {
263 if (!progress && (*i)->finished_in_error ()) {
264 /* We won't see this error if we haven't been showing progress,
267 cout << (*i)->status() << "\n";
271 if (unfinished == 0 || finished_in_error != 0) {
278 dcpomatic_sleep (3600);
282 /* This is just to stop valgrind reporting leaks due to JobManager
283 indirectly holding onto codecs.
287 ServerFinder::drop ();
289 return error ? EXIT_FAILURE : EXIT_SUCCESS;