Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[videoAPI] minor example and documentation changes #2821

Merged
merged 8 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 123 additions & 53 deletions examples/python/video_api.ipynb

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions torchvision/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@


if _HAS_VIDEO_OPT:

def _has_video_opt():
return True


else:

def _has_video_opt():
return False

Expand Down Expand Up @@ -87,15 +91,24 @@ class VideoReader:

def __init__(self, path, stream="video"):
if not _has_video_opt():
raise RuntimeError("Not compiled with video_reader support")
raise RuntimeError(
"Not compiled with video_reader support, "
+ "to enable video_reader support, please install "
+ "ffmpeg (version 4.2 is currently supported) and"
+ "build torchvision from source."
)
self._c = torch.classes.torchvision.Video(path, stream)

def __next__(self):
"""Decodes and returns the next frame of the current stream
"""Decodes and returns the next frame of the current stream.
At the moment, frames are encoded as a dict with mandatory
bjuncek marked this conversation as resolved.
Show resolved Hide resolved
data and pts fields, where data is a tensor, and pts is a
presentation timestamp of the frame expressed in seconds
as a float.

Returns:
(dict): a dictionary with fields ``data`` and ``pts``
containing decoded frame and corresponding timestamp
containing decoded frame and corresponding timestamp
bjuncek marked this conversation as resolved.
Show resolved Hide resolved

"""
frame, pts = self._c.next()
Expand Down