def reencode_images(
    sample_collection,
    ext=".png",
    force_reencode=True,
    media_field="filepath",
    output_field=None,
    output_dir=None,
    rel_dir=None,
    update_filepaths=True,
    delete_originals=False,
    num_workers=None,
    skip_failures=False,
    progress=None,
):
    """Re-encodes the images in the sample collection to the given format.

    If no ``output_dir`` is specified and ``delete_originals`` is False, then
    if a transformation would result in overwriting an existing file with the
    same filename, the original file is renamed to ``<name>-original.<ext>``.

    .. note::

        This method will not update the ``metadata`` field of the collection
        after transforming. You can repopulate the ``metadata`` field if needed
        by calling::

            sample_collection.compute_metadata(overwrite=True)

    Args:
        sample_collection: a
            :class:`fiftyone.core.collections.SampleCollection`
        ext (".png"): the image format to use (e.g., ".png" or ".jpg")
        force_reencode (True): whether to re-encode images whose extension
            already matches ``ext``
        media_field ("filepath"): the input field containing the image paths to
            transform
        output_field (None): an optional field in which to store the paths to
            the transformed images. By default, ``media_field`` is updated
            in-place
        output_dir (None): an optional output directory in which to write the
            transformed images. If none is provided, the images are updated
            in-place
        rel_dir (None): an optional relative directory to strip from each input
            filepath to generate a unique identifier that is joined with
            ``output_dir`` to generate an output path for each image. This
            argument allows for populating nested subdirectories in
            ``output_dir`` that match the shape of the input paths
        update_filepaths (True): whether to store the output paths on the
            sample collection
        delete_originals (False): whether to delete the original images after
            re-encoding
        num_workers (None): a suggested number of worker processes to use
        skip_failures (False): whether to gracefully continue without raising
            an error if an image cannot be re-encoded
        progress (None): whether to render a progress bar (True/False), use the
            default value ``fiftyone.config.show_progress_bars`` (None), or a
            progress callback function to invoke instead
    """
    fov.validate_image_collection(sample_collection)

    _transform_images(
        sample_collection,
        ext=ext,
        force_reencode=force_reencode,
        media_field=media_field,
        output_field=output_field,
        output_dir=output_dir,
        rel_dir=rel_dir,
        update_filepaths=update_filepaths,
        delete_originals=delete_originals,
        num_workers=num_workers,
        skip_failures=skip_failures,
        progress=progress,
    )
Re-encodes the images in the sample collection to the given format.

    If no ``output_dir`` is specified and ``delete_originals`` is False, then
    if a transformation would result in overwriting an existing file with the
    same filename, the original file is renamed to ``<name>-original.<ext>``.

    .. note::

        This method will not update the ``metadata`` field of the collection
        after transforming. You can repopulate the ``metadata`` field if needed
        by calling::

            sample_collection.compute_metadata(overwrite=True)

    Args:
        sample_collection: a
            :class:`fiftyone.core.collections.SampleCollection`
        ext (".png"): the image format to use (e.g., ".png" or ".jpg")
        force_reencode (True): whether to re-encode images whose extension
            already matches ``ext``
        media_field ("filepath"): the input field containing the image paths to
            transform
        output_field (None): an optional field in which to store the paths to
            the transformed images. By default, ``media_field`` is updated
            in-place
        output_dir (None): an optional output directory in which to write the
            transformed images. If none is provided, the images are updated
            in-place
        rel_dir (None): an optional relative directory to strip from each input
            filepath to generate a unique identifier that is joined with
            ``output_dir`` to generate an output path for each image. This
            argument allows for populating nested subdirectories in
            ``output_dir`` that match the shape of the input paths
        update_filepaths (True): whether to store the output paths on the
            sample collection
        delete_originals (False): whether to delete the original images after
            re-encoding
        num_workers (None): a suggested number of worker processes to use
        skip_failures (False): whether to gracefully continue without raising
            an error if an image cannot be re-encoded
        progress (None): whether to render a progress bar (True/False), use the
            default value ``fiftyone.config.show_progress_bars`` (None), or a
            progress callback function to invoke instead
    
fiftyone/utils/image.py