summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/create_cli.cc210
-rw-r--r--src/lib/create_cli.h60
-rw-r--r--src/lib/wscript1
3 files changed, 271 insertions, 0 deletions
diff --git a/src/lib/create_cli.cc b/src/lib/create_cli.cc
new file mode 100644
index 000000000..94e984fcf
--- /dev/null
+++ b/src/lib/create_cli.cc
@@ -0,0 +1,210 @@
+/*
+ Copyright (C) 2019 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "create_cli.h"
+#include "dcp_content_type.h"
+#include "ratio.h"
+#include "compose.hpp"
+#include <dcp/raw_convert.h>
+#include <string>
+
+#include <iostream>
+
+using std::string;
+using std::cout;
+using boost::optional;
+
+string CreateCLI::_help =
+ "\nSyntax: %1 [OPTION] <CONTENT> [OPTION] [<CONTENT> ...]\n"
+ " -v, --version show DCP-o-matic version\n"
+ " -h, --help show this help\n"
+ " -n, --name <name> film name\n"
+ " -t, --template <name> template name\n"
+ " -e, --encrypt make an encrypted DCP\n"
+ " -c, --dcp-content-type <type> FTR, SHR, TLR, TST, XSN, RTG, TSR, POL, PSA or ADV\n"
+ " -f, --dcp-frame-rate <rate> set DCP video frame rate (otherwise guessed from content)\n"
+ " --container-ratio <ratio> 119, 133, 137, 138, 166, 178, 185 or 239\n"
+ " --content-ratio <ratio> 119, 133, 137, 138, 166, 178, 185 or 239\n"
+ " -s, --still-length <n> number of seconds that still content should last\n"
+ " --standard <standard> SMPTE or interop (default SMPTE)\n"
+ " --no-use-isdcf-name do not use an ISDCF name; use the specified name unmodified\n"
+ " --no-sign do not sign the DCP\n"
+ " --config <dir> directory containing config.xml and cinemas.xml\n"
+ " -o, --output <dir> output directory\n"
+ " --threed make a 3D DCP\n"
+ " --left-eye next piece of content is for the left eye\n"
+ " --right-eye next piece of content is for the right eye\n";
+
+template <class T>
+void
+argument_option (int& n, int argc, char* argv[], string short_name, string long_name, bool* claimed, optional<string>* error, T* out)
+{
+ string const a = argv[n];
+ if (a != short_name && a != long_name) {
+ return;
+ }
+
+ if ((n + 1) >= argc) {
+ **error = String::compose("%1: option %2 requires an argument", argv[0], long_name);
+ return;
+ }
+
+ *out = dcp::raw_convert<T>(string(argv[++n]));
+ *claimed = true;
+}
+
+CreateCLI::CreateCLI (int argc, char* argv[])
+ : version (false)
+ , encrypt (false)
+ , threed (false)
+ , dcp_content_type (0)
+ , dcp_frame_rate (24)
+ , container_ratio (0)
+ , content_ratio (0)
+ , still_length (10)
+ , standard (dcp::SMPTE)
+ , no_use_isdcf_name (false)
+ , no_sign (false)
+{
+ string dcp_content_type_string = "TST";
+ string content_ratio_string;
+ string container_ratio_string;
+ string standard_string = "SMPTE";
+ int dcp_frame_rate_int = 0;
+ string template_name_string;
+ string config_dir_string;
+ string output_dir_string;
+ VideoFrameType next_frame_type = VIDEO_FRAME_TYPE_2D;
+
+ int i = 1;
+ while (i < argc) {
+ string const a = argv[i];
+ bool claimed = false;
+
+ if (a == "-v" || a == "--version") {
+ version = true;
+ return;
+ } else if (a == "-h" || a == "--help") {
+ error = "Create a film directory (ready for making a DCP) or metadata file from some content files.\n"
+ "A film directory will be created if -o or --output is specified, otherwise a metadata file\n"
+ "will be written to stdout.\n" + String::compose(_help, argv[0]);
+ return;
+ }
+
+ if (a == "-e" || a == "--encrypt") {
+ encrypt = claimed = true;
+ } else if (a == "--no-use-isdcf-name") {
+ no_use_isdcf_name = claimed = true;
+ } else if (a == "--no-sign") {
+ no_sign = claimed = true;
+ } else if (a == "--threed") {
+ threed = claimed = true;
+ } else if (a == "--left-eye") {
+ next_frame_type = VIDEO_FRAME_TYPE_3D_LEFT;
+ claimed = true;
+ } else if (a == "--right-eye") {
+ next_frame_type = VIDEO_FRAME_TYPE_3D_RIGHT;
+ claimed = true;
+ }
+
+ argument_option(i, argc, argv, "-n", "--name", &claimed, &error, &name);
+ argument_option(i, argc, argv, "-t", "--template", &claimed, &error, &template_name_string);
+ argument_option(i, argc, argv, "-c", "--dcp-content-type", &claimed, &error, &dcp_content_type_string);
+ argument_option(i, argc, argv, "-f", "--dcp-frame-rate", &claimed, &error, &dcp_frame_rate_int);
+ argument_option(i, argc, argv, "", "--container-ratio", &claimed, &error, &container_ratio_string);
+ argument_option(i, argc, argv, "", "--content-ratio", &claimed, &error, &content_ratio_string);
+ argument_option(i, argc, argv, "-s", "--still-length", &claimed, &error, &still_length);
+ argument_option(i, argc, argv, "", "--standard", &claimed, &error, &standard_string);
+ argument_option(i, argc, argv, "", "--config", &claimed, &error, &config_dir_string);
+ argument_option(i, argc, argv, "-o", "--output", &claimed, &error, &output_dir_string);
+
+ if (!claimed) {
+ if (a.length() > 2 && a.substr(0, 2) == "--") {
+ error = String::compose("%1: unrecognised option '%2'", argv[0], a) + String::compose(_help, argv[0]);
+ return;
+ } else {
+ Content c;
+ c.path = a;
+ c.frame_type = next_frame_type;
+ content.push_back (c);
+ next_frame_type = VIDEO_FRAME_TYPE_2D;
+ }
+ }
+
+ ++i;
+ }
+
+ if (!config_dir_string.empty()) {
+ config_dir = config_dir_string;
+ }
+
+ if (!output_dir_string.empty()) {
+ output_dir = output_dir_string;
+ }
+
+ if (!template_name_string.empty()) {
+ template_name = template_name_string;
+ }
+
+ if (dcp_frame_rate_int) {
+ dcp_frame_rate = dcp_frame_rate_int;
+ }
+
+ dcp_content_type = DCPContentType::from_isdcf_name(dcp_content_type_string);
+ if (!dcp_content_type) {
+ error = String::compose("%1: unrecognised DCP content type '%2'", argv[0], dcp_content_type_string);
+ return;
+ }
+
+ if (content_ratio_string.empty()) {
+ error = String::compose("%1: missing required option --content-ratio", argv[0]);
+ return;
+ }
+
+ content_ratio = Ratio::from_id (content_ratio_string);
+ if (!content_ratio) {
+ error = String::compose("%1: unrecognised content ratio %2", content_ratio_string);
+ return;
+ }
+
+ if (container_ratio_string.empty()) {
+ container_ratio_string = content_ratio_string;
+ }
+
+ container_ratio = Ratio::from_id (container_ratio_string);
+ if (!container_ratio) {
+ error = String::compose("%1: unrecognised container ratio %2", argv[0], container_ratio_string);
+ return;
+ }
+
+ if (standard_string != "SMPTE" && standard_string != "interop") {
+ error = String::compose("%1: standard must be SMPTE or interop", argv[0]);
+ return;
+ }
+
+ if (content.empty()) {
+ error = String::compose("%1: no content specified", argv[0]);
+ return;
+ }
+
+ if (name.empty()) {
+ name = content[0].path.leaf().string();
+ }
+}
diff --git a/src/lib/create_cli.h b/src/lib/create_cli.h
new file mode 100644
index 000000000..1f1cb3cc4
--- /dev/null
+++ b/src/lib/create_cli.h
@@ -0,0 +1,60 @@
+/*
+ Copyright (C) 2019 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "types.h"
+#include <dcp/types.h>
+#include <boost/optional.hpp>
+#include <boost/filesystem.hpp>
+#include <vector>
+
+class DCPContentType;
+class Ratio;
+
+class CreateCLI
+{
+public:
+ CreateCLI (int argc, char* argv[]);
+
+ struct Content {
+ boost::filesystem::path path;
+ VideoFrameType frame_type;
+ };
+
+ bool version;
+ std::string name;
+ boost::optional<std::string> template_name;
+ bool encrypt;
+ bool threed;
+ DCPContentType const * dcp_content_type;
+ boost::optional<int> dcp_frame_rate;
+ Ratio const * container_ratio;
+ Ratio const * content_ratio;
+ int still_length;
+ dcp::Standard standard;
+ bool no_use_isdcf_name;
+ bool no_sign;
+ boost::optional<boost::filesystem::path> config_dir;
+ boost::optional<boost::filesystem::path> output_dir;
+ boost::optional<std::string> error;
+ std::vector<Content> content;
+
+private:
+ static std::string _help;
+};
diff --git a/src/lib/wscript b/src/lib/wscript
index b78f093cf..9e20131a8 100644
--- a/src/lib/wscript
+++ b/src/lib/wscript
@@ -51,6 +51,7 @@ sources = """
config.cc
content.cc
content_factory.cc
+ create_cli.cc
cross.cc
crypto.cc
curl_uploader.cc