2 Copyright (C) 2013-2015 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.
20 #include "lib/version.h"
23 #include "lib/content_factory.h"
24 #include "lib/job_manager.h"
25 #include "lib/signal_manager.h"
27 #include "lib/dcp_content_type.h"
28 #include "lib/ratio.h"
29 #include "lib/image_content.h"
30 #include <boost/filesystem.hpp>
42 using boost::shared_ptr;
43 using boost::dynamic_pointer_cast;
48 cerr << "Syntax: " << n << " [OPTION] <CONTENT> [<CONTENT> ...]\n"
49 << " -v, --version show DCP-o-matic version\n"
50 << " -h, --help show this help\n"
51 << " -n, --name <name> film name\n"
52 << " -c, --dcp-content-type <type> FTR, SHR, TLR, TST, XSN, RTG, TSR, POL, PSA or ADV\n"
53 << " --container-ratio <ratio> 119, 133, 137, 138, 166, 178, 185 or 239\n"
54 << " --content-ratio <ratio> 119, 133, 137, 138, 166, 178, 185 or 239\n"
55 << " -s, --still-length <n> number of seconds that still content should last\n"
56 << " --standard <standard> SMPTE or interop (default SMPTE)\n"
57 << " --no-use-isdcf-name do not use an ISDCF name; use the specified name unmodified\n"
58 << " --no-sign do not sign the DCP\n"
59 << " -o, --output <dir> output directory\n";
65 cerr << "Create a film directory (ready for making a DCP) or metadata file from some content files.\n"
66 << "A film directory will be created if -o or --output is specified, otherwise a metadata file\n"
67 << "will be written to stdout.\n";
72 class SimpleSignalManager : public SignalManager
75 /* Do nothing in this method so that UI events happen in our thread
76 when we call SignalManager::ui_idle().
82 main (int argc, char* argv[])
87 DCPContentType const * dcp_content_type = DCPContentType::from_isdcf_name ("TST");
88 Ratio const * container_ratio = 0;
89 Ratio const * content_ratio = 0;
90 int still_length = 10;
91 dcp::Standard standard = dcp::SMPTE;
92 boost::filesystem::path output;
94 bool use_isdcf_name = true;
98 static struct option long_options[] = {
99 { "version", no_argument, 0, 'v'},
100 { "help", no_argument, 0, 'h'},
101 { "name", required_argument, 0, 'n'},
102 { "dcp-content-type", required_argument, 0, 'c'},
103 { "container-ratio", required_argument, 0, 'A'},
104 { "content-ratio", required_argument, 0, 'B'},
105 { "still-length", required_argument, 0, 's'},
106 { "standard", required_argument, 0, 'C'},
107 { "no-use-isdcf-name", no_argument, 0, 'D'},
108 { "no-sign", no_argument, 0, 'E'},
109 { "output", required_argument, 0, 'o'},
113 int c = getopt_long (argc, argv, "vhn:c:A:B:C:s:o:DE", long_options, &option_index);
120 cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
129 dcp_content_type = DCPContentType::from_isdcf_name (optarg);
130 if (dcp_content_type == 0) {
131 cerr << "Bad DCP content type.\n";
137 container_ratio = Ratio::from_id (optarg);
138 if (container_ratio == 0) {
139 cerr << "Bad container ratio.\n";
145 content_ratio = Ratio::from_id (optarg);
146 if (content_ratio == 0) {
147 cerr << "Bad content ratio " << optarg << ".\n";
153 if (strcmp (optarg, "interop") == 0) {
154 standard = dcp::INTEROP;
155 } else if (strcmp (optarg, "SMPTE") != 0) {
156 cerr << "Bad standard " << optarg << ".\n";
162 use_isdcf_name = false;
168 still_length = atoi (optarg);
184 if (!content_ratio) {
185 cerr << argv[0] << ": missing required option --content-ratio.\n";
189 if (!container_ratio) {
190 container_ratio = content_ratio;
193 if (optind == argc) {
194 cerr << argv[0] << ": no content specified.\n";
198 signal_manager = new SimpleSignalManager ();
201 name = boost::filesystem::path (argv[optind]).leaf().string ();
205 shared_ptr<Film> film (new Film (output, false));
206 film->set_name (name);
208 film->set_container (container_ratio);
209 film->set_dcp_content_type (dcp_content_type);
210 film->set_interop (standard == dcp::INTEROP);
211 film->set_use_isdcf_name (use_isdcf_name);
212 film->set_signed (sign);
214 for (int i = optind; i < argc; ++i) {
215 shared_ptr<Content> c = content_factory (film, argv[i]);
216 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (c);
218 vc->set_scale (VideoContentScale (content_ratio));
220 film->examine_and_add_content (c);
223 JobManager* jm = JobManager::instance ();
225 while (jm->work_to_do ()) {}
226 while (signal_manager->ui_idle() > 0) {}
228 ContentList content = film->content ();
229 for (ContentList::iterator i = content.begin(); i != content.end(); ++i) {
230 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (*i);
232 ic->set_video_length (still_length * 24);
237 list<shared_ptr<Job> > jobs = jm->get ();
238 for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
239 if ((*i)->finished_in_error ()) {
240 cerr << (*i)->error_summary () << "\n"
241 << (*i)->error_details () << "\n";
247 if (!output.empty ()) {
248 film->write_metadata ();
250 film->metadata()->write_to_stream_formatted (cout, "UTF-8");
252 } catch (exception& e) {
253 cerr << argv[0] << ": " << e.what() << "\n";