pytorch / pytorch/vision

Obscure error messages using VideoReader when PyAV version too old/not installed

Open
#8,510 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.