Add some tests; fix failure to make DCP when there is a bit of audio right at the...
[dcpomatic.git] / src / lib / video_content.cc
index 4f1b08016ae7c438da59e10a9204d284408abe2f..92219b4c7cf9be404289d09f1be614f10f75144c 100644 (file)
@@ -32,7 +32,6 @@
 #include "log.h"
 #include <dcp/raw_convert.h>
 #include <libcxml/cxml.h>
-#include <dcp/colour_matrix.h>
 #include <libxml++/libxml++.h>
 #include <iomanip>
 #include <iostream>
@@ -141,7 +140,6 @@ VideoContent::VideoContent (Content* parent, cxml::ConstNodePtr node, int versio
                _scale = VideoContentScale (node->node_child ("Scale"));
        }
 
-
        if (node->optional_node_child ("ColourConversion")) {
                _colour_conversion = ColourConversion (node->node_child ("ColourConversion"), version);
        }
@@ -243,10 +241,14 @@ VideoContent::take_from_examiner (shared_ptr<VideoExaminer> d)
                _sample_aspect_ratio = ar;
                _yuv = yuv;
 
-               /* Guess correct scale from size and sample aspect ratio */
-               _scale = VideoContentScale (
-                       Ratio::nearest_from_ratio (double (_size.width) * ar.get_value_or (1) / _size.height)
-                       );
+               if (Config::instance()->default_scale_to ()) {
+                       _scale = VideoContentScale (Config::instance()->default_scale_to ());
+               } else {
+                       /* Guess correct scale from size and sample aspect ratio */
+                       _scale = VideoContentScale (
+                               Ratio::nearest_from_ratio (double (_size.width) * ar.get_value_or (1) / _size.height)
+                               );
+               }
        }
 
        LOG_GENERAL ("Video length obtained from header as %1 frames", _length);
@@ -407,11 +409,11 @@ VideoContent::processing_description () const
        if ((crop().left || crop().right || crop().top || crop().bottom) && size() != dcp::Size (0, 0)) {
                dcp::Size cropped = size_after_crop ();
                d += String::compose (
-                       _("Cropped to %1x%2"),
+                       _("\nCropped to %1x%2"),
                        cropped.width, cropped.height
                        );
 
-               snprintf (buffer, sizeof(buffer), " (%.2f:1)\n", cropped.ratio());
+               snprintf (buffer, sizeof(buffer), " (%.2f:1)", cropped.ratio());
                d += buffer;
        }
 
@@ -421,33 +423,33 @@ VideoContent::processing_description () const
 
        if (scaled != size_after_crop ()) {
                d += String::compose (
-                       _("Scaled to %1x%2"),
+                       _("\nScaled to %1x%2"),
                        scaled.width, scaled.height
                        );
 
-               snprintf (buffer, sizeof(buffer), _(" (%.2f:1)\n"), scaled.ratio());
+               snprintf (buffer, sizeof(buffer), _(" (%.2f:1)"), scaled.ratio());
                d += buffer;
        }
 
        if (scaled != container_size) {
                d += String::compose (
-                       _("Padded with black to fit container %1 (%2x%3)"),
-                       film->container()->nickname (),
+                       _("\nPadded with black to fit container %1 (%2x%3)"),
+                       film->container()->container_nickname (),
                        container_size.width, container_size.height
                        );
 
-               snprintf (buffer, sizeof(buffer), _(" (%.2f:1)\n"), container_size.ratio());
+               snprintf (buffer, sizeof(buffer), _(" (%.2f:1)"), container_size.ratio());
                d += buffer;
        }
 
        if (_parent->video_frame_rate()) {
                double const vfr = _parent->video_frame_rate().get ();
 
-               snprintf (buffer, sizeof(buffer), _("Content frame rate %.4f\n"), vfr);
+               snprintf (buffer, sizeof(buffer), _("\nContent frame rate %.4f\n"), vfr);
                d += buffer;
 
                FrameRateChange frc (vfr, film->video_frame_rate ());
-               d += frc.description () + "\n";
+               d += frc.description ();
        }
 
        return d;
@@ -457,7 +459,7 @@ void
 VideoContent::add_properties (list<UserProperty>& p) const
 {
        p.push_back (UserProperty (UserProperty::VIDEO, _("Length"), length (), _("video frames")));
-       p.push_back (UserProperty (UserProperty::VIDEO, _("Size"), size().width + "x" + size().height));
+       p.push_back (UserProperty (UserProperty::VIDEO, _("Size"), String::compose ("%1x%2", size().width, size().height)));
 }
 
 void
@@ -525,3 +527,20 @@ VideoContent::set_fade_out (Frame t)
 {
        maybe_set (_fade_out, t, VideoContentProperty::FADE_OUT);
 }
+
+void
+VideoContent::use_template (shared_ptr<const VideoContent> c)
+{
+       _colour_conversion = c->_colour_conversion;
+       _frame_type = c->_frame_type;
+       _crop = c->_crop;
+       _scale = c->_scale;
+       _fade_in = c->_fade_in;
+       _fade_out = c->_fade_out;
+}
+
+void
+VideoContent::modify_position (DCPTime& pos) const
+{
+       pos = pos.ceil (_parent->film()->video_frame_rate());
+}