Skip to content

Commit

Permalink
better name
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasHug committed Aug 19, 2024
1 parent bca6af3 commit f1e2328
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def temp_video(num_frames, height, width, fps, lossless=False, video_codec=None,


@pytest.mark.skipif(
get_video_backend() != "pyav" and not io._HAS_VIDEO_OPT, reason="video_reader backend not available"
get_video_backend() != "pyav" and not io._HAS_CPU_VIDEO_DECODER, reason="video_reader backend not available"
)
@pytest.mark.skipif(av is None, reason="PyAV unavailable")
class TestVideo:
Expand All @@ -77,14 +77,14 @@ def test_write_read_video(self):
assert_equal(data, lv)
assert info["video_fps"] == 5

@pytest.mark.skipif(not io._HAS_VIDEO_OPT, reason="video_reader backend is not chosen")
@pytest.mark.skipif(not io._HAS_CPU_VIDEO_DECODER, reason="video_reader backend is not chosen")
def test_probe_video_from_file(self):
with temp_video(10, 300, 300, 5) as (f_name, data):
video_info = io._probe_video_from_file(f_name)
assert pytest.approx(2, rel=0.0, abs=0.1) == video_info.video_duration
assert pytest.approx(5, rel=0.0, abs=0.1) == video_info.video_fps

@pytest.mark.skipif(not io._HAS_VIDEO_OPT, reason="video_reader backend is not chosen")
@pytest.mark.skipif(not io._HAS_CPU_VIDEO_DECODER, reason="video_reader backend is not chosen")
def test_probe_video_from_memory(self):
with temp_video(10, 300, 300, 5) as (f_name, data):
with open(f_name, "rb") as fp:
Expand Down
4 changes: 2 additions & 2 deletions test/test_video_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from numpy.random import randint
from pytest import approx
from torchvision import set_video_backend
from torchvision.io import _HAS_VIDEO_OPT
from torchvision.io import _HAS_CPU_VIDEO_DECODER


try:
Expand Down Expand Up @@ -263,7 +263,7 @@ def _get_video_tensor(video_dir, video_file):


@pytest.mark.skipif(av is None, reason="PyAV unavailable")
@pytest.mark.skipif(_HAS_VIDEO_OPT is False, reason="Didn't compile with ffmpeg")
@pytest.mark.skipif(_HAS_CPU_VIDEO_DECODER is False, reason="Didn't compile with ffmpeg")
class TestVideoReader:
def check_separate_decoding_result(self, tv_result, config):
"""check the decoding results from TorchVision decoder"""
Expand Down
4 changes: 2 additions & 2 deletions test/test_videoapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import torchvision
from pytest import approx
from torchvision.datasets.utils import download_url
from torchvision.io import _HAS_VIDEO_OPT, VideoReader
from torchvision.io import _HAS_CPU_VIDEO_DECODER, VideoReader


# WARNING: these tests have been skipped forever on the CI because the video ops
Expand Down Expand Up @@ -62,7 +62,7 @@ def fate(name, path="."):
}


@pytest.mark.skipif(_HAS_VIDEO_OPT is False, reason="Didn't compile with ffmpeg")
@pytest.mark.skipif(_HAS_CPU_VIDEO_DECODER is False, reason="Didn't compile with ffmpeg")
class TestVideoApi:
@pytest.mark.skipif(av is None, reason="PyAV unavailable")
@pytest.mark.parametrize("test_video", test_videos.keys())
Expand Down
2 changes: 1 addition & 1 deletion torchvision/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def set_video_backend(backend):
global _video_backend
if backend not in ["pyav", "video_reader", "cuda"]:
raise ValueError("Invalid video backend '%s'. Options are 'pyav', 'video_reader' and 'cuda'" % backend)
if backend == "video_reader" and not io._HAS_VIDEO_OPT:
if backend == "video_reader" and not io._HAS_CPU_VIDEO_DECODER:
# TODO: better messages
message = "video_reader video backend is not available. Please compile torchvision from source and try again"
raise RuntimeError(message)
Expand Down
2 changes: 2 additions & 0 deletions torchvision/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
_HAS_GPU_VIDEO_DECODER = False

from ._video_opt import (
_HAS_CPU_VIDEO_DECODER,
_HAS_VIDEO_OPT,
_probe_video_from_file,
_probe_video_from_memory,
Expand Down Expand Up @@ -49,6 +50,7 @@
"_read_video_from_memory",
"_read_video_timestamps_from_memory",
"_probe_video_from_memory",
"_HAS_CPU_VIDEO_DECODER",
"_HAS_VIDEO_OPT",
"_HAS_GPU_VIDEO_DECODER",
"_read_video_clip_from_memory",
Expand Down
5 changes: 3 additions & 2 deletions torchvision/io/_video_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

try:
_load_library("video_reader")
_HAS_VIDEO_OPT = True
_HAS_CPU_VIDEO_DECODER = True
except (ImportError, OSError):
_HAS_VIDEO_OPT = False
_HAS_CPU_VIDEO_DECODER = False

_HAS_VIDEO_OPT = _HAS_CPU_VIDEO_DECODER # For BC
default_timebase = Fraction(0, 1)


Expand Down
4 changes: 2 additions & 2 deletions torchvision/io/video_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

from ..utils import _log_api_usage_once

from ._video_opt import _HAS_VIDEO_OPT
from ._video_opt import _HAS_CPU_VIDEO_DECODER

if _HAS_VIDEO_OPT:
if _HAS_CPU_VIDEO_DECODER:

def _has_video_opt() -> bool:
return True
Expand Down

0 comments on commit f1e2328

Please sign in to comment.