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/ui_signaller.h"
33 #include "lib/dcp_content_type.h"
34 #include "lib/ratio.h"
41 using boost::shared_ptr;
42 using boost::dynamic_pointer_cast;
47 cerr << "Create a film directory (ready for making a DCP) or metadata file from some content files.\n"
48 << "A film directory will be created if -o or --output is specified, otherwise a metadata file\n"
49 << "will be written to stdout.\n"
50 << "Syntax: " << n << " [OPTION] <CONTENT> [<CONTENT> ...]\n"
51 << " -v, --version show DCP-o-matic version\n"
52 << " -h, --help show this help\n"
53 << " -n, --name <name> film name\n"
54 << " -c, --dcp-content-type <type> FTR, SHR, TLR, TST, XSN, RTG, TSR, POL, PSA or ADV\n"
55 << " --container-ratio 119, 133, 137, 138, 166, 178, 185 or 239\n"
56 << " --content-ratio 119, 133, 137, 138, 166, 178, 185 or 239\n"
57 << " -o, --output <dir> output directory\n";
61 main (int argc, char* argv[])
66 DCPContentType const * dcp_content_type = DCPContentType::from_dci_name ("TST");
67 Ratio const * container_ratio = 0;
68 Ratio const * content_ratio = 0;
69 boost::filesystem::path output;
73 static struct option long_options[] = {
74 { "version", no_argument, 0, 'v'},
75 { "help", no_argument, 0, 'h'},
76 { "name", required_argument, 0, 'n'},
77 { "dcp-content-type", required_argument, 0, 'c'},
78 { "container-ratio", required_argument, 0, 'A'},
79 { "content-ratio", required_argument, 0, 'B'},
80 { "output", required_argument, 0, 'o'},
84 int c = getopt_long (argc, argv, "vhn:c:A:B:o:", long_options, &option_index);
91 cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
100 dcp_content_type = DCPContentType::from_dci_name (optarg);
101 if (dcp_content_type == 0) {
102 cerr << "Bad DCP content type.\n";
108 container_ratio = Ratio::from_id (optarg);
109 if (container_ratio == 0) {
110 cerr << "Bad container ratio.\n";
116 content_ratio = Ratio::from_id (optarg);
117 if (content_ratio == 0) {
118 cerr << "Bad content ratio " << optarg << ".\n";
134 if (!content_ratio) {
135 cerr << "Missing required option --content-ratio.\n";
140 if (!container_ratio) {
141 container_ratio = content_ratio;
144 ui_signaller = new UISignaller ();
147 shared_ptr<Film> film (new Film (output, false));
148 if (!name.empty ()) {
149 film->set_name (name);
152 film->set_container (container_ratio);
154 for (int i = optind; i < argc; ++i) {
155 shared_ptr<Content> c = content_factory (film, argv[i]);
156 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (c);
158 vc->set_ratio (content_ratio);
160 film->examine_and_add_content (c);
163 JobManager* jm = JobManager::instance ();
164 while (jm->work_to_do ()) {
165 ui_signaller->ui_idle ();
169 list<shared_ptr<Job> > jobs = jm->get ();
170 for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
171 if ((*i)->finished_in_error ()) {
172 cerr << (*i)->error_summary () << "\n"
173 << (*i)->error_details () << "\n";
179 if (!output.empty ()) {
180 film->write_metadata ();
182 film->metadata()->write_to_stream_formatted (cout);
184 } catch (exception& e) {
185 cerr << argv[0] << ": " << e.what() << "\n";