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[])
84 dcpomatic_setup_path_encoding ();
88 DCPContentType const * dcp_content_type = DCPContentType::from_isdcf_name ("TST");
89 Ratio const * container_ratio = 0;
90 Ratio const * content_ratio = 0;
91 int still_length = 10;
92 dcp::Standard standard = dcp::SMPTE;
93 boost::filesystem::path output;
95 bool use_isdcf_name = true;
99 static struct option long_options[] = {
100 { "version", no_argument, 0, 'v'},
101 { "help", no_argument, 0, 'h'},
102 { "name", required_argument, 0, 'n'},
103 { "dcp-content-type", required_argument, 0, 'c'},
104 { "container-ratio", required_argument, 0, 'A'},
105 { "content-ratio", required_argument, 0, 'B'},
106 { "still-length", required_argument, 0, 's'},
107 { "standard", required_argument, 0, 'C'},
108 { "no-use-isdcf-name", no_argument, 0, 'D'},
109 { "no-sign", no_argument, 0, 'E'},
110 { "output", required_argument, 0, 'o'},
114 int c = getopt_long (argc, argv, "vhn:c:A:B:C:s:o:DE", long_options, &option_index);
121 cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
130 dcp_content_type = DCPContentType::from_isdcf_name (optarg);
131 if (dcp_content_type == 0) {
132 cerr << "Bad DCP content type.\n";
138 container_ratio = Ratio::from_id (optarg);
139 if (container_ratio == 0) {
140 cerr << "Bad container ratio.\n";
146 content_ratio = Ratio::from_id (optarg);
147 if (content_ratio == 0) {
148 cerr << "Bad content ratio " << optarg << ".\n";
154 if (strcmp (optarg, "interop") == 0) {
155 standard = dcp::INTEROP;
156 } else if (strcmp (optarg, "SMPTE") != 0) {
157 cerr << "Bad standard " << optarg << ".\n";
163 use_isdcf_name = false;
169 still_length = atoi (optarg);
185 if (!content_ratio) {
186 cerr << argv[0] << ": missing required option --content-ratio.\n";
190 if (!container_ratio) {
191 container_ratio = content_ratio;
194 if (optind == argc) {
195 cerr << argv[0] << ": no content specified.\n";
199 signal_manager = new SimpleSignalManager ();
202 name = boost::filesystem::path (argv[optind]).leaf().string ();
206 shared_ptr<Film> film (new Film (output, false));
207 film->set_name (name);
209 film->set_container (container_ratio);
210 film->set_dcp_content_type (dcp_content_type);
211 film->set_interop (standard == dcp::INTEROP);
212 film->set_use_isdcf_name (use_isdcf_name);
213 film->set_signed (sign);
215 for (int i = optind; i < argc; ++i) {
216 shared_ptr<Content> c = content_factory (film, argv[i]);
217 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (c);
219 vc->set_scale (VideoContentScale (content_ratio));
221 film->examine_and_add_content (c);
224 JobManager* jm = JobManager::instance ();
226 while (jm->work_to_do ()) {}
227 while (signal_manager->ui_idle() > 0) {}
229 ContentList content = film->content ();
230 for (ContentList::iterator i = content.begin(); i != content.end(); ++i) {
231 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (*i);
233 ic->set_video_length (still_length * 24);
238 list<shared_ptr<Job> > jobs = jm->get ();
239 for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
240 if ((*i)->finished_in_error ()) {
241 cerr << (*i)->error_summary () << "\n"
242 << (*i)->error_details () << "\n";
248 if (!output.empty ()) {
249 film->write_metadata ();
251 film->metadata()->write_to_stream_formatted (cout, "UTF-8");
253 } catch (exception& e) {
254 cerr << argv[0] << ": " << e.what() << "\n";