code: def _read_from_stream(
      container, start_pts, end_pts, stream, stream_name, buffer_size=4
  ):
      """
      Args:
          container: pyav container
          start_pts/end_pts: the starting/ending Presentation TimeStamp where
              frames are read
          stream: pyav stream
          stream_name: a dictionary of streams. For example, {"video": 0} means
              video stream at stream index 0
          buffer_size: pts of frames decoded by PyAv is not guaranteed to be in
              ascending order. We need to decode more frames even when we meet end
              pts
      """
      # seeking in the stream is imprecise. Thus, seek to an earlier PTS by a margin
      margin = 1
      seek_offset = max(start_pts - margin, 0)
  
      container.seek(
          seek_offset, any_frame=False, backward=True, stream=stream
      )
      frames = {}
      buffer_count = 0
      for frame in container.decode(**stream_name):
          if frame.pts < start_pts:
              continue
          if frame.pts <= end_pts:
              frames[frame.pts] = frame
          else:
              buffer_count += 1
              if buffer_count >= buffer_size:
                  break
      result = [frames[pts] for pts in sorted(frames)]
  
      return result
  
imports: import collections
  import math
  import os
  from fractions import Fraction
  import numpy
  import pytest
  import torch
  import torchvision.io
  from common_utils import assert_equal
  from numpy.random import randint
  from pytest import approx
  from torchvision import set_video_backend
  from torchvision.io import _HAS_VIDEO_OPT
label_desc: Use image node_id 1 for calling a global function with example usage: _read_from_stream(container, start_pts, end_pts, stream, stream_name, buffer_size) and returns: result