code: def test_read_and_write(test_images, tmp_path):
      fname1 = test_images / "cockatoo.mp4"
  
      R = iio.read(fname1, "ffmpeg")
      assert isinstance(R, imageio.plugins.ffmpeg.FfmpegFormat.Reader)
  
      fname2 = tmp_path / "cockatoo.out.mp4"
  
      frame1, frame2, frame3 = 41, 131, 227
  
      # Read
      ims1 = []
      with iio.read(fname1, "ffmpeg") as R:
          for i in range(10):
              im = R.get_next_data()
              ims1.append(im)
              assert im.shape == (720, 1280, 3)
              assert (im.sum() / im.size) > 0  # pypy mean is broken
          assert im.sum() > 0
  
          # Seek to reference frames in steps. OUR code will skip steps
          im11 = R.get_data(frame1)
          im12 = R.get_data(frame2)
          im13 = R.get_data(frame3)
  
          # Now go backwards, seek will kick in
          R.get_next_data()
          im23 = R.get_data(frame3)
          im22 = R.get_data(frame2)
          im21 = R.get_data(frame1)
  
          # Also use set_image_index
          R.set_image_index(frame2)
          im32 = R.get_next_data()
          R.set_image_index(frame3)
          im33 = R.get_next_data()
          R.set_image_index(frame1)
          im31 = R.get_next_data()
  
          for im in (
              im11,
              im12,
              im13,
              im21,
              im22,
              im23,
              im31,
              im32,
              im33,
          ):
              assert im.shape == (720, 1280, 3)
  
          assert (im11 == im21).all() and (im11 == im31).all()
          assert (im12 == im22).all() and (im12 == im32).all()
          assert (im13 == im23).all() and (im13 == im33).all()
  
          assert not (im11 == im12).all()
          assert not (im11 == im13).all()
  
      # Save
      with iio.save(fname2, "ffmpeg") as W:
          for im in ims1:
              W.append_data(im)
  
      # Read the result
      ims2 = iio.mimread(fname2, "ffmpeg")
      assert len(ims1) == len(ims2)
      for im in ims2:
          assert im.shape == (720, 1280, 3)
  
      # Check
      for im1, im2 in zip(ims1, ims2):
          diff = np.abs(im1.astype(np.float32) - im2.astype(np.float32))
          if IS_PYPY:
              assert (diff.sum() / diff.size) < 100
          else:
              assert diff.mean() < 2.5
  
imports: import gc
  import os
  import platform
  import sys
  import threading
  import time
  import warnings
  from io import BytesIO
  from pathlib import Path
  import imageio.plugins
  import imageio.v2
  import imageio.v3
  import numpy
  import pytest
  from imageio import core
  from imageio.core import IS_PYPY
  from conftest import deprecated_test
label_desc: Use image node_id 6 for calling a global function with example usage: test_read_and_write(test_images, tmp_path) without return types