Skip to content

Commit

Permalink
[fbsync] Remove deprecated path parameter to VideoReader and made src…
Browse files Browse the repository at this point in the history
… mandatory (#8125)

Summary: Co-authored-by: vfdev <vfdev.5@gmail.com>

Reviewed By: vmoens

Differential Revision: D52538998

fbshipit-source-id: a94116a744de3180bf9eea3fbfc02202a681cdd0
  • Loading branch information
NicolasHug authored and facebook-github-bot committed Jan 15, 2024
1 parent 0b44780 commit d5495cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
8 changes: 8 additions & 0 deletions test/test_videoapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ def test_keyframe_reading(self, test_video, config, backend):
for i in range(len(av_keyframes)):
assert av_keyframes[i] == approx(vr_keyframes[i], rel=0.001)

def test_src(self):
with pytest.raises(ValueError, match="src cannot be empty"):
VideoReader(src="")
with pytest.raises(ValueError, match="src must be either string"):
VideoReader(src=2)
with pytest.raises(TypeError, match="unexpected keyword argument"):
VideoReader(path="path")


if __name__ == "__main__":
pytest.main([__file__])
22 changes: 5 additions & 17 deletions torchvision/io/video_reader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io
import warnings

from typing import Any, Dict, Iterator, Optional
from typing import Any, Dict, Iterator

import torch

Expand Down Expand Up @@ -102,40 +102,28 @@ class VideoReader:
If Tensor, it is interpreted internally as byte buffer.
It must be one-dimensional, of type ``torch.uint8``.
stream (string, optional): descriptor of the required stream, followed by the stream id,
in the format ``{stream_type}:{stream_id}``. Defaults to ``"video:0"``.
Currently available options include ``['video', 'audio']``
num_threads (int, optional): number of threads used by the codec to decode video.
Default value (0) enables multithreading with codec-dependent heuristic. The performance
will depend on the version of FFMPEG codecs supported.
path (str, optional):
.. warning:
This parameter was deprecated in ``0.15`` and will be removed in ``0.17``.
Please use ``src`` instead.
"""

def __init__(
self,
src: str = "",
src: str,
stream: str = "video",
num_threads: int = 0,
path: Optional[str] = None,
) -> None:
_log_api_usage_once(self)
from .. import get_video_backend

self.backend = get_video_backend()
if isinstance(src, str):
if src == "":
if path is None:
raise TypeError("src cannot be empty")
src = path
warnings.warn("path is deprecated and will be removed in 0.17. Please use src instead")
if not src:
raise ValueError("src cannot be empty")
elif isinstance(src, bytes):
if self.backend in ["cuda"]:
raise RuntimeError(
Expand All @@ -154,7 +142,7 @@ def __init__(
"VideoReader cannot be initialized from Tensor object when using cuda or pyav backend."
)
else:
raise TypeError("`src` must be either string, Tensor or bytes object.")
raise ValueError(f"src must be either string, Tensor or bytes object. Got {type(src)}")

if self.backend == "cuda":
device = torch.device("cuda")
Expand Down

0 comments on commit d5495cd

Please sign in to comment.