From eeaca1992aa117fe3a2a4a079d8a20a01d88e933 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 8 Apr 2022 00:43:28 +0200 Subject: [PATCH] Guess video range better when importing 2.14.x projects (#2227). --- src/lib/dcp_content.cc | 2 +- src/lib/ffmpeg_content.cc | 7 +++++-- src/lib/image_content.cc | 2 +- src/lib/video_content.cc | 17 ++++++++++++----- src/lib/video_content.h | 4 ++-- src/lib/video_mxf_content.cc | 2 +- test/data | 2 +- test/film_metadata_test.cc | 36 ++++++++++++++++++++++++++++++++++++ 8 files changed, 59 insertions(+), 13 deletions(-) diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc index 6df0588e9..f8639cef9 100644 --- a/src/lib/dcp_content.cc +++ b/src/lib/dcp_content.cc @@ -95,7 +95,7 @@ DCPContent::DCPContent (boost::filesystem::path p) DCPContent::DCPContent (cxml::ConstNodePtr node, int version) : Content (node) { - video = VideoContent::from_xml (this, node, version); + video = VideoContent::from_xml (this, node, version, VideoRange::FULL); audio = AudioContent::from_xml (this, node, version); list notes; text = TextContent::from_xml (this, node, version, notes); diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 9017ad605..c791309ad 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -90,7 +90,11 @@ get_optional_enum (cxml::ConstNodePtr node, string name) FFmpegContent::FFmpegContent (cxml::ConstNodePtr node, int version, list& notes) : Content (node) { - video = VideoContent::from_xml (this, node, version); + _color_range = get_optional_enum(node, "ColorRange"); + + VideoRange const video_range_hint = (_color_range && *_color_range == AVCOL_RANGE_JPEG) ? VideoRange::FULL : VideoRange::VIDEO; + + video = VideoContent::from_xml (this, node, version, video_range_hint); audio = AudioContent::from_xml (this, node, version); text = TextContent::from_xml (this, node, version, notes); @@ -124,7 +128,6 @@ FFmpegContent::FFmpegContent (cxml::ConstNodePtr node, int version, list _first_video = ContentTime (f.get ()); } - _color_range = get_optional_enum(node, "ColorRange"); _color_primaries = get_optional_enum(node, "ColorPrimaries"); _color_trc = get_optional_enum(node, "ColorTransferCharacteristic"); _colorspace = get_optional_enum(node, "Colorspace"); diff --git a/src/lib/image_content.cc b/src/lib/image_content.cc index 9464babd4..d8f482a3b 100644 --- a/src/lib/image_content.cc +++ b/src/lib/image_content.cc @@ -61,7 +61,7 @@ ImageContent::ImageContent (boost::filesystem::path p) ImageContent::ImageContent (cxml::ConstNodePtr node, int version) : Content (node) { - video = VideoContent::from_xml (this, node, version); + video = VideoContent::from_xml (this, node, version, VideoRange::FULL); } diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index 51d6ba418..86efeee7b 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -86,17 +86,20 @@ VideoContent::VideoContent (Content* parent) } +/** @param video_range_hint Video range to use if none is given in the XML */ shared_ptr -VideoContent::from_xml (Content* parent, cxml::ConstNodePtr node, int version) +VideoContent::from_xml (Content* parent, cxml::ConstNodePtr node, int version, VideoRange video_range_hint) { if (!node->optional_number_child ("VideoWidth")) { return {}; } - return make_shared(parent, node, version); + return make_shared(parent, node, version, video_range_hint); } -VideoContent::VideoContent (Content* parent, cxml::ConstNodePtr node, int version) + +/** @param video_range_hint Video range to use if none is given in the XML */ +VideoContent::VideoContent (Content* parent, cxml::ConstNodePtr node, int version, VideoRange video_range_hint) : ContentPart (parent) { _size.width = node->number_child ("VideoWidth"); @@ -185,8 +188,12 @@ VideoContent::VideoContent (Content* parent, cxml::ConstNodePtr node, int versio _fade_in = _fade_out = 0; } - _range = VideoRange::FULL; - if (node->optional_string_child("Range").get_value_or("full") == "video") { + auto video_range = node->optional_string_child("Range"); + if (!video_range) { + _range = video_range_hint; + } else if (*video_range == "full") { + _range = VideoRange::FULL; + } else { _range = VideoRange::VIDEO; } diff --git a/src/lib/video_content.h b/src/lib/video_content.h index 2adf941d9..3ec884578 100644 --- a/src/lib/video_content.h +++ b/src/lib/video_content.h @@ -60,7 +60,7 @@ class VideoContent : public ContentPart, public std::enable_shared_from_this>); void as_xml (xmlpp::Node *) const; @@ -216,7 +216,7 @@ public: void modify_position (std::shared_ptr film, dcpomatic::DCPTime& pos) const; void modify_trim_start (dcpomatic::ContentTime& pos) const; - static std::shared_ptr from_xml (Content* parent, cxml::ConstNodePtr, int); + static std::shared_ptr from_xml (Content* parent, cxml::ConstNodePtr node, int version, VideoRange video_range_hint); private: diff --git a/src/lib/video_mxf_content.cc b/src/lib/video_mxf_content.cc index c7ee69d89..c6165172a 100644 --- a/src/lib/video_mxf_content.cc +++ b/src/lib/video_mxf_content.cc @@ -51,7 +51,7 @@ VideoMXFContent::VideoMXFContent (boost::filesystem::path path) VideoMXFContent::VideoMXFContent (cxml::ConstNodePtr node, int version) : Content (node) { - video = VideoContent::from_xml (this, node, version); + video = VideoContent::from_xml (this, node, version, VideoRange::FULL); } diff --git a/test/data b/test/data index 796f3e657..6b3ced6ff 160000 --- a/test/data +++ b/test/data @@ -1 +1 @@ -Subproject commit 796f3e657f63985b360447a437c1d30be1ccaa28 +Subproject commit 6b3ced6ff12cca13b1765c16bbdface28040e444 diff --git a/test/film_metadata_test.cc b/test/film_metadata_test.cc index 62cb5cf1d..5c44c2a91 100644 --- a/test/film_metadata_test.cc +++ b/test/film_metadata_test.cc @@ -32,6 +32,7 @@ #include "lib/film.h" #include "lib/ratio.h" #include "lib/text_content.h" +#include "lib/video_content.h" #include "test.h" #include #include @@ -174,3 +175,38 @@ BOOST_AUTO_TEST_CASE (metadata_loads_from_2_14_x_4) BOOST_REQUIRE (!film->luminance()); } + +BOOST_AUTO_TEST_CASE (metadata_video_range_guessed_for_dcp) +{ + namespace fs = boost::filesystem; + auto film = make_shared(fs::path("test/data/214x_dcp")); + film->read_metadata(); + + BOOST_REQUIRE_EQUAL(film->content().size(), 1U); + BOOST_REQUIRE(film->content()[0]->video); + BOOST_CHECK(film->content()[0]->video->range() == VideoRange::FULL); +} + + +BOOST_AUTO_TEST_CASE (metadata_video_range_guessed_for_mp4_with_unknown_range) +{ + namespace fs = boost::filesystem; + auto film = make_shared(fs::path("test/data/214x_mp4")); + film->read_metadata(); + + BOOST_REQUIRE_EQUAL(film->content().size(), 1U); + BOOST_REQUIRE(film->content()[0]->video); + BOOST_CHECK(film->content()[0]->video->range() == VideoRange::VIDEO); +} + + +BOOST_AUTO_TEST_CASE (metadata_video_range_guessed_for_png) +{ + namespace fs = boost::filesystem; + auto film = make_shared(fs::path("test/data/214x_png")); + film->read_metadata(); + + BOOST_REQUIRE_EQUAL(film->content().size(), 1U); + BOOST_REQUIRE(film->content()[0]->video); + BOOST_CHECK(film->content()[0]->video->range() == VideoRange::FULL); +} -- 2.30.2