def transform_time(tim):
    """Transform from hh:mm:ss:fn or pts to hh:mm:ss:ms."""
    try:
        parts = tim.split(":")
        frame_nr = int(parts[-1])
        milis = min(int(frame_nr*1000/29.97), 999)
        newtime = "%s.%03d" % (":".join(parts[:-1]), milis)
    except AttributeError: # pts time
        seconds = tim//90000
        milis = int((tim % 90000)/90.0)
        hours = seconds//3600
        minutes = seconds//60
        seconds -= hours*3600 + minutes*60
        newtime = "%02d:%02d:%02d.%03d" % (hours, minutes, seconds, milis)
    return newtime