def video_info(file: Union[File, VideoFile]) -> Video:
    """
    Returns video file information.

    Args:
        file (VideoFile): Video file object.

    Returns:
        Video: Video file information.
    """
    file = file.as_video_file()

    if not (file_path := file.get_local_path()):
        file.ensure_cached()
        file_path = file.get_local_path()
        if not file_path:
            raise FileError("unable to download video file", file.source, file.path)

    try:
        probe = ffmpeg.probe(file_path)
    except Exception as exc:
        raise FileError(
            "unable to extract metadata from video file", file.source, file.path
        ) from exc

    all_streams = probe.get("streams")
    video_format = probe.get("format")
    if not all_streams or not video_format:
        raise FileError(
            "unable to extract metadata from video file", file.source, file.path
        )

    video_streams = [s for s in all_streams if s["codec_type"] == "video"]
    if len(video_streams) == 0:
        raise FileError(
            "unable to extract metadata from video file", file.source, file.path
        )

    video_stream = video_streams[0]

    r_frame_rate = video_stream.get("r_frame_rate", "0")
    if "/" in r_frame_rate:
        num, denom = r_frame_rate.split("/")
        fps = float(num) / float(denom)
    else:
        fps = float(r_frame_rate)

    width = int(video_stream.get("width", 0))
    height = int(video_stream.get("height", 0))
    duration = float(video_format.get("duration", 0))
    if "nb_frames" in video_stream:
        frames = int(video_stream.get("nb_frames", 0))
    else:
        start_time = float(video_format.get("start_time", 0))
        frames = int((duration - start_time) * fps)
    format_name = video_format.get("format_name", "")
    codec_name = video_stream.get("codec_name", "")

    return Video(
        width=width,
        height=height,
        fps=fps,
        duration=duration,
        frames=frames,
        format=format_name,
        codec=codec_name,
    )

    Returns video file information.

    Args:
        file (VideoFile): Video file object.

    Returns:
        Video: Video file information.
    
src/datachain/lib/video.py