code: def test_keyframe_intervals(test_images):
      buffer = io.BytesIO()
      with ExitStack() as ctx:
          in_file = ctx.enter_context(
              iio.imopen(
                  test_images / "cockatoo.mp4", "r", plugin="pyav"
              )
          )
          out_file = ctx.enter_context(
              iio.imopen(buffer, "w", plugin="pyav", extension=".mp4")
          )
  
          out_file.init_video_stream(
              "libx264", max_keyframe_interval=5, force_keyframes=True
          )
  
          for idx in range(50):
              frame = in_file.read(index=idx)
              out_file.write_frame(frame)
  
      buffer.seek(0)
      key_dist = [0]
      i_dist = [0]
      with iio.imopen(buffer, "r", plugin="pyav") as file:
          n_frames = file.properties().shape[0]
          for idx in range(1, n_frames):
              medatada = file.metadata(index=idx)
              if medatada["frame_type"] == "I":
                  i_dist.append(idx)
              if medatada["key_frame"]:
                  key_dist.append(idx)
  
      assert np.max(np.diff(i_dist)) <= 5
      assert np.max(np.diff(key_dist)) <= 5
  
imports: import io
  import warnings
  from contextlib import ExitStack
  from pathlib import Path
  import numpy
  import pytest
  from conftest import IS_PYPY
  import imageio.v3
  from av.video.format import names
  from imageio.plugins.pyav import _format_to_dtype
label_desc: Use image node_id 29 for calling a global function with example usage: test_keyframe_intervals(test_images) without return types