Skip to content

Commit a0f8404

Browse files
committed
Deal with "close" timecode rates via a heuristic, instead of misleading entries in valid_timecode_rates table.
Signed-off-by: Joshua Minor <[email protected]>
1 parent b6fbca2 commit a0f8404

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

src/opentime/rationalTime.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@ namespace opentime { namespace OPENTIME_VERSION {
1313

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

16-
static constexpr std::array<double, 4> dropframe_timecode_rates{ {
17-
// 23.976,
18-
// 23.98,
19-
// 23.97,
20-
// 24000.0/1001.0,
21-
29.97,
16+
static constexpr std::array<double, 2> dropframe_timecode_rates{ {
2217
30000.0 / 1001.0,
23-
59.94,
2418
60000.0 / 1001.0,
2519
} };
2620

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

41-
static constexpr std::array<double, 16> valid_timecode_rates{
35+
static constexpr std::array<double, 12> valid_timecode_rates{
4236
{ 1.0,
4337
12.0,
44-
23.97,
45-
23.976,
46-
23.98,
4738
24000.0 / 1001.0,
4839
24.0,
4940
25.0,
@@ -52,7 +43,6 @@ static constexpr std::array<double, 16> valid_timecode_rates{
5243
30.0,
5344
48.0,
5445
50.0,
55-
59.94,
5646
60000.0 / 1001.0,
5747
60.0 }
5848
};
@@ -460,7 +450,8 @@ RationalTime::to_timecode(
460450
return std::string();
461451
}
462452

463-
if (!is_valid_timecode_rate(rate))
453+
double nearest_valid_rate = nearest_valid_timecode_rate(rate);
454+
if (abs(nearest_valid_rate - rate) > 0.1)
464455
{
465456
if (error_status)
466457
{
@@ -469,6 +460,9 @@ RationalTime::to_timecode(
469460
return std::string();
470461
}
471462

463+
// Let's assume this is the rate instead of the given rate.
464+
rate = nearest_valid_rate;
465+
472466
bool rate_is_dropframe = is_dropframe_rate(rate);
473467
if (drop_frame == IsDropFrameRate::ForceYes and not rate_is_dropframe)
474468
{
@@ -504,11 +498,11 @@ RationalTime::to_timecode(
504498
}
505499
else
506500
{
507-
if ((rate == 29.97) or (rate == 30000 / 1001.0))
501+
if (rate == 30000 / 1001.0)
508502
{
509503
dropframes = 2;
510504
}
511-
else if (rate == 59.94)
505+
else if (rate == 60000 / 1001.0)
512506
{
513507
dropframes = 4;
514508
}

0 commit comments

Comments
 (0)