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 <libxml++/libxml++.h>
31 #include <boost/filesystem.hpp>
43 using boost::shared_ptr;
44 using boost::dynamic_pointer_cast;
49 cerr << "Syntax: " << n << " [OPTION] <CONTENT> [<CONTENT> ...]\n"
50 << " -v, --version show DCP-o-matic version\n"
51 << " -h, --help show this help\n"
52 << " -n, --name <name> film name\n"
53 << " -c, --dcp-content-type <type> FTR, SHR, TLR, TST, XSN, RTG, TSR, POL, PSA or ADV\n"
54 << " --container-ratio <ratio> 119, 133, 137, 138, 166, 178, 185 or 239\n"
55 << " --content-ratio <ratio> 119, 133, 137, 138, 166, 178, 185 or 239\n"
56 << " -s, --still-length <n> number of seconds that still content should last\n"
57 << " --standard <standard> SMPTE or interop (default SMPTE)\n"
58 << " --no-use-isdcf-name do not use an ISDCF name; use the specified name unmodified\n"
59 << " --no-sign do not sign the DCP\n"
60 << " -o, --output <dir> output directory\n";
66 cerr << "Create a film directory (ready for making a DCP) or metadata file from some content files.\n"
67 << "A film directory will be created if -o or --output is specified, otherwise a metadata file\n"
68 << "will be written to stdout.\n";
73 class SimpleSignalManager : public SignalManager
76 /* Do nothing in this method so that UI events happen in our thread
77 when we call SignalManager::ui_idle().
83 main (int argc, char* argv[])
85 dcpomatic_setup_path_encoding ();
89 DCPContentType const * dcp_content_type = DCPContentType::from_isdcf_name ("TST");
90 Ratio const * container_ratio = 0;
91 Ratio const * content_ratio = 0;
92 int still_length = 10;
93 dcp::Standard standard = dcp::SMPTE;
94 boost::filesystem::path output;
96 bool use_isdcf_name = true;
100 static struct option long_options[] = {
101 { "version", no_argument, 0, 'v'},
102 { "help", no_argument, 0, 'h'},
103 { "name", required_argument, 0, 'n'},
104 { "dcp-content-type", required_argument, 0, 'c'},
105 { "container-ratio", required_argument, 0, 'A'},
106 { "content-ratio", required_argument, 0, 'B'},
107 { "still-length", required_argument, 0, 's'},
108 { "standard", required_argument, 0, 'C'},
109 { "no-use-isdcf-name", no_argument, 0, 'D'},
110 { "no-sign", no_argument, 0, 'E'},
111 { "output", required_argument, 0, 'o'},
115 int c = getopt_long (argc, argv, "vhn:c:A:B:C:s:o:DE", long_options, &option_index);
122 cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
131 dcp_content_type = DCPContentType::from_isdcf_name (optarg);
132 if (dcp_content_type == 0) {
133 cerr << "Bad DCP content type.\n";
139 container_ratio = Ratio::from_id (optarg);
140 if (container_ratio == 0) {
141 cerr << "Bad container ratio.\n";
147 content_ratio = Ratio::from_id (optarg);
148 if (content_ratio == 0) {
149 cerr << "Bad content ratio " << optarg << ".\n";
155 if (strcmp (optarg, "interop") == 0) {
156 standard = dcp::INTEROP;
157 } else if (strcmp (optarg, "SMPTE") != 0) {
158 cerr << "Bad standard " << optarg << ".\n";
164 use_isdcf_name = false;
170 still_length = atoi (optarg);
186 if (!content_ratio) {
187 cerr << argv[0] << ": missing required option --content-ratio.\n";
191 if (!container_ratio) {
192 container_ratio = content_ratio;
195 if (optind == argc) {
196 cerr << argv[0] << ": no content specified.\n";
200 signal_manager = new SimpleSignalManager ();
203 name = boost::filesystem::path (argv[optind]).leaf().string ();
207 shared_ptr<Film> film (new Film (output, false));
208 film->set_name (name);
210 film->set_container (container_ratio);
211 film->set_dcp_content_type (dcp_content_type);
212 film->set_interop (standard == dcp::INTEROP);
213 film->set_use_isdcf_name (use_isdcf_name);
214 film->set_signed (sign);
216 for (int i = optind; i < argc; ++i) {
217 shared_ptr<Content> c = content_factory (film, argv[i]);
218 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (c);
220 vc->set_scale (VideoContentScale (content_ratio));
222 film->examine_and_add_content (c);
225 JobManager* jm = JobManager::instance ();
227 while (jm->work_to_do ()) {}
228 while (signal_manager->ui_idle() > 0) {}
230 ContentList content = film->content ();
231 for (ContentList::iterator i = content.begin(); i != content.end(); ++i) {
232 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (*i);
234 ic->set_video_length (still_length * 24);
239 list<shared_ptr<Job> > jobs = jm->get ();
240 for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
241 if ((*i)->finished_in_error ()) {
242 cerr << (*i)->error_summary () << "\n"
243 << (*i)->error_details () << "\n";
249 if (!output.empty ()) {
250 film->write_metadata ();
252 film->metadata()->write_to_stream_formatted (cout, "UTF-8");
254 } catch (exception& e) {
255 cerr << argv[0] << ": " << e.what() << "\n";