Coverage for  / opt / hostedtoolcache / Python / 3.12.13 / x64 / lib / python3.12 / site-packages / fcp7xml_to_unreal / models / helpers.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-17 22:47 +0000

1from fcp7xml_to_unreal import logger 

2 

3 

4def tc_to_frames(tc="00:59:50:00"): 

5 # tc is in the following format: 

6 # HH:MM:SS:FF 

7 

8 (hours, minutes, seconds, frames) = [int(c) for c in tc.split(":", 3)] 

9 

10 if (frames < 0) | (frames > 23): 

11 logger.error(f"Timecode error: illegal frame value in {tc}") 

12 return -1 

13 if (seconds < 0) | (seconds > 59): 

14 logger.error(f"Timecode error: illegal seconds value in {tc}") 

15 return -1 

16 if (minutes < 0) | (minutes > 59): 

17 logger.error(f"Timecode error: illegal minutes value in {tc}") 

18 return -1 

19 

20 return frames + 24 * seconds + 24 * 60 * minutes + 24 * 60 * 60 * hours 

21 

22 

23def frames_to_tc(frame, for_srt=False, additional_frames: int = 0): 

24 # Add 00:59:50:00 offset 

25 if frame is None: 

26 return "00:59:50:00" 

27 else: 

28 frame = int(frame) + additional_frames 

29 frame = frame + (59 * 60 * 24) + (50 * 24) 

30 h = int(frame / 86400) 

31 m = int(frame / 1440) % 60 

32 s = int((frame % 1440) / 24) 

33 f = frame % 1440 % 24 

34 if not for_srt: 

35 return f"{h:02d}:{m:02d}:{s:02d}:{f:02d}" 

36 else: 

37 ms = int(f / 24 * 1000) 

38 return f"{h:02d}:{m:02d}:{s:02d},{ms:03d}"