From 6a18a737ef8dfbfbe909afe8266f104a2125b5fb Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 1 Jun 2016 22:45:58 +0100 Subject: [PATCH 1/1] Store video frame rate in XML (#883). --- src/lib/content.cc | 16 ++++++++++++++++ src/lib/frame_rate_change.cc | 28 ++++------------------------ src/lib/types.h | 22 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/lib/content.cc b/src/lib/content.cc index 7afbf924f..66b0d477e 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -95,6 +95,7 @@ Content::Content (shared_ptr film, cxml::ConstNodePtr node) _position = DCPTime (node->number_child ("Position")); _trim_start = ContentTime (node->number_child ("TrimStart")); _trim_end = ContentTime (node->number_child ("TrimEnd")); + _video_frame_rate = node->optional_number_child ("VideoFrameRate"); } Content::Content (shared_ptr film, vector > c) @@ -102,6 +103,7 @@ Content::Content (shared_ptr film, vector > c) , _position (c.front()->position ()) , _trim_start (c.front()->trim_start ()) , _trim_end (c.back()->trim_end ()) + , _video_frame_rate (c.front()->video_frame_rate()) , _change_signals_frequent (false) { for (size_t i = 0; i < c.size(); ++i) { @@ -113,6 +115,17 @@ Content::Content (shared_ptr film, vector > c) throw JoinError (_("Only the last piece of content to be joined can have an end trim.")); } + if ( + (_video_frame_rate && !c[i]->_video_frame_rate) || + (!_video_frame_rate && c[i]->_video_frame_rate) + ) { + throw JoinError (_("Content to be joined must have the same video frame rate")); + } + + if (_video_frame_rate && fabs (_video_frame_rate.get() - c[i]->_video_frame_rate.get()) > VIDEO_FRAME_RATE_EPSILON) { + throw JoinError (_("Content to be joined must have the same video frame rate")); + } + for (size_t j = 0; j < c[i]->number_of_paths(); ++j) { _paths.push_back (c[i]->path (j)); } @@ -131,6 +144,9 @@ Content::as_xml (xmlpp::Node* node) const node->add_child("Position")->add_child_text (raw_convert (_position.get ())); node->add_child("TrimStart")->add_child_text (raw_convert (_trim_start.get ())); node->add_child("TrimEnd")->add_child_text (raw_convert (_trim_end.get ())); + if (_video_frame_rate) { + node->add_child("VideoFrameRate")->add_child_text (raw_convert (_video_frame_rate.get())); + } } void diff --git a/src/lib/frame_rate_change.cc b/src/lib/frame_rate_change.cc index 8b2d6cf99..80a167029 100644 --- a/src/lib/frame_rate_change.cc +++ b/src/lib/frame_rate_change.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2015 Carl Hetherington + Copyright (C) 2012-2016 Carl Hetherington This file is part of DCP-o-matic. @@ -18,9 +18,10 @@ */ -#include #include "frame_rate_change.h" +#include "types.h" #include "compose.hpp" +#include #include "i18n.h" @@ -29,28 +30,7 @@ using std::string; static bool about_equal (double a, double b) { - /* A film of F seconds at f FPS will be Ff frames; - Consider some delta FPS d, so if we run the same - film at (f + d) FPS it will last F(f + d) seconds. - - Hence the difference in length over the length of the film will - be F(f + d) - Ff frames - = Ff + Fd - Ff frames - = Fd frames - = Fd/f seconds - - So if we accept a difference of 1 frame, ie 1/f seconds, we can - say that - - 1/f = Fd/f - ie 1 = Fd - ie d = 1/F - - So for a 3hr film, ie F = 3 * 60 * 60 = 10800, the acceptable - FPS error is 1/F ~= 0.0001 ~= 10-e4 - */ - - return (fabs (a - b) < 1e-4); + return (fabs (a - b) < VIDEO_FRAME_RATE_EPSILON); } diff --git a/src/lib/types.h b/src/lib/types.h index d9bee97c6..ab51e38a9 100644 --- a/src/lib/types.h +++ b/src/lib/types.h @@ -48,6 +48,28 @@ namespace xmlpp { */ #define SERVER_LINK_VERSION (64+0) +/** A film of F seconds at f FPS will be Ff frames; + Consider some delta FPS d, so if we run the same + film at (f + d) FPS it will last F(f + d) seconds. + + Hence the difference in length over the length of the film will + be F(f + d) - Ff frames + = Ff + Fd - Ff frames + = Fd frames + = Fd/f seconds + + So if we accept a difference of 1 frame, ie 1/f seconds, we can + say that + + 1/f = Fd/f + ie 1 = Fd + ie d = 1/F + + So for a 3hr film, ie F = 3 * 60 * 60 = 10800, the acceptable + FPS error is 1/F ~= 0.0001 ~= 1e-4 +*/ +#define VIDEO_FRAME_RATE_EPSILON (1e-4) + typedef std::vector > ContentList; typedef std::vector > FFmpegContentList; -- 2.30.2