Guess video range better when importing 2.14.x projects (#2227).
authorCarl Hetherington <cth@carlh.net>
Thu, 7 Apr 2022 22:43:28 +0000 (00:43 +0200)
committerCarl Hetherington <cth@carlh.net>
Thu, 7 Apr 2022 22:43:28 +0000 (00:43 +0200)
src/lib/dcp_content.cc
src/lib/ffmpeg_content.cc
src/lib/image_content.cc
src/lib/video_content.cc
src/lib/video_content.h
src/lib/video_mxf_content.cc
test/data
test/film_metadata_test.cc

index 6df0588e972fb439f6eb0b501bc9e1c7b5d99ea4..f8639cef9cc187f7ed2b35bc2821d955329be0e9 100644 (file)
@@ -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<string> notes;
        text = TextContent::from_xml (this, node, version, notes);
index 9017ad605dd9cb021e10e46bfcff307cc34c3f46..c791309ad04dae2280ce31b4e6146e4385b3ace8 100644 (file)
@@ -90,7 +90,11 @@ get_optional_enum (cxml::ConstNodePtr node, string name)
 FFmpegContent::FFmpegContent (cxml::ConstNodePtr node, int version, list<string>& notes)
        : Content (node)
 {
-       video = VideoContent::from_xml (this, node, version);
+       _color_range = get_optional_enum<AVColorRange>(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<string>
                _first_video = ContentTime (f.get ());
        }
 
-       _color_range = get_optional_enum<AVColorRange>(node, "ColorRange");
        _color_primaries = get_optional_enum<AVColorPrimaries>(node, "ColorPrimaries");
        _color_trc = get_optional_enum<AVColorTransferCharacteristic>(node, "ColorTransferCharacteristic");
        _colorspace = get_optional_enum<AVColorSpace>(node, "Colorspace");
index 9464babd4656fe61f3aa65fa6bfd7775f095b334..d8f482a3b3bcc63c38dac6264b86910cf0bfe8bc 100644 (file)
@@ -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);
 }
 
 
index 51d6ba418f8848e9d32862fc91da113bec60788a..86efeee7b3606ed7d0262da664aa6c4b33bdadec 100644 (file)
@@ -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>
-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<int> ("VideoWidth")) {
                return {};
        }
 
-       return make_shared<VideoContent>(parent, node, version);
+       return make_shared<VideoContent>(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<int> ("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;
        }
 
index 2adf941d97cc3cd4a26a5b0e0c13ca33abd95464..3ec88457823f980bd9ea62b3abf1a4337251ac71 100644 (file)
@@ -60,7 +60,7 @@ class VideoContent : public ContentPart, public std::enable_shared_from_this<Vid
 {
 public:
        explicit VideoContent (Content* parent);
-       VideoContent (Content* parent, cxml::ConstNodePtrint);
+       VideoContent (Content* parent, cxml::ConstNodePtr node, int version, VideoRange video_range_hint);
        VideoContent (Content* parent, std::vector<std::shared_ptr<Content>>);
 
        void as_xml (xmlpp::Node *) const;
@@ -216,7 +216,7 @@ public:
        void modify_position (std::shared_ptr<const Film> film, dcpomatic::DCPTime& pos) const;
        void modify_trim_start (dcpomatic::ContentTime& pos) const;
 
-       static std::shared_ptr<VideoContent> from_xml (Content* parent, cxml::ConstNodePtrint);
+       static std::shared_ptr<VideoContent> from_xml (Content* parent, cxml::ConstNodePtr node, int version, VideoRange video_range_hint);
 
 private:
 
index c7ee69d8932c647b62835ef5d12b5a82ab0ea391..c6165172adf96995c6f76264c09da871d0300947 100644 (file)
@@ -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);
 }
 
 
index 796f3e657f63985b360447a437c1d30be1ccaa28..6b3ced6ff12cca13b1765c16bbdface28040e444 160000 (submodule)
--- a/test/data
+++ b/test/data
@@ -1 +1 @@
-Subproject commit 796f3e657f63985b360447a437c1d30be1ccaa28
+Subproject commit 6b3ced6ff12cca13b1765c16bbdface28040e444
index 62cb5cf1d562f47a95868b70a3416cba03bb9e5b..5c44c2a91377204e5a19e2da91dc8ddc131507ad 100644 (file)
@@ -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 <boost/date_time.hpp>
 #include <boost/filesystem.hpp>
@@ -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<Film>(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<Film>(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<Film>(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);
+}