From 4ee6786d1c3db04dcc77e511121e5d62d0d595b5 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 25 May 2016 13:29:13 +0100 Subject: [PATCH] Add VideoMXFContent (part of #803). --- ChangeLog | 5 ++ src/lib/content_factory.cc | 5 ++ src/lib/player.cc | 11 +++ src/lib/video_mxf_content.cc | 128 +++++++++++++++++++++++++++++++++ src/lib/video_mxf_content.h | 42 +++++++++++ src/lib/video_mxf_decoder.cc | 79 ++++++++++++++++++++ src/lib/video_mxf_decoder.h | 37 ++++++++++ src/lib/video_mxf_examiner.cc | 72 +++++++++++++++++++ src/lib/video_mxf_examiner.h | 41 +++++++++++ src/lib/wscript | 3 + test/video_mxf_content_test.cc | 60 ++++++++++++++++ test/wscript | 1 + 12 files changed, 484 insertions(+) create mode 100644 src/lib/video_mxf_content.cc create mode 100644 src/lib/video_mxf_content.h create mode 100644 src/lib/video_mxf_decoder.cc create mode 100644 src/lib/video_mxf_decoder.h create mode 100644 src/lib/video_mxf_examiner.cc create mode 100644 src/lib/video_mxf_examiner.h create mode 100644 test/video_mxf_content_test.cc diff --git a/ChangeLog b/ChangeLog index 8c58805ff..a5f49d658 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-05-25 c.hetherington + + * Treat video MXFs better by not transcoding + them unless necessary (part of #803). + 2016-05-24 c.hetherington * Add somewhat speculative Rec 1886 and Rec 2020 diff --git a/src/lib/content_factory.cc b/src/lib/content_factory.cc index e21a4c0d0..706c79754 100644 --- a/src/lib/content_factory.cc +++ b/src/lib/content_factory.cc @@ -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 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 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) { diff --git a/src/lib/player.cc b/src/lib/player.cc index cd841d1ce..0c513056c 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -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 vmc = dynamic_pointer_cast (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 index 000000000..f049965d4 --- /dev/null +++ b/src/lib/video_mxf_content.cc @@ -0,0 +1,128 @@ +/* + Copyright (C) 2016 Carl Hetherington + + 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 +#include +#include +#include + +#include "i18n.h" + +using std::list; +using std::string; +using boost::shared_ptr; + +VideoMXFContent::VideoMXFContent (shared_ptr film, boost::filesystem::path path) + : Content (film, path) +{ + +} + +VideoMXFContent::VideoMXFContent (shared_ptr 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 mp (new dcp::MonoPictureAsset (path)); + return true; + } catch (dcp::MXFFileError& e) { + + } catch (dcp::DCPReadError& e) { + + } + + try { + shared_ptr sp (new dcp::StereoPictureAsset (path)); + return true; + } catch (dcp::MXFFileError& e) { + + } catch (dcp::DCPReadError& e) { + + } + + return false; +} + +void +VideoMXFContent::examine (shared_ptr job) +{ + job->set_progress_unknown (); + + Content::examine (job); + + video.reset (new VideoContent (this)); + shared_ptr 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& 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 index 000000000..788af11a1 --- /dev/null +++ b/src/lib/video_mxf_content.h @@ -0,0 +1,42 @@ +/* + Copyright (C) 2016 Carl Hetherington + + 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 film, boost::filesystem::path path); + VideoMXFContent (boost::shared_ptr film, cxml::ConstNodePtr node, int version); + + boost::shared_ptr shared_from_this () { + return boost::dynamic_pointer_cast (Content::shared_from_this ()); + } + + void examine (boost::shared_ptr 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& 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 index 000000000..e8b787d8d --- /dev/null +++ b/src/lib/video_mxf_decoder.cc @@ -0,0 +1,79 @@ +/* + Copyright (C) 2016 Carl Hetherington + + 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 +#include +#include + +using boost::shared_ptr; + +VideoMXFDecoder::VideoMXFDecoder (shared_ptr content, shared_ptr log) + : _content (content) +{ + video.reset (new VideoDecoder (this, content, log)); +} + +bool +VideoMXFDecoder::pass (PassReason reason, bool) +{ + shared_ptr 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 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 (new J2KImageProxy (mono->get_frame(frame), mono->size())), frame); + } else { + video->give (shared_ptr (new J2KImageProxy (stereo->get_frame(frame), stereo->size(), dcp::EYE_LEFT)), frame); + video->give (shared_ptr (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 index 000000000..fa9bfe818 --- /dev/null +++ b/src/lib/video_mxf_decoder.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2016 Carl Hetherington + + 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, boost::shared_ptr log); + +private: + bool pass (PassReason, bool accurate); + void seek (ContentTime t, bool accurate); + + boost::shared_ptr _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 index 000000000..506e6985c --- /dev/null +++ b/src/lib/video_mxf_examiner.cc @@ -0,0 +1,72 @@ +/* + Copyright (C) 2016 Carl Hetherington + + 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 +#include +#include + +using boost::shared_ptr; +using boost::optional; + +VideoMXFExaminer::VideoMXFExaminer (shared_ptr 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 +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 +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 index 000000000..a16e76747 --- /dev/null +++ b/src/lib/video_mxf_examiner.h @@ -0,0 +1,41 @@ +/* + Copyright (C) 2016 Carl Hetherington + + 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); + + boost::optional video_frame_rate () const; + dcp::Size video_size () const; + Frame video_length () const; + boost::optional sample_aspect_ratio () const; + bool yuv () const; + +private: + boost::shared_ptr _asset; +}; diff --git a/src/lib/wscript b/src/lib/wscript index 6a9f5106c..727a398af 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -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 index 000000000..a42fe1a68 --- /dev/null +++ b/test/video_mxf_content_test.cc @@ -0,0 +1,60 @@ +/* + Copyright (C) 2016 Carl Hetherington + + 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 +#include + +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 = 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_factory (film, ref_mxf); + shared_ptr check = dynamic_pointer_cast (content); + BOOST_REQUIRE (check); + film->examine_and_add_content (content); + wait_for_jobs (); + film->make_dcp (); + wait_for_jobs (); + + shared_ptr ref (new dcp::MonoPictureAsset (ref_mxf)); + boost::filesystem::directory_iterator i ("build/test/video_mxf_content_test/video"); + shared_ptr comp (new dcp::MonoPictureAsset (*i)); + dcp::EqualityOptions op; + BOOST_CHECK (ref->equals (comp, op, note)); +} diff --git a/test/wscript b/test/wscript index 1ddc25d70..1dc498bab 100644 --- a/test/wscript +++ b/test/wscript @@ -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 """ -- 2.30.2