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.
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 << "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 << " -o, --output <dir> output directory\n";
63 cerr << "Create a film directory (ready for making a DCP) or metadata file from some content files.\n"
64 << "A film directory will be created if -o or --output is specified, otherwise a metadata file\n"
65 << "will be written to stdout.\n";
68 class SimpleSignalManager : public SignalManager
71 /* Do nothing in this method so that UI events happen in our thread
72 when we call SignalManager::ui_idle().
78 main (int argc, char* argv[])
83 DCPContentType const * dcp_content_type = DCPContentType::from_isdcf_name ("TST");
84 Ratio const * container_ratio = 0;
85 Ratio const * content_ratio = 0;
86 int still_length = 10;
87 dcp::Standard standard = dcp::SMPTE;
88 boost::filesystem::path output;
92 static struct option long_options[] = {
93 { "version", no_argument, 0, 'v'},
94 { "help", no_argument, 0, 'h'},
95 { "name", required_argument, 0, 'n'},
96 { "dcp-content-type", required_argument, 0, 'c'},
97 { "container-ratio", required_argument, 0, 'A'},
98 { "content-ratio", required_argument, 0, 'B'},
99 { "still-length", required_argument, 0, 's'},
100 { "standard", required_argument, 0, 'C'},
101 { "output", required_argument, 0, 'o'},
105 int c = getopt_long (argc, argv, "vhn:c:A:B:C:s:o:", long_options, &option_index);
112 cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
121 dcp_content_type = DCPContentType::from_isdcf_name (optarg);
122 if (dcp_content_type == 0) {
123 cerr << "Bad DCP content type.\n";
129 container_ratio = Ratio::from_id (optarg);
130 if (container_ratio == 0) {
131 cerr << "Bad container ratio.\n";
137 content_ratio = Ratio::from_id (optarg);
138 if (content_ratio == 0) {
139 cerr << "Bad content ratio " << optarg << ".\n";
145 if (strcmp (optarg, "interop") == 0) {
146 standard = dcp::INTEROP;
147 } else if (strcmp (optarg, "SMPTE") != 0) {
148 cerr << "Bad standard " << optarg << ".\n";
154 still_length = atoi (optarg);
167 if (!content_ratio) {
168 cerr << argv[0] << ": missing required option --content-ratio.\n";
172 if (!container_ratio) {
173 container_ratio = content_ratio;
176 if (optind == argc) {
177 cerr << argv[0] << ": no content specified.\n";
181 signal_manager = new SimpleSignalManager ();
184 shared_ptr<Film> film (new Film (output, false));
185 if (!name.empty ()) {
186 film->set_name (name);
189 film->set_container (container_ratio);
190 film->set_dcp_content_type (dcp_content_type);
191 film->set_interop (standard == dcp::INTEROP);
193 for (int i = optind; i < argc; ++i) {
194 shared_ptr<Content> c = content_factory (film, argv[i]);
195 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (c);
197 vc->set_scale (VideoContentScale (content_ratio));
199 film->examine_and_add_content (c);
202 JobManager* jm = JobManager::instance ();
204 while (jm->work_to_do ()) {}
205 while (signal_manager->ui_idle() > 0) {}
207 ContentList content = film->content ();
208 for (ContentList::iterator i = content.begin(); i != content.end(); ++i) {
209 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (*i);
211 ic->set_video_length (still_length * 24);
216 list<shared_ptr<Job> > jobs = jm->get ();
217 for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
218 if ((*i)->finished_in_error ()) {
219 cerr << (*i)->error_summary () << "\n"
220 << (*i)->error_details () << "\n";
226 if (!output.empty ()) {
227 film->write_metadata ();
229 film->metadata()->write_to_stream_formatted (cout, "UTF-8");
231 } catch (exception& e) {
232 cerr << argv[0] << ": " << e.what() << "\n";