code: def pyav_decode_stream(
      container, start_pts, end_pts, stream, stream_name, buffer_size=0
  ):
      """
      Decode the video with PyAV decoder.
      Args:
          container (container): PyAV container.
          start_pts (int): the starting Presentation TimeStamp to fetch the
              video frames.
          end_pts (int): the ending Presentation TimeStamp of the decoded frames.
          stream (stream): PyAV stream.
          stream_name (dict): a dictionary of streams. For example, {"video": 0}
              means video stream at stream index 0.
          buffer_size (int): number of additional frames to decode beyond end_pts.
      Returns:
          result (list): list of frames decoded.
          max_pts (int): max Presentation TimeStamp of the video sequence.
      """
      # Seeking in the stream is imprecise. Thus, seek to an ealier PTS by a
      # margin pts.
      margin = 1024
      seek_offset = max(start_pts - margin, 0)
  
      container.seek(
          seek_offset, any_frame=False, backward=True, stream=stream
      )
      frames = {}
      buffer_count = 0
      max_pts = 0
      for frame in container.decode(**stream_name):
          max_pts = max(max_pts, frame.pts)
          if frame.pts < start_pts:
              continue
          if frame.pts <= end_pts:
              frames[frame.pts] = frame
          else:
              buffer_count += 1
              frames[frame.pts] = frame
              if buffer_count >= buffer_size:
                  break
      result = [frames[pts] for pts in sorted(frames)]
      return result, max_pts
  
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 4 for calling a global function with example usage: pyav_decode_stream(container, start_pts, end_pts, stream, stream_name, buffer_size) and returns: result,  max_pts