Add VideoMXFContent (part of #803).
authorCarl Hetherington <cth@carlh.net>
Wed, 25 May 2016 12:29:13 +0000 (13:29 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 25 May 2016 12:29:13 +0000 (13:29 +0100)
12 files changed:
ChangeLog
src/lib/content_factory.cc
src/lib/player.cc
src/lib/video_mxf_content.cc [new file with mode: 0644]
src/lib/video_mxf_content.h [new file with mode: 0644]
src/lib/video_mxf_decoder.cc [new file with mode: 0644]
src/lib/video_mxf_decoder.h [new file with mode: 0644]
src/lib/video_mxf_examiner.cc [new file with mode: 0644]
src/lib/video_mxf_examiner.h [new file with mode: 0644]
src/lib/wscript
test/video_mxf_content_test.cc [new file with mode: 0644]
test/wscript

index 8c58805ff437c84c12c64a78a0338e9859e5987e..a5f49d6580f4f5ec925f52993d997a8cf1b09720 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-05-25  c.hetherington  <cth@carlh.net>
+
+       * Treat video MXFs better by not transcoding
+       them unless necessary (part of #803).
+
 2016-05-24  c.hetherington  <cth@carlh.net>
 
        * Add somewhat speculative Rec 1886 and Rec 2020
index e21a4c0d0760f721247b94066f14f3ee609458ec..706c7975403b9110d10e1c834a325216d6b18667 100644 (file)
@@ -29,6 +29,7 @@
 #include "dcp_subtitle_content.h"
 #include "util.h"
 #include "ffmpeg_audio_stream.h"
+#include "video_mxf_content.h"
 #include "film.h"
 #include "log_entry.h"
 #include "log.h"
@@ -87,6 +88,8 @@ content_factory (shared_ptr<const Film> film, cxml::NodePtr node, int version, l
                content.reset (new DCPContent (film, node, version));
        } else if (type == "DCPSubtitle") {
                content.reset (new DCPSubtitleContent (film, node, version));
+       } else if (type == "VideoMXF") {
+               content.reset (new VideoMXFContent (film, node, version));
        }
 
        return content;
@@ -162,6 +165,8 @@ content_factory (shared_ptr<const Film> film, boost::filesystem::path path)
                        content.reset (new DCPSubtitleContent (film, path));
                } else if (ext == ".mxf" && dcp::SMPTESubtitleAsset::valid_mxf (path)) {
                        content.reset (new DCPSubtitleContent (film, path));
+               } else if (ext == ".mxf" && VideoMXFContent::valid_mxf (path)) {
+                       content.reset (new VideoMXFContent (film, path));
                }
 
                if (!content) {
index cd841d1ce565fc36cb833ec3ad06952a0d89c5e4..0c513056c56e45ddc1e301d001da346862de7401 100644 (file)
@@ -31,6 +31,8 @@
 #include "subtitle_content.h"
 #include "text_subtitle_decoder.h"
 #include "text_subtitle_content.h"
+#include "video_mxf_decoder.h"
+#include "video_mxf_content.h"
 #include "dcp_content.h"
 #include "job.h"
 #include "image.h"
@@ -179,6 +181,15 @@ Player::setup_pieces ()
                        frc = FrameRateChange (dsc->active_video_frame_rate(), _film->video_frame_rate());
                }
 
+               /* VideoMXFContent */
+               shared_ptr<const VideoMXFContent> vmc = dynamic_pointer_cast<const VideoMXFContent> (i);
+               if (vmc) {
+                       decoder.reset (new VideoMXFDecoder (vmc, _film->log()));
+                       frc = FrameRateChange (vmc->active_video_frame_rate(), _film->video_frame_rate());
+               }
+
+               DCPOMATIC_ASSERT (decoder);
+
                if (decoder->video && _ignore_video) {
                        decoder->video->set_ignore ();
                }
diff --git a/src/lib/video_mxf_content.cc b/src/lib/video_mxf_content.cc
new file mode 100644 (file)
index 0000000..f049965
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "video_mxf_examiner.h"
+#include "video_mxf_content.h"
+#include "video_content.h"
+#include "job.h"
+#include "film.h"
+#include "compose.hpp"
+#include <dcp/mono_picture_asset.h>
+#include <dcp/stereo_picture_asset.h>
+#include <dcp/exceptions.h>
+#include <libxml++/libxml++.h>
+
+#include "i18n.h"
+
+using std::list;
+using std::string;
+using boost::shared_ptr;
+
+VideoMXFContent::VideoMXFContent (shared_ptr<const Film> film, boost::filesystem::path path)
+       : Content (film, path)
+{
+
+}
+
+VideoMXFContent::VideoMXFContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
+       : Content (film, node)
+{
+       video = VideoContent::from_xml (this, node, version);
+}
+
+bool
+VideoMXFContent::valid_mxf (boost::filesystem::path path)
+{
+       try {
+               shared_ptr<dcp::MonoPictureAsset> mp (new dcp::MonoPictureAsset (path));
+               return true;
+       } catch (dcp::MXFFileError& e) {
+
+       } catch (dcp::DCPReadError& e) {
+
+       }
+
+       try {
+               shared_ptr<dcp::StereoPictureAsset> sp (new dcp::StereoPictureAsset (path));
+               return true;
+       } catch (dcp::MXFFileError& e) {
+
+       } catch (dcp::DCPReadError& e) {
+
+       }
+
+       return false;
+}
+
+void
+VideoMXFContent::examine (shared_ptr<Job> job)
+{
+       job->set_progress_unknown ();
+
+       Content::examine (job);
+
+       video.reset (new VideoContent (this));
+       shared_ptr<VideoMXFExaminer> examiner (new VideoMXFExaminer (shared_from_this ()));
+       video->take_from_examiner (examiner);
+}
+
+string
+VideoMXFContent::summary () const
+{
+       return String::compose (_("%1 [video]"), path_summary());
+}
+
+string
+VideoMXFContent::technical_summary () const
+{
+       return Content::technical_summary() + " - " + video->technical_summary ();
+}
+
+string
+VideoMXFContent::identifier () const
+{
+       return Content::identifier() + "_" + video->identifier();
+}
+
+void
+VideoMXFContent::as_xml (xmlpp::Node* node) const
+{
+       node->add_child("Type")->add_child_text ("VideoMXF");
+       Content::as_xml (node);
+       video->as_xml (node);
+}
+
+DCPTime
+VideoMXFContent::full_length () const
+{
+       FrameRateChange const frc (active_video_frame_rate(), film()->video_frame_rate());
+       return DCPTime::from_frames (llrint (video->length_after_3d_combine() * frc.factor()), film()->video_frame_rate());
+}
+
+void
+VideoMXFContent::add_properties (list<UserProperty>& p) const
+{
+       video->add_properties (p);
+}
+
+void
+VideoMXFContent::set_default_colour_conversion ()
+{
+       video->unset_colour_conversion ();
+}
diff --git a/src/lib/video_mxf_content.h b/src/lib/video_mxf_content.h
new file mode 100644 (file)
index 0000000..788af11
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "content.h"
+
+class VideoMXFContent : public Content
+{
+public:
+       VideoMXFContent (boost::shared_ptr<const Film> film, boost::filesystem::path path);
+       VideoMXFContent (boost::shared_ptr<const Film> film, cxml::ConstNodePtr node, int version);
+
+       boost::shared_ptr<VideoMXFContent> shared_from_this () {
+               return boost::dynamic_pointer_cast<VideoMXFContent> (Content::shared_from_this ());
+       }
+
+       void examine (boost::shared_ptr<Job> job);
+       std::string summary () const;
+       std::string technical_summary () const;
+       std::string identifier () const;
+       void as_xml (xmlpp::Node* node) const;
+       DCPTime full_length () const;
+       void add_properties (std::list<UserProperty>& p) const;
+       void set_default_colour_conversion ();
+
+       static bool valid_mxf (boost::filesystem::path path);
+};
diff --git a/src/lib/video_mxf_decoder.cc b/src/lib/video_mxf_decoder.cc
new file mode 100644 (file)
index 0000000..e8b787d
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "video_mxf_decoder.h"
+#include "video_decoder.h"
+#include "video_mxf_content.h"
+#include "j2k_image_proxy.h"
+#include <dcp/mono_picture_asset.h>
+#include <dcp/stereo_picture_asset.h>
+#include <dcp/exceptions.h>
+
+using boost::shared_ptr;
+
+VideoMXFDecoder::VideoMXFDecoder (shared_ptr<const VideoMXFContent> content, shared_ptr<Log> log)
+       : _content (content)
+{
+       video.reset (new VideoDecoder (this, content, log));
+}
+
+bool
+VideoMXFDecoder::pass (PassReason reason, bool)
+{
+       shared_ptr<dcp::MonoPictureAsset> mono;
+       try {
+               mono.reset (new dcp::MonoPictureAsset (_content->path(0)));
+       } catch (dcp::MXFFileError& e) {
+               /* maybe it's stereo */
+       } catch (dcp::DCPReadError& e) {
+               /* maybe it's stereo */
+       }
+
+       shared_ptr<dcp::StereoPictureAsset> stereo;
+       try {
+               stereo.reset (new dcp::StereoPictureAsset (_content->path(0)));
+       } catch (dcp::MXFFileError& e) {
+               if (!mono) {
+                       throw;
+               }
+       } catch (dcp::DCPReadError& e) {
+               if (!mono) {
+                       throw;
+               }
+       }
+
+       double const vfr = _content->active_video_frame_rate ();
+       int64_t const frame = _next.frames_round (vfr);
+
+       if (mono) {
+               video->give (shared_ptr<ImageProxy> (new J2KImageProxy (mono->get_frame(frame), mono->size())), frame);
+       } else {
+               video->give (shared_ptr<ImageProxy> (new J2KImageProxy (stereo->get_frame(frame), stereo->size(), dcp::EYE_LEFT)), frame);
+               video->give (shared_ptr<ImageProxy> (new J2KImageProxy (stereo->get_frame(frame), stereo->size(), dcp::EYE_RIGHT)), frame);
+       }
+
+       _next += ContentTime::from_frames (1, vfr);
+}
+
+void
+VideoMXFDecoder::seek (ContentTime t, bool accurate)
+{
+       video->seek (t, accurate);
+       _next = t;
+}
diff --git a/src/lib/video_mxf_decoder.h b/src/lib/video_mxf_decoder.h
new file mode 100644 (file)
index 0000000..fa9bfe8
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "decoder.h"
+
+class VideoMXFContent;
+class Log;
+
+class VideoMXFDecoder : public Decoder
+{
+public:
+       VideoMXFDecoder (boost::shared_ptr<const VideoMXFContent>, boost::shared_ptr<Log> log);
+
+private:
+       bool pass (PassReason, bool accurate);
+       void seek (ContentTime t, bool accurate);
+
+       boost::shared_ptr<const VideoMXFContent> _content;
+       /** Time of next thing to return from pass */
+       ContentTime _next;
+};
diff --git a/src/lib/video_mxf_examiner.cc b/src/lib/video_mxf_examiner.cc
new file mode 100644 (file)
index 0000000..506e698
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "video_mxf_content.h"
+#include "video_mxf_examiner.h"
+#include <dcp/exceptions.h>
+#include <dcp/mono_picture_asset.h>
+#include <dcp/stereo_picture_asset.h>
+
+using boost::shared_ptr;
+using boost::optional;
+
+VideoMXFExaminer::VideoMXFExaminer (shared_ptr<const VideoMXFContent> content)
+{
+       try {
+               _asset.reset (new dcp::MonoPictureAsset (content->path(0)));
+       } catch (dcp::MXFFileError& e) {
+               /* maybe it's stereo */
+       } catch (dcp::DCPReadError& e) {
+               /* maybe it's stereo */
+       }
+
+       if (!_asset) {
+               _asset.reset (new dcp::StereoPictureAsset (content->path(0)));
+       }
+}
+
+optional<double>
+VideoMXFExaminer::video_frame_rate () const
+{
+       return _asset->frame_rate().as_float ();
+}
+
+dcp::Size
+VideoMXFExaminer::video_size () const
+{
+       return _asset->size ();
+}
+
+Frame
+VideoMXFExaminer::video_length () const
+{
+       return _asset->intrinsic_duration ();
+}
+
+optional<double>
+VideoMXFExaminer::sample_aspect_ratio () const
+{
+       return 1.0;
+}
+
+bool
+VideoMXFExaminer::yuv () const
+{
+       return false;
+}
diff --git a/src/lib/video_mxf_examiner.h b/src/lib/video_mxf_examiner.h
new file mode 100644 (file)
index 0000000..a16e767
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "video_examiner.h"
+
+class VideoMXFContent;
+
+namespace dcp {
+       class PictureAsset;
+}
+
+class VideoMXFExaminer : public VideoExaminer
+{
+public:
+       VideoMXFExaminer (boost::shared_ptr<const VideoMXFContent>);
+
+       boost::optional<double> video_frame_rate () const;
+       dcp::Size video_size () const;
+       Frame video_length () const;
+       boost::optional<double> sample_aspect_ratio () const;
+       bool yuv () const;
+
+private:
+       boost::shared_ptr<dcp::PictureAsset> _asset;
+};
index 6a9f5106c1752986aa9129c7bc494c1d9dff8d94..727a398af146bc19a7b0ddedc96580a215b8e8fb 100644 (file)
@@ -136,6 +136,9 @@ sources = """
           video_content_scale.cc
           video_decoder.cc
           video_filter_graph.cc
+          video_mxf_content.cc
+          video_mxf_decoder.cc
+          video_mxf_examiner.cc
           writer.cc
           """
 
diff --git a/test/video_mxf_content_test.cc b/test/video_mxf_content_test.cc
new file mode 100644 (file)
index 0000000..a42fe1a
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "lib/film.h"
+#include "lib/video_mxf_content.h"
+#include "lib/content_factory.h"
+#include "lib/dcp_content_type.h"
+#include "lib/ratio.h"
+#include "test.h"
+#include <dcp/mono_picture_asset.h>
+#include <boost/test/unit_test.hpp>
+
+using boost::shared_ptr;
+using boost::dynamic_pointer_cast;
+
+static boost::filesystem::path ref_mxf = "test/data/scaling_test_185_185/j2c_a41afbff-e1ad-41c4-9a84-de315b95dd0f.mxf";
+
+static void note (dcp::NoteType, std::string)
+{
+
+}
+
+/** Basic test of using video MXF content */
+BOOST_AUTO_TEST_CASE (video_mxf_content_test)
+{
+       shared_ptr<Film> film = new_test_film ("video_mxf_content_test");
+       film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
+       film->set_container (Ratio::from_id ("185"));
+       film->set_name ("video_mxf_content_test");
+
+       shared_ptr<Content> content = content_factory (film, ref_mxf);
+       shared_ptr<VideoMXFContent> check = dynamic_pointer_cast<VideoMXFContent> (content);
+       BOOST_REQUIRE (check);
+       film->examine_and_add_content (content);
+       wait_for_jobs ();
+       film->make_dcp ();
+       wait_for_jobs ();
+
+       shared_ptr<dcp::MonoPictureAsset> ref (new dcp::MonoPictureAsset (ref_mxf));
+       boost::filesystem::directory_iterator i ("build/test/video_mxf_content_test/video");
+       shared_ptr<dcp::MonoPictureAsset> comp (new dcp::MonoPictureAsset (*i));
+       dcp::EqualityOptions op;
+       BOOST_CHECK (ref->equals (comp, op, note));
+}
index 1ddc25d702d333c9ef32d132336bcb3475461f51..1dc498baba7a7d37dd8a04c27c567ca340c4fe83 100644 (file)
@@ -93,6 +93,7 @@ def build(bld):
                  vf_test.cc
                  video_content_scale_test.cc
                  video_decoder_fill_test.cc
+                 video_mxf_content_test.cc
                  xml_subtitle_test.cc
                  """