Parse a SMPTE ``HH:MM:SS:FF`` (or 8-digit ``HHMMSSFF``) start timecode into a frame count.
(value: str, frame_rate: Fraction | float)
| 255 | |
| 256 | |
| 257 | def _parse_edl_start_timecode(value: str, frame_rate: Fraction | float) -> int: |
| 258 | """Parse a SMPTE ``HH:MM:SS:FF`` (or 8-digit ``HHMMSSFF``) start timecode into a frame count.""" |
| 259 | stripped = value.strip() |
| 260 | if ":" in stripped: |
| 261 | parts = stripped.split(":") |
| 262 | elif stripped.isdigit() and len(stripped) == 8: |
| 263 | parts = [stripped[0:2], stripped[2:4], stripped[4:6], stripped[6:8]] |
| 264 | else: |
| 265 | raise ValueError( |
| 266 | f"Invalid start timecode {value!r}: expected HH:MM:SS:FF or 8 digits (HHMMSSFF)." |
| 267 | ) |
| 268 | if len(parts) != 4 or not all(p.isdigit() for p in parts): |
| 269 | raise ValueError( |
| 270 | f"Invalid start timecode {value!r}: expected HH:MM:SS:FF or 8 digits (HHMMSSFF)." |
| 271 | ) |
| 272 | hours, minutes, seconds, frames = (int(p) for p in parts) |
| 273 | max_frames = math.ceil(float(frame_rate)) |
| 274 | if minutes >= 60 or seconds >= 60 or frames >= max_frames: |
| 275 | raise ValueError( |
| 276 | f"Invalid start timecode {value!r}: MM<60, SS<60, FF<{max_frames} required." |
| 277 | ) |
| 278 | return round((hours * 3600 + minutes * 60 + seconds) * float(frame_rate)) + frames |
| 279 | |
| 280 | |
| 281 | def write_scene_list_edl( |
no outgoing calls
no test coverage detected