Output git commit from makedcp -v.
[dcpomatic.git] / src / tools / makedcp.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #include <iostream>
21 #include <iomanip>
22 #include <getopt.h>
23 #include <libdcp/test_mode.h>
24 #include <libdcp/version.h>
25 #include "format.h"
26 #include "film.h"
27 #include "filter.h"
28 #include "transcode_job.h"
29 #include "make_dcp_job.h"
30 #include "job_manager.h"
31 #include "ab_transcode_job.h"
32 #include "util.h"
33 #include "scaler.h"
34 #include "version.h"
35 #include "cross.h"
36 #include "config.h"
37
38 using namespace std;
39 using namespace boost;
40
41 static void
42 help (string n)
43 {
44         cerr << "Syntax: " << n << " [OPTION] <FILM>\n"
45              << "  -v, --version      show DVD-o-matic version\n"
46              << "  -h, --help         show this help\n"
47              << "  -d, --deps         list DVD-o-matic dependency details and quit\n"
48              << "  -c, --config       list configuration settings that affect output and quit\n"
49              << "  -t, --test         run in test mode (repeatable UUID generation, timestamps etc.)\n"
50              << "  -n, --no-progress  do not print progress to stdout\n"
51              << "\n"
52              << "<FILM> is the film directory.\n";
53 }
54
55 int
56 main (int argc, char* argv[])
57 {
58         string film_dir;
59         bool test_mode = false;
60         bool progress = true;
61
62         int option_index = 0;
63         while (1) {
64                 static struct option long_options[] = {
65                         { "version", no_argument, 0, 'v'},
66                         { "help", no_argument, 0, 'h'},
67                         { "deps", no_argument, 0, 'd'},
68                         { "config", no_argument, 0, 'c'},
69                         { "test", no_argument, 0, 't'},
70                         { "no-progress", no_argument, 0, 'n'},
71                         { 0, 0, 0, 0 }
72                 };
73
74                 int c = getopt_long (argc, argv, "vhdctn", long_options, &option_index);
75
76                 if (c == -1) {
77                         break;
78                 }
79
80                 switch (c) {
81                 case 'v':
82                         cout << "dvdomatic version " << dvdomatic_version << " " << dvdomatic_git_commit << "\n";
83                         exit (EXIT_SUCCESS);
84                 case 'h':
85                         help (argv[0]);
86                         exit (EXIT_SUCCESS);
87                 case 'd':
88                         cout << dependency_version_summary () << "\n";
89                         exit (EXIT_SUCCESS);
90                 case 't':
91                         test_mode = true;
92                         break;
93                 case 'n':
94                         progress = false;
95                         break;
96                 case 'c':
97                         cout << "Colour LUT " << colour_lut_index_to_name (Config::instance()->colour_lut_index()) << "; "
98                              << "J2K bandwidth " << Config::instance()->j2k_bandwidth() << "; ";
99 #ifdef DVDOMATIC_DEBUG
100                         cout << "built in debug mode\n";
101 #else
102                         cout << "built in optimised mode\n";
103 #endif                  
104                         exit (EXIT_SUCCESS);
105                 }
106         }
107
108         if (optind >= argc) {
109                 help (argv[0]);
110                 exit (EXIT_FAILURE);
111         }
112
113         film_dir = argv[optind];
114                         
115         dvdomatic_setup ();
116
117         cout << "DVD-o-matic " << dvdomatic_version << " git " << dvdomatic_git_commit;
118         char buf[256];
119         if (gethostname (buf, 256) == 0) {
120                 cout << " on " << buf;
121         }
122         cout << "\n";
123
124         if (test_mode) {
125                 libdcp::enable_test_mode ();
126                 cout << dependency_version_summary() << "\n";
127         }
128
129         Film* film = 0;
130         try {
131                 film = new Film (film_dir, true);
132         } catch (std::exception& e) {
133                 cerr << argv[0] << ": error reading film `" << film_dir << "' (" << e.what() << ")\n";
134                 exit (EXIT_FAILURE);
135         }
136
137         cout << "\nMaking ";
138         if (film->dcp_ab ()) {
139                 cout << "A/B ";
140         }
141         cout << "DCP for " << film->name() << "\n";
142         cout << "Test mode: " << (test_mode ? "yes" : "no") << "\n";
143         cout << "Content: " << film->content() << "\n";
144         pair<string, string> const f = Filter::ffmpeg_strings (film->filters ());
145         cout << "Filters: " << f.first << " " << f.second << "\n";
146
147         film->make_dcp (true);
148
149         list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
150
151         bool all_done = false;
152         bool first = true;
153         while (!all_done) {
154
155                 dvdomatic_sleep (5);
156
157                 if (!first && progress) {
158                         cout << "\033[" << jobs.size() << "A";
159                         cout.flush ();
160                 }
161
162                 first = false;
163                 
164                 all_done = true;
165                 for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
166                         if (progress) {
167                                 cout << (*i)->name() << ": ";
168                                 
169                                 float const p = (*i)->overall_progress ();
170                                 
171                                 if (p >= 0) {
172                                         cout << (*i)->status() << "                         \n";
173                                 } else {
174                                         cout << ": Running           \n";
175                                 }
176                         }
177                         
178                         if (!(*i)->finished ()) {
179                                 all_done = false;
180                         }
181
182                         if (!progress && (*i)->finished_in_error ()) {
183                                 /* We won't see this error if we haven't been showing progress,
184                                    so show it now.
185                                 */
186                                 cout << (*i)->status() << "\n";
187                         }
188                 }
189         }
190
191         return 0;
192 }
193
194