Fix first frame being shown even when trimmed (#2952).
authorCarl Hetherington <cth@carlh.net>
Fri, 17 Jan 2025 10:14:32 +0000 (11:14 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 18 Jan 2025 20:06:40 +0000 (21:06 +0100)
We calculated the DCP time of the first frame (when its content was
trimmed) and it was clamped from -8 frames to 0, which meant it was used
when it should not have been.

src/lib/player.cc
test/data
test/video_trim_test.cc [new file with mode: 0644]
test/wscript

index f348f6b2859de1f4b8804d4e442379ee95b26d94..1f44c961cf9c121d7ca222fd2e11766a06f272a7 100644 (file)
@@ -608,7 +608,7 @@ Player::dcp_to_content_time (shared_ptr<const Piece> piece, DCPTime t) const
 DCPTime
 Player::content_time_to_dcp (shared_ptr<const Piece> piece, ContentTime t) const
 {
-       return max (DCPTime(), DCPTime(t - piece->content->trim_start(), piece->frc) + piece->content->position());
+       return DCPTime(t - piece->content->trim_start(), piece->frc) + piece->content->position();
 }
 
 
index dc18332316687dc2e4171e3b5905ea266c357632..c2ad073f0bf7105fb628dbbe2eb82d92bc800dcc 160000 (submodule)
--- a/test/data
+++ b/test/data
@@ -1 +1 @@
-Subproject commit dc18332316687dc2e4171e3b5905ea266c357632
+Subproject commit c2ad073f0bf7105fb628dbbe2eb82d92bc800dcc
diff --git a/test/video_trim_test.cc b/test/video_trim_test.cc
new file mode 100644 (file)
index 0000000..c4b24b4
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+    Copyright (C) 2025 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 "lib/content_factory.h"
+#include "lib/dcpomatic_time.h"
+#include "lib/image_png.h"
+#include "lib/player.h"
+#include "lib/player_video.h"
+#include "test.h"
+#include <boost/test/unit_test.hpp>
+
+
+using std::make_shared;
+using std::shared_ptr;
+
+
+
+BOOST_AUTO_TEST_CASE(video_trim_test)
+{
+       auto content = content_factory("test/data/count300bd24.m2ts")[0];
+       auto film = new_test_film("trim_video_test", { content });
+
+       content->set_trim_start(film, dcpomatic::ContentTime::from_frames(8, 24));
+
+       shared_ptr<PlayerVideo> first_video;
+
+       auto player = make_shared<Player>(film, Image::Alignment::COMPACT);
+       player->Video.connect([&first_video](shared_ptr<PlayerVideo> video, dcpomatic::DCPTime) {
+             first_video = video;
+       });
+
+       while (!first_video) {
+               BOOST_REQUIRE(!player->pass());
+       }
+
+       image_as_png(first_video->image([](AVPixelFormat) { return AV_PIX_FMT_RGB24; }, VideoRange::FULL, true)).write("build/test/video_trim_test.png");
+       check_image("test/data/video_trim_test.png", "build/test/video_trim_test.png");
+}
+
index 8c02f8ebc9b9669f96552290b671543808d2b00e..44f4d9c63db7ed91b92bc2cefe8825d529248c03 100644 (file)
@@ -184,6 +184,7 @@ def build(bld):
                  video_mxf_content_test.cc
                  vf_kdm_test.cc
                  writer_test.cc
+                 video_trim_test.cc
                  zipper_test.cc
                  """