code: def sample_videos(
      sample_collection,
      frames_patt=None,
      frames=None,
      fps=None,
      max_fps=None,
      size=None,
      min_size=None,
      max_size=None,
      original_frame_numbers=True,
      force_sample=False,
      media_field="filepath",
      output_field=None,
      output_dir=None,
      rel_dir=None,
      save_filepaths=False,
      delete_originals=False,
      skip_failures=False,
      verbose=False,
      **kwargs,
  ):
      """Samples the videos in the sample collection into directories of
      per-frame images according to the provided parameters using ``ffmpeg``.
  
      By default, each folder of images is written using the same basename as the
      input video. For example, if ``frames_patt = "%%06d.jpg"``, then videos
      with the following paths::
  
          /path/to/video1.mp4
          /path/to/video2.mp4
          ...
  
      would be sampled as follows::
  
          /path/to/video1/
              000001.jpg
              000002.jpg
              ...
          /path/to/video2/
              000001.jpg
              000002.jpg
              ...
  
      However, you can use the optional ``output_dir`` and ``rel_dir`` parameters
      to customize the location and shape of the sampled frame folders. For
      example, if ``output_dir = "/tmp"`` and ``rel_dir = "/path/to"``, then
      videos with the following paths::
  
          /path/to/folderA/video1.mp4
          /path/to/folderA/video2.mp4
          /path/to/folderB/video3.mp4
          ...
  
      would be sampled as follows::
  
          /tmp/folderA/
              video1/
                  000001.jpg
                  000002.jpg
                  ...
              video2/
                  000001.jpg
                  000002.jpg
                  ...
          /tmp/folderB/
              video3/
                  000001.jpg
                  000002.jpg
                  ...
  
      Args:
          sample_collection: a
              :class:`fiftyone.core.collections.SampleCollection`
          frames_patt (None): a pattern specifying the filename/format to use to
              store the sampled frames, e.g., ``"%%06d.jpg"``. The default value
              is ``fiftyone.config.default_sequence_idx + fiftyone.config.default_image_ext``
          frames (None): an optional list of lists defining specific frames to
              sample from each video. Entries can also be None, in which case all
              frames will be sampled. If provided, ``fps`` and ``max_fps`` are
              ignored
          fps (None): an optional frame rate at which to sample frames
          max_fps (None): an optional maximum frame rate. Videos with frame rate
              exceeding this value are downsampled
          size (None): an optional ``(width, height)`` for each frame. One
              dimension can be -1, in which case the aspect ratio is preserved
          min_size (None): an optional minimum ``(width, height)`` for each
              frame. A dimension can be -1 if no constraint should be applied.
              The frames are resized (aspect-preserving) if necessary to meet
              this constraint
          max_size (None): an optional maximum ``(width, height)`` for each
              frame. A dimension can be -1 if no constraint should be applied.
              The frames are resized (aspect-preserving) if necessary to meet
              this constraint
          original_frame_numbers (True): whether to use the original frame
              numbers when writing the output frames (True) or to instead reindex
              the frames as 1, 2, ... (False)
          force_sample (False): whether to resample videos whose sampled frames
              already exist
          media_field ("filepath"): the input field containing the video paths to
              sample
          output_field (None): an optional frame field in which to store the
              paths to the sampled frames. By default, ``media_field`` is used
          output_dir (None): an optional output directory in which to write the
              sampled frames. By default, the frames are written in folders with
              the same basename of each video
          rel_dir (None): a relative directory to remove from the filepath of
              each video, if possible. The path is converted to an absolute path
              (if necessary) via :func:`fiftyone.core.storage.normalize_path`.
              This argument can be used in conjunction with ``output_dir`` to
              cause the sampled frames to be written in a nested directory
              structure within ``output_dir`` matching the shape of the input
              video's folder structure
          save_filepaths (False): whether to save the sampled frame paths in the
              ``output_field`` field of each frame of the input collection
          delete_originals (False): whether to delete the original videos after
              sampling
          skip_failures (False): whether to gracefully continue without raising
              an error if a video cannot be sampled
          verbose (False): whether to log the ``ffmpeg`` commands that are
              executed
          **kwargs: keyword arguments for ``eta.core.video.FFmpeg(**kwargs)``
      """
      fov.validate_video_collection(sample_collection)
  
      _transform_videos(
          sample_collection,
          frames=frames,
          fps=fps,
          max_fps=max_fps,
          size=size,
          min_size=min_size,
          max_size=max_size,
          sample_frames=True,
          original_frame_numbers=original_frame_numbers,
          frames_patt=frames_patt,
          force_reencode=force_sample,
          media_field=media_field,
          output_field=output_field,
          output_dir=output_dir,
          rel_dir=rel_dir,
          save_filepaths=save_filepaths,
          delete_originals=delete_originals,
          skip_failures=skip_failures,
          verbose=verbose,
          **kwargs,
      )
  
imports: import itertools
  import json
  import logging
  import os
  import eta.core.frameutils
  import eta.core.image
  import eta.core.numutils
  import eta.core.utils
  import eta.core.video
  import fiftyone
  import fiftyone.core.metadata
  import fiftyone.core.storage
  import fiftyone.core.utils
  import fiftyone.core.validation
label_desc: Use image node_id 4 for calling a global function with example usage: sample_videos(sample_collection, frames_patt, frames, fps, max_fps, size, min_size, max_size, original_frame_numbers, force_sample, media_field, output_field, output_dir, rel_dir, save_filepaths, delete_originals, skip_failures, verbose) without return types