(frame: number, fps: number)
| 1 | import { HeliosError, HeliosErrorCode } from './errors.js'; |
| 2 | |
| 3 | export function framesToTimecode(frame: number, fps: number): string { |
| 4 | if (fps <= 0) { |
| 5 | throw new HeliosError(HeliosErrorCode.INVALID_FPS, "FPS must be greater than 0"); |
| 6 | } |
| 7 | |
| 8 | // Ensure frame is non-negative and integer |
| 9 | const safeFrame = Math.max(0, Math.floor(frame)); |
| 10 | |
| 11 | const totalSeconds = Math.floor(safeFrame / fps); |
| 12 | const f = safeFrame % fps; |
| 13 | const s = totalSeconds % 60; |
| 14 | const m = Math.floor(totalSeconds / 60) % 60; |
| 15 | const h = Math.floor(totalSeconds / 3600); |
| 16 | |
| 17 | const pad = (n: number) => n.toString().padStart(2, '0'); |
| 18 | |
| 19 | return `${pad(h)}:${pad(m)}:${pad(s)}:${pad(f)}`; |
| 20 | } |
| 21 | |
| 22 | export function timecodeToFrames(timecode: string, fps: number): number { |
| 23 | if (fps <= 0) { |
no test coverage detected