Move things round a bit.
[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 "format.h"
24 #include "film.h"
25 #include "filter.h"
26 #include "transcode_job.h"
27 #include "make_mxf_job.h"
28 #include "make_dcp_job.h"
29 #include "job_manager.h"
30 #include "ab_transcode_job.h"
31 #include "util.h"
32 #include "scaler.h"
33
34 using namespace std;
35 using namespace boost;
36
37 static void
38 help (string n)
39 {
40         cerr << "Syntax: " << n << " [--help] [--deps] [--film <film>]\n";
41 }
42
43 int
44 main (int argc, char* argv[])
45 {
46         string film_dir;
47
48         while (1) {
49                 static struct option long_options[] = {
50                         { "help", no_argument, 0, 'h'},
51                         { "deps", no_argument, 0, 'd'},
52                         { "film", required_argument, 0, 'f'},
53                         { 0, 0, 0, 0 }
54                 };
55
56                 int option_index = 0;
57                 int c = getopt_long (argc, argv, "hdf:", long_options, &option_index);
58
59                 if (c == -1) {
60                         break;
61                 }
62
63                 switch (c) {
64                 case 'h':
65                         help (argv[0]);
66                         exit (EXIT_SUCCESS);
67                 case 'd':
68                         cout << dependency_version_summary () << "\n";
69                         exit (EXIT_SUCCESS);
70                 case 'f':
71                         film_dir = optarg;
72                         break;
73                 }
74         }
75
76         if (film_dir.empty ()) {
77                 help (argv[0]);
78                 exit (EXIT_FAILURE);
79         }
80                         
81         dvdomatic_setup ();
82
83         Film* film = 0;
84         try {
85                 film = new Film (film_dir, true);
86         } catch (std::exception& e) {
87                 cerr << argv[0] << ": error reading film `" << film_dir << "' (" << e.what() << ")\n";
88                 exit (EXIT_FAILURE);
89         }
90
91         cout << "\nMaking ";
92         if (film->dcp_ab ()) {
93                 cout << "A/B ";
94         }
95         cout << "DCP for " << film->name() << "\n";
96         cout << "Content: " << film->content() << "\n";
97         pair<string, string> const f = Filter::ffmpeg_strings (film->filters ());
98         cout << "Filters: " << f.first << " " << f.second << "\n";
99
100         film->make_dcp (true);
101
102         list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
103
104         bool all_done = false;
105         bool first = true;
106         while (!all_done) {
107                 
108                 sleep (5);
109                 
110                 if (!first) {
111                         cout << "\033[" << jobs.size() << "A";
112                         cout.flush ();
113                 }
114
115                 first = false;
116                 
117                 all_done = true;
118                 for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
119                         cout << (*i)->name() << ": ";
120
121                         float const p = (*i)->overall_progress ();
122
123                         if (p >= 0) {
124                                 cout << (*i)->status() << "                         \n";
125                         } else {
126                                 cout << ": Running           \n";
127                         }
128                         
129                         if (!(*i)->finished ()) {
130                                 all_done = false;
131                         }
132                 }
133         }
134
135         return 0;
136 }
137
138