Skip to content

AttributeError: 'av.video.codeccontext.VideoCodecContext' object has no attribute 'close' #1699

@danielhaviv

Description

@danielhaviv

Overview

When itrating over the frames of a video file using the example in the docs, the following exception is raised: AttributeError: 'av.video.codeccontext.VideoCodecContext' object has no attribute 'close'.

This only happens when plugin=pyav.

result = iio.imiter("path_to_file", plugin="pyav", thread_type="FRAME")

Expected behavior

The iteration the complete successfully.

Actual behavior

An exception is raised: AttributeError: 'av.video.codeccontext.VideoCodecContext' object has no attribute 'close'

Traceback:

File /local_disk0/.ephemeral_nfs/envs/pythonEnv-a7476e59-022b-400f-839b-7be4a4ea962a/lib/python3.11/site-packages/imageio/v3.py:90, in imiter(uri, plugin, extension, format_hint, **kwargs)
     57 def imiter(uri, *, plugin=None, extension=None, format_hint=None, **kwargs):
     58     """Read a sequence of ndimages from a URI.
     59 
     60     Returns an iterable that yields ndimages from the given URI. The exact
   (...)
     87 
     88     """
---> 90     with imopen(
     91         uri,
     92         "r",
     93         legacy_mode=False,
     94         plugin=plugin,
     95         format_hint=format_hint,
     96         extension=extension,
     97     ) as img_file:
     98         for image in img_file.iter(**kwargs):
     99             # Note: casting to ndarray here to ensure compatibility
    100             # with the v2.9 API
    101             yield np.asarray(image)
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-a7476e59-022b-400f-839b-7be4a4ea962a/lib/python3.11/site-packages/imageio/core/v3_plugin_api.py:367, in PluginV3.__exit__(self, type, value, traceback)
    366 def __exit__(self, type, value, traceback) -> None:
--> 367     self.close()
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-a7476e59-022b-400f-839b-7be4a4ea962a/lib/python3.11/site-packages/imageio/plugins/pyav.py:785, in PyAVPlugin.close(self)
    783 if self._video_stream is not None:
    784     try:
--> 785         self._video_stream.close()
    786     except ValueError:
    787         pass  # stream already closed
File av/video/stream.pyx:21, in av.video.stream.VideoStream.__getattr__()

Investigation

Read an AVI file using the linked example from the documentation.

Reproduction

Read an AVI file using the linked example from the documentation:

result = iio.imiter("path_to_file", plugin="pyav", thread_type="FRAME")
list(result)

Versions

  • OS: buntu 22.04.5 LTS
  • PyAV runtime:
PyAV v14.0.1
library configuration: --disable-static --enable-shared --libdir=/tmp/vendor/lib --prefix=/tmp/vendor --disable-alsa --disable-doc --disable-libtheora --disable-libfreetype --disable-libfontconfig --disable-libbluray --disable-libopenjpeg --disable-mediafoundation --enable-gmp --enable-gnutls --enable-libaom --enable-libdav1d --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-libspeex --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libxcb --enable-libxml2 --enable-lzma --enable-zlib --enable-version3 --enable-libx264 --disable-libopenh264 --enable-libx265 --enable-gpl
library license: GPL version 3 or later
libavcodec     61. 19.100
libavdevice    61.  3.100
libavfilter    10.  4.100
libavformat    61.  7.100
libavutil      59. 39.100
libswresample   5.  3.100
libswscale      8.  3.100
  • I am/tried using the binary wheels

Research

I have done the following:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions