2 Copyright (C) 2012 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.
23 #include <libdcp/version.h>
25 #include "lib/filter.h"
26 #include "lib/transcode_job.h"
27 #include "lib/job_manager.h"
29 #include "lib/scaler.h"
30 #include "lib/version.h"
31 #include "lib/cross.h"
32 #include "lib/config.h"
34 #include "lib/ui_signaller.h"
35 #include "lib/server_finder.h"
36 #include "lib/json_server.h"
44 using boost::shared_ptr;
49 cerr << "Syntax: " << n << " [OPTION] <FILM>\n"
50 << " -v, --version show DCP-o-matic version\n"
51 << " -h, --help show this help\n"
52 << " -d, --deps list DCP-o-matic dependency details and quit\n"
53 << " -f, --flags show flags passed to C++ compiler on build\n"
54 << " -n, --no-progress do not print progress to stdout\n"
55 << " -r, --no-remote do not use any remote servers\n"
56 << " -j, --json <port> run a JSON server on the specified port\n"
57 << " -k, --keep-going keep running even when the job is complete\n"
59 << "<FILM> is the film directory.\n";
63 main (int argc, char* argv[])
67 bool no_remote = false;
69 bool keep_going = false;
73 static struct option long_options[] = {
74 { "version", no_argument, 0, 'v'},
75 { "help", no_argument, 0, 'h'},
76 { "deps", no_argument, 0, 'd'},
77 { "flags", no_argument, 0, 'f'},
78 { "no-progress", no_argument, 0, 'n'},
79 { "no-remote", no_argument, 0, 'r'},
80 { "json", required_argument, 0, 'j' },
81 { "keep-going", no_argument, 0, 'k' },
85 int c = getopt_long (argc, argv, "vhdfnrj:k", long_options, &option_index);
93 cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
99 cout << dependency_version_summary () << "\n";
102 cout << dcpomatic_cxx_flags << "\n";
111 json_port = atoi (optarg);
119 if (optind >= argc) {
124 film_dir = argv[optind];
127 ui_signaller = new UISignaller ();
130 ServerFinder::instance()->disable ();
134 new JSONServer (json_port);
137 cout << "DCP-o-matic " << dcpomatic_version << " git " << dcpomatic_git_commit;
139 if (gethostname (buf, 256) == 0) {
140 cout << " on " << buf;
144 shared_ptr<Film> film;
146 film.reset (new Film (film_dir));
147 film->read_metadata ();
148 } catch (std::exception& e) {
149 cerr << argv[0] << ": error reading film `" << film_dir << "' (" << e.what() << ")\n";
153 cout << "\nMaking DCP for " << film->name() << "\n";
154 // cout << "Content: " << film->content() << "\n";
155 // pair<string, string> const f = Filter::ffmpeg_strings (film->filters ());
156 // cout << "Filters: " << f.first << " " << f.second << "\n";
160 bool should_stop = false;
163 while (!should_stop) {
167 list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
169 if (!first && progress) {
170 cout << "\033[" << jobs.size() << "A";
177 int finished_in_error = 0;
179 for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
181 cout << (*i)->name() << ": ";
183 float const p = (*i)->progress ();
186 cout << (*i)->status() << " \n";
188 cout << ": Running \n";
192 if (!(*i)->finished ()) {
196 if ((*i)->finished_in_error ()) {
201 if (!progress && (*i)->finished_in_error ()) {
202 /* We won't see this error if we haven't been showing progress,
205 cout << (*i)->status() << "\n";
209 if (unfinished == 0 || finished_in_error != 0) {
216 dcpomatic_sleep (3600);
220 /* This is just to stop valgrind reporting leaks due to JobManager
221 indirectly holding onto codecs.
225 return error ? EXIT_FAILURE : EXIT_SUCCESS;