code: def _pyav_decode_stream(
      container: av.container.input.InputContainer,
      start_pts: int,
      end_pts: int,
      stream: av.video.stream.VideoStream,
      stream_name: dict,
      buffer_size: int = 0,
      perform_seek: bool = True,
  ) -> Tuple[List, float]:
      """
      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.
      Returns:
          result (list): list of decoded frames.
          max_pts (int): max Presentation TimeStamp of the video sequence.
      """
  
      # Seeking in the stream is imprecise. Thus, seek to an earlier pts by a
      # margin pts.
      margin = 1024
  
      # NOTE:
      # Don't want to seek if iterating through a video due to slow-downs. I
      # believe this is some PyAV bug where seeking after a certain point causes
      # major slow-downs
      if perform_seek:
          seek_offset = max(start_pts - margin, 0)
          container.seek(
              int(seek_offset),
              any_frame=False,
              backward=True,
              stream=stream,
          )
      frames = {}
      max_pts = 0
      for frame in container.decode(**stream_name):
          max_pts = max(max_pts, frame.pts)
          if frame.pts >= start_pts and frame.pts < end_pts:
              frames[frame.pts] = frame
          elif frame.pts >= end_pts:
              break
  
      result = [frames[pts] for pts in sorted(frames)]
      return result, max_pts
  
imports: import logging
  import math
  from fractions import Fraction
  from typing import BinaryIO, Dict, List, Optional, Tuple, Union
  import av
  import numpy
  import torch
  from pytorchvideo.data.encoded_video import EncodedVideo
  from .utils import pts_to_secs, secs_to_pts, thwc_to_cthw
label_desc: Use image node_id 1 for calling a global function with example usage: _pyav_decode_stream(container, start_pts, end_pts, stream, stream_name, buffer_size, perform_seek) and returns: result,  max_pts