2 Copyright (C) 2013 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.
25 #include <boost/filesystem.hpp>
26 #include "lib/version.h"
29 #include "lib/content_factory.h"
30 #include "lib/job_manager.h"
31 #include "lib/signal_manager.h"
33 #include "lib/dcp_content_type.h"
34 #include "lib/ratio.h"
35 #include "lib/image_content.h"
42 using boost::shared_ptr;
43 using boost::dynamic_pointer_cast;
48 cerr << "Create a film directory (ready for making a DCP) or metadata file from some content files.\n"
49 << "A film directory will be created if -o or --output is specified, otherwise a metadata file\n"
50 << "will be written to stdout.\n"
51 << "Syntax: " << n << " [OPTION] <CONTENT> [<CONTENT> ...]\n"
52 << " -v, --version show DCP-o-matic version\n"
53 << " -h, --help show this help\n"
54 << " -n, --name <name> film name\n"
55 << " -c, --dcp-content-type <type> FTR, SHR, TLR, TST, XSN, RTG, TSR, POL, PSA or ADV\n"
56 << " --container-ratio <ratio> 119, 133, 137, 138, 166, 178, 185 or 239\n"
57 << " --content-ratio <ratio> 119, 133, 137, 138, 166, 178, 185 or 239\n"
58 << " -s, --still-length <n> number of seconds that still content should last\n"
59 << " -o, --output <dir> output directory\n";
62 class SimpleSignalManager : public SignalManager
65 /* Do nothing in this method so that UI events happen in our thread
66 when we call SignalManager::ui_idle().
72 main (int argc, char* argv[])
77 DCPContentType const * dcp_content_type = DCPContentType::from_isdcf_name ("TST");
78 Ratio const * container_ratio = 0;
79 Ratio const * content_ratio = 0;
80 int still_length = 10;
81 boost::filesystem::path output;
85 static struct option long_options[] = {
86 { "version", no_argument, 0, 'v'},
87 { "help", no_argument, 0, 'h'},
88 { "name", required_argument, 0, 'n'},
89 { "dcp-content-type", required_argument, 0, 'c'},
90 { "container-ratio", required_argument, 0, 'A'},
91 { "content-ratio", required_argument, 0, 'B'},
92 { "still-length", required_argument, 0, 's'},
93 { "output", required_argument, 0, 'o'},
97 int c = getopt_long (argc, argv, "vhn:c:A:B:s:o:", long_options, &option_index);
104 cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
113 dcp_content_type = DCPContentType::from_isdcf_name (optarg);
114 if (dcp_content_type == 0) {
115 cerr << "Bad DCP content type.\n";
121 container_ratio = Ratio::from_id (optarg);
122 if (container_ratio == 0) {
123 cerr << "Bad container ratio.\n";
129 content_ratio = Ratio::from_id (optarg);
130 if (content_ratio == 0) {
131 cerr << "Bad content ratio " << optarg << ".\n";
137 still_length = atoi (optarg);
150 if (!content_ratio) {
151 cerr << argv[0] << ": missing required option --content-ratio.\n";
155 if (!container_ratio) {
156 container_ratio = content_ratio;
159 if (optind == argc) {
160 cerr << argv[0] << ": no content specified.\n";
164 signal_manager = new SimpleSignalManager ();
167 shared_ptr<Film> film (new Film (output, false));
168 if (!name.empty ()) {
169 film->set_name (name);
172 film->set_container (container_ratio);
173 film->set_dcp_content_type (dcp_content_type);
175 for (int i = optind; i < argc; ++i) {
176 shared_ptr<Content> c = content_factory (film, argv[i]);
177 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (c);
179 vc->set_scale (VideoContentScale (content_ratio));
181 film->examine_and_add_content (c);
184 JobManager* jm = JobManager::instance ();
186 while (jm->work_to_do ()) {}
187 while (signal_manager->ui_idle() > 0) {}
189 ContentList content = film->content ();
190 for (ContentList::iterator i = content.begin(); i != content.end(); ++i) {
191 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (*i);
193 ic->set_video_length (still_length * 24);
198 list<shared_ptr<Job> > jobs = jm->get ();
199 for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
200 if ((*i)->finished_in_error ()) {
201 cerr << (*i)->error_summary () << "\n"
202 << (*i)->error_details () << "\n";
208 if (!output.empty ()) {
209 film->write_metadata ();
211 film->metadata()->write_to_stream_formatted (cout, "UTF-8");
213 } catch (exception& e) {
214 cerr << argv[0] << ": " << e.what() << "\n";