Improve dcpomatic_create somewhat.
authorCarl Hetherington <cth@carlh.net>
Thu, 20 Feb 2014 20:30:04 +0000 (20:30 +0000)
committerCarl Hetherington <cth@carlh.net>
Thu, 20 Feb 2014 20:30:04 +0000 (20:30 +0000)
src/lib/film.cc
src/lib/film.h
src/tools/dcpomatic_create.cc

index f772730015479268f48ccc3fbbb42f03cd756f4a..fb5014b3a08be4b7ae6e90329ee1d35e3f762961 100644 (file)
@@ -93,7 +93,7 @@ int const Film::state_version = 7;
  *  @param dir Film directory.
  */
 
-Film::Film (boost::filesystem::path dir)
+Film::Film (boost::filesystem::path dir, bool log)
        : _playlist (new Playlist)
        , _use_dci_name (true)
        , _dcp_content_type (Config::instance()->default_dcp_content_type ())
@@ -136,7 +136,11 @@ Film::Film (boost::filesystem::path dir)
        }
 
        set_directory (result);
-       _log.reset (new FileLog (file ("log")));
+       if (log) {
+               _log.reset (new FileLog (file ("log")));
+       } else {
+               _log.reset (new NullLog);
+       }
 
        _playlist->set_sequence_video (_sequence_video);
 }
@@ -327,20 +331,13 @@ Film::encoded_frames () const
        return N;
 }
 
-/** Write state to our `metadata' file */
-void
-Film::write_metadata () const
+shared_ptr<xmlpp::Document>
+Film::metadata () const
 {
-       if (!boost::filesystem::exists (directory ())) {
-               boost::filesystem::create_directory (directory ());
-       }
-       
        LocaleGuard lg;
 
-       boost::filesystem::create_directories (directory ());
-
-       xmlpp::Document doc;
-       xmlpp::Element* root = doc.create_root_node ("Metadata");
+       shared_ptr<xmlpp::Document> doc (new xmlpp::Document);
+       xmlpp::Element* root = doc->create_root_node ("Metadata");
 
        root->add_child("Version")->add_child_text (lexical_cast<string> (state_version));
        root->add_child("Name")->add_child_text (_name);
@@ -370,8 +367,16 @@ Film::write_metadata () const
        root->add_child("Key")->add_child_text (_key.hex ());
        _playlist->as_xml (root->add_child ("Playlist"));
 
-       doc.write_to_file_formatted (file("metadata.xml").string ());
-       
+       return doc;
+}
+
+/** Write state to our `metadata' file */
+void
+Film::write_metadata () const
+{
+       boost::filesystem::create_directories (directory ());
+       shared_ptr<xmlpp::Document> doc = metadata ();
+       doc->write_to_file_formatted (file("metadata.xml").string ());
        _dirty = false;
 }
 
