Skip to content

Commit

Permalink
[videoAPI] minor example and documentation changes (pytorch#2821)
Browse files Browse the repository at this point in the history
* Modified the example to conform with the new DICT return.

* adding better stream documentation to examples

* Clearing up some documentation as a result of a feedback

* Formatting mostly

* Addressing Victor's comments.

* addressing fmassas comments

* remove unnecessary tab

Co-authored-by: Bruno Korbar <[email protected]>
Co-authored-by: vfdev <[email protected]>
  • Loading branch information
3 people authored and bryant1410 committed Nov 22, 2020
1 parent 6f976fa commit 83cca9f
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 62 deletions.
186 changes: 128 additions & 58 deletions examples/python/video_api.ipynb

Large diffs are not rendered by default.

21 changes: 17 additions & 4 deletions torchvision/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@


if _HAS_VIDEO_OPT:

def _has_video_opt():
return True


else:

def _has_video_opt():
return False

Expand Down Expand Up @@ -91,15 +95,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.
Frames are encoded as a dict with mandatory
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
(dict): a dictionary and containing decoded frame (``data``)
and corresponding timestamp (``pts``) in seconds
"""
frame, pts = self._c.next()
Expand Down

0 comments on commit 83cca9f

Please sign in to comment.