Fix various problems caused by non-integer-frame start trims,
authorCarl Hetherington <cth@carlh.net>
Mon, 11 Dec 2017 01:06:37 +0000 (01:06 +0000)
committerCarl Hetherington <cth@carlh.net>
Mon, 11 Dec 2017 01:06:37 +0000 (01:06 +0000)
and also by the inability of content_video_to_dcp to return
negative values.  The latter is necessary for tests on "is this
content too early" to work.

src/lib/content.cc
src/lib/content_factory.cc
src/lib/player.cc
src/lib/video_content.cc
src/lib/video_content.h
test/data

index 691d3a66a546dd85c934d5f505e7e7cc74658f4f..f1246489292f560f08a90e960ed4c0da5df4f77a 100644 (file)
@@ -210,6 +210,11 @@ Content::set_position (DCPTime p)
 void
 Content::set_trim_start (ContentTime t)
 {
+       /* video content can modify its start trim */
+       if (video) {
+               video->modify_trim_start (t);
+       }
+
        {
                boost::mutex::scoped_lock lm (_mutex);
                _trim_start = t;
index 8aa432b0929b34c656a6c2113755cc14b1becdba..51dc4e1b333d57e4c4308a22ef94ad38248091ec 100644 (file)
@@ -119,6 +119,26 @@ content_factory (shared_ptr<const Film> film, cxml::NodePtr node, int version, l
                notes.push_back (note);
        }
 
+       /* ...or have a start trim which is an integer number of frames */
+       ContentTime const old_trim = content->trim_start();
+       content->set_trim_start(old_trim);
+       if (old_trim != content->trim_start()) {
+               string note = _("Your project contains video content whose trim was not aligned to a frame boundary.");
+               note += "  ";
+               if (old_trim < content->trim_start()) {
+                       note += String::compose(
+                               _("The file %1 has been trimmed by %2 milliseconds more."),
+                               content->path_summary(), ContentTime(content->trim_start() - old_trim).seconds() * 1000
+                               );
+               } else {
+                       note += String::compose(
+                               _("The file %1 has been trimmed by %2 milliseconds less."),
+                               content->path_summary(), ContentTime(old_trim - content->trim_start()).seconds() * 1000
+                               );
+               }
+               notes.push_back (note);
+       }
+
        return content;
 }
 
index f91e3a7f2eb9f3b17ced0fc6939db13c8e1f2ae4..0bc460465e0dc5b9036a7c43a86ecdacced628a4 100644 (file)
@@ -346,8 +346,8 @@ DCPTime
 Player::content_video_to_dcp (shared_ptr<const Piece> piece, Frame f) const
 {
        /* See comment in dcp_to_content_video */
-       DCPTime const d = DCPTime::from_frames (f * piece->frc.factor(), piece->frc.dcp) - DCPTime (piece->content->trim_start (), piece->frc);
-       return max (DCPTime (), d + piece->content->position ());
+       DCPTime const d = DCPTime::from_frames (f * piece->frc.factor(), piece->frc.dcp) - DCPTime(piece->content->trim_start(), piece->frc);
+       return d + piece->content->position();
 }
 
 Frame
index 92219b4c7cf9be404289d09f1be614f10f75144c..cd96e19bc8b85100d9a052889870a28dd8d01761 100644 (file)
@@ -544,3 +544,9 @@ VideoContent::modify_position (DCPTime& pos) const
 {
        pos = pos.ceil (_parent->film()->video_frame_rate());
 }
+
+void
+VideoContent::modify_trim_start (ContentTime& trim) const
+{
+       trim = trim.ceil (_parent->video_frame_rate().get());
+}
index 19ea113f76fed45232cf3e8e06ffc2a66beb8d2c..412d4d034d96e032676d96c5baf386da1bca8aac 100644 (file)
@@ -169,6 +169,7 @@ public:
        void add_properties (std::list<UserProperty> &) const;
 
        void modify_position (DCPTime& pos) const;
+       void modify_trim_start (ContentTime& pos) const;
 
        static boost::shared_ptr<VideoContent> from_xml (Content* parent, cxml::ConstNodePtr, int);
 
index cfcc6d6e4e145614460a6c4194d7a9f88cd7b85d..b5e37d2b241a6397b7d53bef57b49d409adf236a 160000 (submodule)
--- a/test/data
+++ b/test/data
@@ -1 +1 @@
-Subproject commit cfcc6d6e4e145614460a6c4194d7a9f88cd7b85d
+Subproject commit b5e37d2b241a6397b7d53bef57b49d409adf236a