import re


def time_to_frame(line: str, fps=24000 / 1001) -> int:
    """
    Converts a timestamp in the format <hours>:<minutes>:<seconds>.<milliseconds> into the corresponding frame number.
    <hours> and <milliseconds> are optional,
    and milliseconds can have arbitrary precision (which means they are no longer milliseconds :thonking: ).
    A parameter for the framerate can be passed if required.
    Valid example inputs: '1:23.456', '01:10:00', '0:00:00.000', '24:30.2'
    """
    timestamp = re.match(r'(\d{1,2}:)?\d{1,2}:\d{1,2}(\.\d{1,3})', line)
    if not timestamp:
        return -1
    times = timestamp.group(0).split(':')
    if '.' in times[-1]:     # milliseconds are specified
        times[-1], ms = times[-1].split('.')
        frame = fps * (int(ms) / 10**len(ms))
    else:
        frame = 0
    for t in reversed(times):
        frame += (fps * int(t))
        fps *= 60
    return round(frame)