class_docstr: Class for video byte-level reading with ffmpeg.
class_docstr_tok: ["Class","for","video","byte-level","reading","with","ffmpeg","."]
docstr: Reads the next frame from the file.
  Note that upon (re)initialization, the first frame will already have been read
  and stored in ``self.lastread``.
docstr_tok: ["Reads","the","next","frame","from","the","file",".","Note","that","upon","(","re",")","initialization",",","the","first","frame","will","already","have","been","read","and","stored","in","``","self.lastread","``","."]
code: def read_frame(self):
      """
      Reads the next frame from the file.
      Note that upon (re)initialization, the first frame will already have been read
      and stored in ``self.lastread``.
      """
      w, h = self.size
      nbytes = self.depth * w * h
  
      s = self.proc.stdout.read(nbytes)
  
      if len(s) != nbytes:
          warnings.warn(
              (
                  "In file %s, %d bytes wanted but %d bytes read at frame index"
                  " %d (out of a total %d frames), at time %.02f/%.02f sec."
                  " Using the last valid frame instead."
              )
              % (
                  self.filename,
                  nbytes,
                  len(s),
                  self.pos,
                  self.n_frames,
                  1.0 * self.pos / self.fps,
                  self.duration,
              ),
              UserWarning,
          )
          if not hasattr(self, "last_read"):
              raise IOError(
                  (
                      "MoviePy error: failed to read the first frame of "
                      f"video file {self.filename}. That might mean that the file is "
                      "corrupted. That may also mean that you are using "
                      "a deprecated version of FFMPEG. On Ubuntu/Debian "
                      "for instance the version in the repos is deprecated. "
                      "Please update to a recent version from the website."
                  )
              )
  
          result = self.last_read
  
      else:
          if hasattr(np, "frombuffer"):
              result = np.frombuffer(s, dtype="uint8")
          else:
              result = np.fromstring(s, dtype="uint8")
          result.shape = (
              h,
              w,
              len(s) // (w * h),
          )  # reshape((h, w, len(s)//(w*h)))
          self.last_read = result
  
      # We have to do this down here because `self.pos` is used in the warning above
      self.pos += 1
  
      return result
  
imports: import os
  import re
  import subprocess
  import warnings
  import numpy
  from moviepy.config import FFMPEG_BINARY
  from moviepy.tools import convert_to_seconds, cross_platform_popen_params
label_desc: Use image node_id 4 for calling the FFMPEG_VideoReader obj's underlying member method code with example usage: obj.read_frame() and returns: result