async def get_metadata(
    collection: SampleCollection,
    sample: t.Dict,
    media_type: str,
    metadata_cache: t.Dict[str, t.Dict[str, str]],
    url_cache: t.Dict[str, str],
):
    """Gets the metadata for the given local media file.

    Args:
        filepath: the path to the file
        media_type: the file's media type
        metadata (None): a pre-existing metadata dict to use if possible

    Returns:
        metadata dict
    """
    filepath = sample["filepath"]
    metadata = sample.get("metadata", None)

    (
        opm_field,
        detections_fields,
        additional_fields,
    ) = _get_additional_media_fields(collection)

    filepath_result, filepath_source, urls = _create_media_urls(
        collection,
        sample,
        media_type,
        url_cache,
        additional_fields=additional_fields,
        opm_field=opm_field,
        detections_fields=detections_fields,
    )
    if filepath_result is not None:
        filepath = filepath_result

    is_video = media_type == fom.VIDEO

    # If sufficient pre-existing metadata exists, use it
    if filepath not in metadata_cache and metadata:
        if is_video:
            width = metadata.get("frame_width", None)
            height = metadata.get("frame_height", None)
            frame_rate = metadata.get("frame_rate", None)

            if width and height and frame_rate:
                metadata_cache[filepath] = dict(
                    aspect_ratio=width / height,
                    frame_rate=frame_rate,
                )
        else:
            width = metadata.get("width", None)
            height = metadata.get("height", None)

            if width and height:
                metadata_cache[filepath] = dict(
                    aspect_ratio=width / height,
                )

    if filepath not in metadata_cache:
        try:
            # Retrieve media metadata from disk
            metadata_cache[filepath] = await read_metadata(
                filepath_source, is_video
            )
        except Exception as exc:
            # Immediately fail so the user knows they should install FFmpeg
            if isinstance(exc, FFmpegNotFoundException):
                raise exc

            # Something went wrong (ie non-existent file), so we gracefully
            # return some placeholder metadata so the App grid can be rendered
            if is_video:
                metadata_cache[filepath] = dict(aspect_ratio=1, frame_rate=30)
            else:
                metadata_cache[filepath] = dict(aspect_ratio=1)

    return dict(urls=urls, **metadata_cache[filepath])
Gets the metadata for the given local media file.

    Args:
        filepath: the path to the file
        media_type: the file's media type
        metadata (None): a pre-existing metadata dict to use if possible

    Returns:
        metadata dict
    
fiftyone/server/metadata.py