| 1234567891011121314151617181920212223242526272829 |
- /**
- * Smart timecode formatter.
- * Shows HH only if total duration >= 1 hour.
- * Shows MM only if total duration >= 1 minute.
- * Otherwise: SS:FF
- */
- export function formatTimecode(s: number, fps: number = 30, totalDuration?: number): string {
- if (!s || isNaN(s)) return '00:00:00:00';
- const h = Math.floor(s / 3600);
- const m = Math.floor((s % 3600) / 60);
- const sec = Math.floor(s % 60);
- const f = Math.round(s * fps) % fps;
- // Determine minimum display based on total duration
- const total = totalDuration ?? s;
- const totalH = Math.floor(total / 3600);
- const totalM = Math.floor((total % 3600) / 60);
- if (totalH > 0) {
- // Video is 1h+: show HH:MM:SS:FF
- return `${String(h).padStart(2,'0')}:${String(m).padStart(2,'0')}:${String(sec).padStart(2,'0')}:${String(f).padStart(2,'0')}`;
- }
- if (totalM > 0) {
- // Video is 1m+: show MM:SS:FF
- return `${String(m).padStart(2,'0')}:${String(sec).padStart(2,'0')}:${String(f).padStart(2,'0')}`;
- }
- // Under 1m: show SS:FF
- return `${String(sec).padStart(2,'0')}:${String(f).padStart(2,'0')}`;
- }
|