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