mirror of
https://github.com/iluvcapra/ptulsconv.git
synced 2025-12-31 08:50:48 +00:00
More typing, removed dead code in tc convert
This commit is contained in:
@@ -3,8 +3,7 @@ import re
|
|||||||
import math
|
import math
|
||||||
|
|
||||||
|
|
||||||
def smpte_to_frame_count(smpte_rep_string: str, frames_per_logical_second: int, drop_frame_hint=False,
|
def smpte_to_frame_count(smpte_rep_string: str, frames_per_logical_second: int, drop_frame_hint=False) -> int:
|
||||||
include_fractional=False) -> object:
|
|
||||||
"""
|
"""
|
||||||
Convert a string with a SMPTE timecode representation into a frame count.
|
Convert a string with a SMPTE timecode representation into a frame count.
|
||||||
|
|
||||||
@@ -40,10 +39,10 @@ def smpte_to_frame_count(smpte_rep_string: str, frames_per_logical_second: int,
|
|||||||
dropped_frames = frames_dropped_per_inst * inst_count
|
dropped_frames = frames_dropped_per_inst * inst_count
|
||||||
frames = raw_frames - dropped_frames
|
frames = raw_frames - dropped_frames
|
||||||
|
|
||||||
if include_fractional:
|
# if include_fractional:
|
||||||
return frames, frac
|
# return frames, frac
|
||||||
else:
|
# else:
|
||||||
return frames
|
return frames
|
||||||
|
|
||||||
|
|
||||||
def frame_count_to_smpte(frame_count: int, frames_per_logical_second: int, drop_frame: bool = False,
|
def frame_count_to_smpte(frame_count: int, frames_per_logical_second: int, drop_frame: bool = False,
|
||||||
|
|||||||
@@ -4,6 +4,13 @@ from typing import Tuple, List
|
|||||||
|
|
||||||
|
|
||||||
class SessionDescriptor:
|
class SessionDescriptor:
|
||||||
|
header: "HeaderDescriptor"
|
||||||
|
files: List["FileDescriptor"]
|
||||||
|
clips: List["ClipDescriptor"]
|
||||||
|
plugins: List["PluginDescriptor"]
|
||||||
|
tracks: List["TrackDescriptor"]
|
||||||
|
markers: List["MarkerDescriptor"]
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.header = kwargs['header']
|
self.header = kwargs['header']
|
||||||
self.files = kwargs['files']
|
self.files = kwargs['files']
|
||||||
@@ -38,8 +45,7 @@ class HeaderDescriptor:
|
|||||||
def convert_timecode(self, tc_string) -> Fraction:
|
def convert_timecode(self, tc_string) -> Fraction:
|
||||||
frame_count = smpte_to_frame_count(tc_string,
|
frame_count = smpte_to_frame_count(tc_string,
|
||||||
self.logical_fps,
|
self.logical_fps,
|
||||||
self.timecode_drop_frame,
|
self.timecode_drop_frame)
|
||||||
include_fractional=False)
|
|
||||||
|
|
||||||
return self.frame_duration * frame_count
|
return self.frame_duration * frame_count
|
||||||
|
|
||||||
@@ -53,20 +59,20 @@ class HeaderDescriptor:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def logical_fps(self) -> int:
|
def logical_fps(self) -> int:
|
||||||
return self._get_tcformat_params[0]
|
return self._get_tc_format_params[0]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def frame_duration(self) -> Fraction:
|
def frame_duration(self) -> Fraction:
|
||||||
return self._get_tcformat_params[1]
|
return self._get_tc_format_params[1]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _get_tcformat_params(self) -> Tuple[int, Fraction]:
|
def _get_tc_format_params(self) -> Tuple[int, Fraction]:
|
||||||
frame_rates = {"23.976": (24, Fraction(1001, 24_000)),
|
frame_rates = {"23.976": (24, Fraction(1001, 24_000)),
|
||||||
"24": (24, Fraction(1, 24)),
|
"24": (24, Fraction(1, 24)),
|
||||||
"29.97": (30, Fraction(1001, 30_000)),
|
"29.97": (30, Fraction(1001, 30_000)),
|
||||||
"30": (30, Fraction(1, 30)),
|
"30": (30, Fraction(1, 30)),
|
||||||
"59.94": (60, Fraction(1001, 60_000)),
|
"59.94": (60, Fraction(1001, 60_000)),
|
||||||
"60": (60, Fraction(1, 60))
|
"60": (60, Fraction(1, 60))
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.timecode_format in frame_rates.keys():
|
if self.timecode_format in frame_rates.keys():
|
||||||
|
|||||||
@@ -32,12 +32,6 @@ class TestBroadcastTimecode(unittest.TestCase):
|
|||||||
s1 = broadcast_timecode.frame_count_to_smpte(c1, 30, drop_frame=True)
|
s1 = broadcast_timecode.frame_count_to_smpte(c1, 30, drop_frame=True)
|
||||||
self.assertEqual(s1, "01:00:03;18")
|
self.assertEqual(s1, "01:00:03;18")
|
||||||
|
|
||||||
def test_fractional_to_framecount(self):
|
|
||||||
s1 = "00:00:01:04.105"
|
|
||||||
c1, f1 = broadcast_timecode.smpte_to_frame_count(s1, 24, drop_frame_hint=False, include_fractional=True)
|
|
||||||
self.assertEqual(c1, 28)
|
|
||||||
self.assertEqual(f1, 0.105)
|
|
||||||
|
|
||||||
def test_fractional_to_string(self):
|
def test_fractional_to_string(self):
|
||||||
c1 = 99
|
c1 = 99
|
||||||
f1 = .145
|
f1 = .145
|
||||||
@@ -66,10 +60,6 @@ class TestBroadcastTimecode(unittest.TestCase):
|
|||||||
f1 = broadcast_timecode.footage_to_frame_count(s1)
|
f1 = broadcast_timecode.footage_to_frame_count(s1)
|
||||||
self.assertEqual(f1, 3115)
|
self.assertEqual(f1, 3115)
|
||||||
|
|
||||||
s2 = "1+1.014"
|
|
||||||
f2 = broadcast_timecode.footage_to_frame_count(s2, include_fractional=True)
|
|
||||||
self.assertEqual(f2, (17, 0.014))
|
|
||||||
|
|
||||||
s3 = "0+0.1"
|
s3 = "0+0.1"
|
||||||
f3 = broadcast_timecode.footage_to_frame_count(s3, include_fractional=False)
|
f3 = broadcast_timecode.footage_to_frame_count(s3, include_fractional=False)
|
||||||
self.assertEqual(f3, 0)
|
self.assertEqual(f3, 0)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class DocParserTestCase(unittest.TestCase):
|
|||||||
count_files=0)
|
count_files=0)
|
||||||
|
|
||||||
self.assertEqual(header.session_name, "Test Session")
|
self.assertEqual(header.session_name, "Test Session")
|
||||||
self.assertEqual(header.convert_timecode(header.start_timecode), Fraction((59 * 60 + 52) * 30, 30))
|
self.assertEqual(header.start_time, Fraction((59 * 60 + 52) * 30, 30))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user