Skip to content

Commit

Permalink
Deal with "close" timecode rates via a heuristic, instead of misleadi…
Browse files Browse the repository at this point in the history
…ng entries in valid_timecode_rates table.

Signed-off-by: Joshua Minor <[email protected]>
  • Loading branch information
jminor committed May 11, 2023
1 parent 23ff3f9 commit 661a556
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/opentime/rationalTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ namespace opentime { namespace OPENTIME_VERSION {

RationalTime RationalTime::_invalid_time{ 0, RationalTime::_invalid_rate };

static constexpr std::array<double, 4> dropframe_timecode_rates{ {
// 23.976,
// 23.98,
// 23.97,
// 24000.0/1001.0,
29.97,
static constexpr std::array<double, 2> dropframe_timecode_rates{ {
30000.0 / 1001.0,
59.94,
60000.0 / 1001.0,
} };

Expand All @@ -38,12 +32,9 @@ static constexpr std::array<double, 11> smpte_timecode_rates{
60.0 }
};

static constexpr std::array<double, 16> valid_timecode_rates{
static constexpr std::array<double, 12> valid_timecode_rates{
{ 1.0,
12.0,
23.97,
23.976,
23.98,
24000.0 / 1001.0,
24.0,
25.0,
Expand All @@ -52,7 +43,6 @@ static constexpr std::array<double, 16> valid_timecode_rates{
30.0,
48.0,
50.0,
59.94,
60000.0 / 1001.0,
60.0 }
};
Expand Down Expand Up @@ -460,7 +450,8 @@ RationalTime::to_timecode(
return std::string();
}

if (!is_valid_timecode_rate(rate))
double nearest_valid_rate = nearest_valid_timecode_rate(rate);
if (abs(nearest_valid_rate - rate) > 0.1)
{
if (error_status)
{
Expand All @@ -469,6 +460,9 @@ RationalTime::to_timecode(
return std::string();
}

// Let's assume this is the rate instead of the given rate.
rate = nearest_valid_rate;

bool rate_is_dropframe = is_dropframe_rate(rate);
if (drop_frame == IsDropFrameRate::ForceYes and not rate_is_dropframe)
{
Expand Down Expand Up @@ -504,11 +498,11 @@ RationalTime::to_timecode(
}
else
{
if ((rate == 29.97) or (rate == 30000 / 1001.0))
if (rate == 30000 / 1001.0)
{
dropframes = 2;
}
else if (rate == 59.94)
else if (rate == 60000 / 1001.0)
{
dropframes = 4;
}
Expand Down

0 comments on commit 661a556

Please sign in to comment.