2 Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "frame_rate_change.h"
22 #include "compose.hpp"
29 about_equal (float a, float b)
31 /* A film of F seconds at f FPS will be Ff frames;
32 Consider some delta FPS d, so if we run the same
33 film at (f + d) FPS it will last F(f + d) seconds.
35 Hence the difference in length over the length of the film will
36 be F(f + d) - Ff frames
41 So if we accept a difference of 1 frame, ie 1/f seconds, we can
48 So for a 3hr film, ie F = 3 * 60 * 60 = 10800, the acceptable
49 FPS error is 1/F ~= 0.0001 ~= 10-e4
52 return (fabs (a - b) < 1e-4);
56 FrameRateChange::FrameRateChange (float source_, int dcp_)
61 , change_speed (false)
63 if (fabs (source / 2.0 - dcp) < fabs (source - dcp)) {
64 /* The difference between source and DCP frame rate will be lower
65 (i.e. better) if we skip.
68 } else if (fabs (source * 2 - dcp) < fabs (source - dcp)) {
69 /* The difference between source and DCP frame rate would be better
70 if we repeated each frame once; it may be better still if we
71 repeated more than once. Work out the required repeat.
73 repeat = round (dcp / source);
76 speed_up = dcp / (source * factor());
77 change_speed = !about_equal (speed_up, 1.0);
81 FrameRateChange::description () const
85 if (!skip && repeat == 1 && !change_speed) {
86 description = _("Content and DCP have the same rate.\n");
89 description = _("DCP will use every other frame of the content.\n");
90 } else if (repeat == 2) {
91 description = _("Each content frame will be doubled in the DCP.\n");
92 } else if (repeat > 2) {
93 description = String::compose (_("Each content frame will be repeated %1 more times in the DCP.\n"), repeat - 1);
97 float const pc = dcp * 100 / (source * factor());
98 description += String::compose (_("DCP will run at %1%% of the content speed.\n"), pc);