Obscure error messages using VideoReader when PyAV version too old/not installed
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17.9k
- Forks
- 7.3k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 13
Description
🐛 Describe the bug
When a sufficiently recent version of PyAV is not installed, the script vision/torchvision/io/video_reader.py initialises the variable av to an ImportError object that contains a description of the issue, either at line 38:
av = ImportError(
"""\
PyAV is not installed, and is necessary for the video operations in torchvision.
See https://github.com/mikeboers/PyAV#installation for instructions on how to
install PyAV on your system.
"""
)
or on line 28 (code omitted for brevity, but is similar to the above). This is potentially very useful information that would make it easy to see why an application isn't working. Unfortunately, this error is never actually raised.
Instead, when a VideoReader object is created, the av variable is simply assumed to contain the PyAV module object. This is first used on line 159:
self.container = av.open(src, metadata_errors="ignore")
As an ImportError object does not have a method called open, this results in a rather mystifying error condition being raised: AttributeError: 'ImportError' object has no attribute 'open'.
I suspect there should be a test immediately prior to line 159 which checks if av is an ImportError object and raises it if it is.
Versions
This bug is not related to specific versions, but can be seen by examination of the current version of the source code.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with vision/torchvision/io/video_reader.py, especially VideoReader initialization near the av.open call and the existing ImportError setup. Reproduce the missing or outdated PyAV case, then add coverage showing that the stored import error is raised instead of an AttributeError; done means the original PyAV installation message is exposed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100