index 0a747193eae4debd6fdab184328fbe2156ddcda5..06d19e67ef9f948689de3f61f8236921033f0503 100644 (file)
@@ -56,7 +56,7 @@ class Screen;
 class Film : public boost::enable_shared_from_this<Film>, public boost::noncopyable
 {
 public:
-       Film (boost::filesystem::path);
+       Film (boost::filesystem::path, bool log = true);
 
        boost::filesystem::path info_dir () const;
        boost::filesystem::path j2c_path (int, Eyes, bool) const;
@@ -85,6 +85,7 @@ public:
 
        void read_metadata ();
        void write_metadata () const;
+       boost::shared_ptr<xmlpp::Document> metadata () const;
 
        std::string dci_name (bool if_created_now) const;
        std::string dcp_name (bool if_created_now = false) const;
index 8dc4de50ef278dc66a02b9964a9fd146607086a9..05121652aa7148312affcf820a189d978d9cf08c 100644 (file)
@@ -30,6 +30,8 @@
 #include "lib/job_manager.h"
 #include "lib/ui_signaller.h"
 #include "lib/job.h"
+#include "lib/dcp_content_type.h"
+#include "lib/ratio.h"
 
 using std::string;
 using std::cout;
@@ -37,22 +39,33 @@ using std::cerr;
 using std::list;
 using std::exception;
 using boost::shared_ptr;
+using boost::dynamic_pointer_cast;
 
 static void
 help (string n)
 {
-       cerr << "Create a film directory (ready for making a DCP) from some content files.\n"
+       cerr << "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"
             << "Syntax: " << n << " [OPTION] <CONTENT> [<CONTENT> ...]\n"
-            << "  -v, --version   show DCP-o-matic version\n"
-            << "  -h, --help      show this help\n"
-            << "  -n, --name      film name\n"
-            << "  -o, --output    output directory (required)\n";
+            << "  -v, --version                 show DCP-o-matic version\n"
+            << "  -h, --help                    show this help\n"
+            << "  -n, --name <name>             film name\n"
+            << "  -c, --dcp-content-type <type> FTR, SHR, TLR, TST, XSN, RTG, TSR, POL, PSA or ADV\n"
+            << "      --container-ratio         119, 133, 137, 138, 166, 178, 185 or 239\n"
+            << "      --content-ratio           119, 133, 137, 138, 166, 178, 185 or 239\n"
+            << "  -o, --output <dir>            output directory\n";
 }
 
 int
 main (int argc, char* argv[])
 {
+       dcpomatic_setup ();
+
        string name;
+       DCPContentType const * dcp_content_type = DCPContentType::from_dci_name ("TST");
+       Ratio const * container_ratio = 0;
+       Ratio const * content_ratio = 0;
        boost::filesystem::path output;
        
        int option_index = 0;
@@ -61,11 +74,14 @@ main (int argc, char* argv[])
                        { "version", no_argument, 0, 'v'},
                        { "help", no_argument, 0, 'h'},
                        { "name", required_argument, 0, 'n'},
+                       { "dcp-content-type", required_argument, 0, 'c'},
+                       { "container-ratio", required_argument, 0, 'A'},
+                       { "content-ratio", required_argument, 0, 'B'},
                        { "output", required_argument, 0, 'o'},
                        { 0, 0, 0, 0}
                };
 
-               int c = getopt_long (argc, argv, "vhn:o:", long_options, &option_index);
+               int c = getopt_long (argc, argv, "vhn:c:A:B:o:", long_options, &option_index);
                if (c == -1) {
                        break;
                }
@@ -80,6 +96,30 @@ main (int argc, char* argv[])
                case 'n':
                        name = optarg;
                        break;
+               case 'c':
+                       dcp_content_type = DCPContentType::from_dci_name (optarg);
+                       if (dcp_content_type == 0) {
+                               cerr << "Bad DCP content type.\n";
+                               help (argv[0]);
+                               exit (EXIT_FAILURE);
+                       }
+                       break;
+               case 'A':
+                       container_ratio = Ratio::from_id (optarg);
+                       if (container_ratio == 0) {
+                               cerr << "Bad container ratio.\n";
+                               help (argv[0]);
+                               exit (EXIT_FAILURE);
+                       }
+                       break;
+               case 'B':
+                       content_ratio = Ratio::from_id (optarg);
+                       if (content_ratio == 0) {
+                               cerr << "Bad content ratio " << optarg << ".\n";
+                               help (argv[0]);
+                               exit (EXIT_FAILURE);
+                       }
+                       break;
                case 'o':
                        output = optarg;
                        break;
@@ -91,23 +131,33 @@ main (int argc, char* argv[])
                exit (EXIT_FAILURE);
        }
 
-       if (output.empty ()) {
-               cerr << "Missing required option -o or --output.\n"
-                    << "Use " << argv[0] << " --help for help.\n";
+       if (!content_ratio) {
+               cerr << "Missing required option --content-ratio.\n";
+               help (argv[0]);
                exit (EXIT_FAILURE);
        }
 
-       dcpomatic_setup ();
+       if (!container_ratio) {
+               container_ratio = content_ratio;
+       }
+
        ui_signaller = new UISignaller ();
 
        try {
-               shared_ptr<Film> film (new Film (output));
+               shared_ptr<Film> film (new Film (output, false));
                if (!name.empty ()) {
                        film->set_name (name);
                }
+
+               film->set_container (container_ratio);
                
                for (int i = optind; i < argc; ++i) {
-                       film->examine_and_add_content (content_factory (film, argv[i]));
+                       shared_ptr<Content> c = content_factory (film, argv[i]);
+                       shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (c);
+                       if (vc) {
+                               vc->set_ratio (content_ratio);
+                       }
+                       film->examine_and_add_content (c);
                }
                
                JobManager* jm = JobManager::instance ();
@@ -125,8 +175,12 @@ main (int argc, char* argv[])
                        }
                        exit (EXIT_FAILURE);
                }
-               
-               film->write_metadata ();
+
+               if (!output.empty ()) {
+                       film->write_metadata ();
+               } else {
+                       film->metadata()->write_to_stream_formatted (cout);
+               }
        } catch (exception& e) {
                cerr << argv[0] << ": " << e.what() << "\n";
                exit (EXIT_FAILURE);