Skip to content

Commit 1d454b6

Browse files
committed
Add handling for higher frame rate timecode output
1 parent 4d4704e commit 1d454b6

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

src/opentime/rationalTime.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static constexpr std::array<double, 2> dropframe_timecode_rates{ {
2222
// ST 12-1:2014 - SMPTE Standard - Time and Control Code
2323
// https://ieeexplore.ieee.org/document/7291029
2424
//
25-
static constexpr std::array<double, 11> smpte_timecode_rates{
25+
static constexpr std::array<double, 22> smpte_timecode_rates{
2626
{ 24000.0 / 1001.0,
2727
24.0,
2828
25.0,
@@ -32,19 +32,19 @@ static constexpr std::array<double, 11> smpte_timecode_rates{
3232
48.0,
3333
50.0,
3434
60000.0 / 1001.0,
35-
60.0
36-
72.0
35+
60.0,
3736
72000.0 / 1001.0,
38-
96.0
37+
72.0,
3938
96000.0 / 1001.0,
40-
120.0
39+
96.0,
4140
120000.0 / 1001.0,
42-
144.0
41+
120.0,
4342
144000.0 / 1001.0,
44-
192.0
43+
144.0,
4544
192000.0 / 1001.0,
46-
240.0
45+
192.0,
4746
240000.0 / 1001.0,
47+
240.0
4848
}
4949
};
5050

@@ -470,7 +470,7 @@ RationalTime::to_timecode(
470470
// so as a convenience we will snap the rate to the nearest
471471
// SMPTE rate if it is close enough.
472472
double nearest_smpte_rate = nearest_smpte_timecode_rate(rate);
473-
double error_margin = nearest_smpte_rate * 0.002
473+
double error_margin = nearest_smpte_rate * 0.002;
474474
if (abs(nearest_smpte_rate - rate) > error_margin)
475475
{
476476
if (error_status)
@@ -575,8 +575,11 @@ RationalTime::to_timecode(
575575
int hours =
576576
static_cast<int>(std::floor(std::floor(seconds_total / 60) / 60));
577577

578+
std::string frames_digits = (nominal_fps < 100) ? "2" : "3";
579+
std::string timecode_format_string = "%02d:%02d:%02d%c%0"+frames_digits+"d";
580+
578581
return string_printf(
579-
"%02d:%02d:%02d%c%02d",
582+
timecode_format_string.c_str(),
580583
hours,
581584
minutes,
582585
seconds,

tests/test_opentime.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,23 @@ def test_timecode_2997(self):
401401
t2 = otio.opentime.from_timecode(to_tc, rate=ntsc_2997)
402402
self.assertEqual(t2, t)
403403

404+
def test_to_timecode_120(self):
405+
timecode = "00:00:00:000"
406+
t = otio.opentime.RationalTime(value=0, rate=120)
407+
self.assertEqual(timecode, otio.opentime.to_timecode(t, rate=120))
408+
409+
timecode = "00:00:00:010"
410+
t = otio.opentime.RationalTime(value=10, rate=120)
411+
self.assertEqual(timecode, otio.opentime.to_timecode(t, rate=120))
412+
413+
timecode = "00:00:00:119"
414+
t = otio.opentime.RationalTime(value=119, rate=120)
415+
self.assertEqual(timecode, otio.opentime.to_timecode(t, rate=120))
416+
417+
timecode = "00:00:01:000"
418+
t = otio.opentime.RationalTime(value=120, rate=120)
419+
self.assertEqual(timecode, otio.opentime.to_timecode(t, rate=120))
420+
404421
def test_faulty_formatted_timecode_24(self):
405422
"""
406423
01:00:13;23 is drop-frame timecode, which only applies for

0 commit comments

Comments
 (0)