code: def decode(
      container,
      sampling_rate,
      num_frames,
      clip_idx=-1,
      num_clips_uniform=10,
      video_meta=None,
      target_fps=30,
      backend="pyav",
      max_spatial_scale=0,
      use_offset=False,
      time_diff_prob=0.0,
      gaussian_prob=0.0,
      min_delta=-math.inf,
      max_delta=math.inf,
      temporally_rnd_clips=True,
  ):
      """
      Decode the video and perform temporal sampling.
      Args:
          container (container): pyav container.
          sampling_rate (list of ints): frame sampling rate (interval between two sampled
              frames).
          num_frames (list of ints): number of frames to sample.
          clip_idx (int): if clip_idx is -1, perform random temporal
              sampling. If clip_idx is larger than -1, uniformly split the
              video to num_clips_uniform clips, and select the
              clip_idx-th video clip.
          num_clips_uniform (int): overall number of clips to uniformly
              sample from the given video.
          video_meta (dict): a dict contains VideoMetaData. Details can be find
              at `pytorch/vision/torchvision/io/_video_opt.py`.
          target_fps (int): the input video may have different fps, convert it to
              the target video fps before frame sampling.
          backend (str): decoding backend includes `pyav` and `torchvision`. The
              default one is `pyav`.
          max_spatial_scale (int): keep the aspect ratio and resize the frame so
              that shorter edge size is max_spatial_scale. Only used in
              `torchvision` backend.
      Returns:
          frames (tensor): decoded frames from the video.
      """
      # Currently support two decoders: 1) PyAV, and 2) TorchVision.
      assert clip_idx >= -1, "Not valied clip_idx {}".format(clip_idx)
      assert len(sampling_rate) == len(num_frames)
      num_decode = len(num_frames)
      num_frames_orig = num_frames
      if num_decode > 1 and temporally_rnd_clips:
          ind_clips = np.random.permutation(num_decode)
          sampling_rate = [sampling_rate[i] for i in ind_clips]
          num_frames = [num_frames[i] for i in ind_clips]
      else:
          ind_clips = np.arange(
              num_decode
          )  # clips come temporally ordered from decoder
      try:
          if backend == "pyav":
              assert (
                  min_delta == -math.inf and max_delta == math.inf
              ), "delta sampling not supported in pyav"
              frames_decoded, fps, decode_all_video = pyav_decode(
                  container,
                  sampling_rate,
                  num_frames,
                  clip_idx,
                  num_clips_uniform,
                  target_fps,
                  use_offset=use_offset,
              )
          elif backend == "torchvision":
              (
                  frames_decoded,
                  fps,
                  decode_all_video,
                  start_end_delta_time,
              ) = torchvision_decode(
                  container,
                  sampling_rate,
                  num_frames,
                  clip_idx,
                  video_meta,
                  num_clips_uniform,
                  target_fps,
                  ("visual",),
                  max_spatial_scale,
                  use_offset=use_offset,
                  min_delta=min_delta,
                  max_delta=max_delta,
              )
          else:
              raise NotImplementedError(
                  "Unknown decoding backend {}".format(backend)
              )
      except Exception as e:
          print(
              "Failed to decode by {} with exception: {}".format(
                  backend, e
              )
          )
          return None, None, None
  
      # Return None if the frames was not decoded successfully.
      if frames_decoded is None or None in frames_decoded:
          return None, None, None
  
      if not isinstance(frames_decoded, list):
          frames_decoded = [frames_decoded]
      num_decoded = len(frames_decoded)
      clip_sizes = [
          np.maximum(
              1.0, sampling_rate[i] * num_frames[i] / target_fps * fps
          )
          for i in range(len(sampling_rate))
      ]
  
      if decode_all_video:  # full video was decoded (not trimmed yet)
          assert num_decoded == 1 and start_end_delta_time is None
          start_end_delta_time = get_multiple_start_end_idx(
              frames_decoded[0].shape[0],
              clip_sizes,
              clip_idx if decode_all_video else 0,
              num_clips_uniform if decode_all_video else 1,
              min_delta=min_delta,
              max_delta=max_delta,
              use_offset=use_offset,
          )
  
      frames_out, start_inds, time_diff_aug = (
          [None] * num_decode,
          [None] * num_decode,
          [None] * num_decode,
      )
      augment_vid = gaussian_prob > 0.0 or time_diff_prob > 0.0
      for k in range(num_decode):
          T = num_frames[k]
          # Perform temporal sampling from the decoded video.
  
          if decode_all_video:
              frames = frames_decoded[0]
              if augment_vid:
                  frames = frames.clone()
              start_idx, end_idx = (
                  start_end_delta_time[k, 0],
                  start_end_delta_time[k, 1],
              )
          else:
              frames = frames_decoded[k]
              # video is already trimmed so we just need subsampling
              start_idx, end_idx, clip_position = get_start_end_idx(
                  frames.shape[0], clip_sizes[k], 0, 1
              )
          if augment_vid:
              frames, time_diff_aug[k] = transform.augment_raw_frames(
                  frames, time_diff_prob, gaussian_prob
              )
          frames_k = temporal_sampling(frames, start_idx, end_idx, T)
          frames_out[k] = frames_k
  
      # if we shuffle, need to randomize the output, otherwise it will always be past->future
      if num_decode > 1 and temporally_rnd_clips:
          frames_out_, time_diff_aug_ = [None] * num_decode, [
              None
          ] * num_decode
          start_end_delta_time_ = np.zeros_like(start_end_delta_time)
          for i, j in enumerate(ind_clips):
              frames_out_[j] = frames_out[i]
              start_end_delta_time_[j, :] = start_end_delta_time[i, :]
              time_diff_aug_[j] = time_diff_aug[i]
  
          frames_out = frames_out_
          start_end_delta_time = start_end_delta_time_
          time_diff_aug = time_diff_aug_
          assert all(
              frames_out[i].shape[0] == num_frames_orig[i]
              for i in range(num_decode)
          )
  
      return frames_out, start_end_delta_time, time_diff_aug
  
file_path: SlowFast/slowfast/datasets/decoder.py
imports: import logging
  import math
  import numpy
  import random
  import torch
  import torchvision.io
  from .None import transform
label_desc: Use image node_id 7 for calling a global function with example usage: decode(container, sampling_rate, num_frames, clip_idx, num_clips_uniform, video_meta, target_fps, backend, max_spatial_scale, use_offset, time_diff_prob, gaussian_prob, min_delta, max_delta, temporally_rnd_clips) and returns: frames_out,  start_end_delta_time,  time_diff_aug, None,  None,  None, None,  None,  None