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";
70 class SimpleSignalManager : public SignalManager
73 /* Do nothing in this method so that UI events happen in our thread
74 when we call SignalManager::ui_idle().
80 main (int argc, char* argv[])
85 DCPContentType const * dcp_content_type = DCPContentType::from_isdcf_name ("TST");
86 Ratio const * container_ratio = 0;
87 Ratio const * content_ratio = 0;
88 int still_length = 10;
89 dcp::Standard standard = dcp::SMPTE;
90 boost::filesystem::path output;
94 static struct option long_options[] = {
95 { "version", no_argument, 0, 'v'},
96 { "help", no_argument, 0, 'h'},
97 { "name", required_argument, 0, 'n'},
98 { "dcp-content-type", required_argument, 0, 'c'},
99 { "container-ratio", required_argument, 0, 'A'},
100 { "content-ratio", required_argument, 0, 'B'},
101 { "still-length", required_argument, 0, 's'},
102 { "standard", required_argument, 0, 'C'},
103 { "output", required_argument, 0, 'o'},
107 int c = getopt_long (argc, argv, "vhn:c:A:B:C:s:o:", long_options, &option_index);
114 cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
123 dcp_content_type = DCPContentType::from_isdcf_name (optarg);
124 if (dcp_content_type == 0) {
125 cerr << "Bad DCP content type.\n";
131 container_ratio = Ratio::from_id (optarg);
132 if (container_ratio == 0) {
133 cerr << "Bad container ratio.\n";
139 content_ratio = Ratio::from_id (optarg);
140 if (content_ratio == 0) {
141 cerr << "Bad content ratio " << optarg << ".\n";
147 if (strcmp (optarg, "interop") == 0) {
148 standard = dcp::INTEROP;
149 } else if (strcmp (optarg, "SMPTE") != 0) {
150 cerr << "Bad standard " << optarg << ".\n";
156 still_length = atoi (optarg);
169 if (!content_ratio) {
170 cerr << argv[0] << ": missing required option --content-ratio.\n";
174 if (!container_ratio) {
175 container_ratio = content_ratio;
178 if (optind == argc) {
179 cerr << argv[0] << ": no content specified.\n";
183 signal_manager = new SimpleSignalManager ();
186 name = boost::filesystem::path (argv[optind]).leaf().string ();
190 shared_ptr<Film> film (new Film (output, false));
191 film->set_name (name);
193 film->set_container (container_ratio);
194 film->set_dcp_content_type (dcp_content_type);
195 film->set_interop (standard == dcp::INTEROP);
197 for (int i = optind; i < argc; ++i) {
198 shared_ptr<Content> c = content_factory (film, argv[i]);
199 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (c);
201 vc->set_scale (VideoContentScale (content_ratio));
203 film->examine_and_add_content (c);
206 JobManager* jm = JobManager::instance ();
208 while (jm->work_to_do ()) {}
209 while (signal_manager->ui_idle() > 0) {}
211 ContentList content = film->content ();
212 for (ContentList::iterator i = content.begin(); i != content.end(); ++i) {
213 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (*i);
215 ic->set_video_length (still_length * 24);
220 list<shared_ptr<Job> > jobs = jm->get ();
221 for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
222 if ((*i)->finished_in_error ()) {
223 cerr << (*i)->error_summary () << "\n"
224 << (*i)->error_details () << "\n";
230 if (!output.empty ()) {
231 film->write_metadata ();
233 film->metadata()->write_to_stream_formatted (cout, "UTF-8");
235 } catch (exception& e) {
236 cerr << argv[0] << ": " << e.what() << "\n";