X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fvideo_content.cc;h=05f5c538eee2a81c6344f603ab2bfa3e60dfd2cb;hb=04533b9cf34ce8089113015715083ee9c5b2b001;hp=9c8ecf0bb7d5c9b595077ced69a80d5aef8884b9;hpb=39bc73fe192f932ed6695eb87b19de446e8b4f55;p=dcpomatic.git diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index 9c8ecf0bb..05f5c538e 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -30,6 +30,7 @@ #include "util.h" #include "film.h" #include "exceptions.h" +#include "frame_rate_change.h" #include "i18n.h" @@ -45,6 +46,8 @@ using std::stringstream; using std::setprecision; using std::cout; using std::vector; +using std::min; +using std::max; using boost::shared_ptr; using boost::optional; using boost::dynamic_pointer_cast; @@ -85,10 +88,17 @@ VideoContent::VideoContent (shared_ptr f, boost::filesystem::path p) VideoContent::VideoContent (shared_ptr f, cxml::ConstNodePtr node, int version) : Content (f, node) { - _video_length = ContentTime (node->number_child ("VideoLength")); _video_size.width = node->number_child ("VideoWidth"); _video_size.height = node->number_child ("VideoHeight"); _video_frame_rate = node->number_child ("VideoFrameRate"); + + if (version < 32) { + /* DCP-o-matic 1.0 branch */ + _video_length = ContentTime::from_frames (node->number_child ("VideoLength"), _video_frame_rate); + } else { + _video_length = ContentTime (node->number_child ("VideoLength")); + } + _video_frame_type = static_cast (node->number_child ("VideoFrameType")); _crop.left = node->number_child ("LeftCrop"); _crop.right = node->number_child ("RightCrop"); @@ -372,6 +382,32 @@ VideoContent::dcp_time_to_content_time (DCPTime t) const return ContentTime (t, FrameRateChange (video_frame_rate(), film->video_frame_rate())); } +void +VideoContent::scale_and_crop_to_fit_width () +{ + shared_ptr film = _film.lock (); + assert (film); + + set_scale (VideoContentScale (film->container ())); + + int const crop = max (0, int (video_size().height - double (film->frame_size().height) * video_size().width / film->frame_size().width)); + set_top_crop (crop / 2); + set_bottom_crop (crop / 2); +} + +void +VideoContent::scale_and_crop_to_fit_height () +{ + shared_ptr film = _film.lock (); + assert (film); + + set_scale (VideoContentScale (film->container ())); + + int const crop = max (0, int (video_size().width - double (film->frame_size().width) * video_size().height / film->frame_size().height)); + set_left_crop (crop / 2); + set_right_crop (crop / 2); +} + VideoContentScale::VideoContentScale (Ratio const * r) : _ratio (r) , _scale (true)