Skip to content

Commit 36daee3

Browse files
bjuncekBruno Korbarvfdev-5
authored
[videoAPI] minor example and documentation changes (#2821)
* 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 <korbar@vggdev9.vggdev.cluster> Co-authored-by: vfdev <vfdev.5@gmail.com>
1 parent dc5d055 commit 36daee3

File tree

2 files changed

+145
-62
lines changed

2 files changed

+145
-62
lines changed

examples/python/video_api.ipynb

Lines changed: 128 additions & 58 deletions
Large diffs are not rendered by default.

torchvision/io/__init__.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@
3131

3232

3333
if _HAS_VIDEO_OPT:
34+
3435
def _has_video_opt():
3536
return True
37+
38+
3639
else:
40+
3741
def _has_video_opt():
3842
return False
3943

@@ -91,15 +95,24 @@ class VideoReader:
9195

9296
def __init__(self, path, stream="video"):
9397
if not _has_video_opt():
94-
raise RuntimeError("Not compiled with video_reader support")
98+
raise RuntimeError(
99+
"Not compiled with video_reader support, "
100+
+ "to enable video_reader support, please install "
101+
+ "ffmpeg (version 4.2 is currently supported) and"
102+
+ "build torchvision from source."
103+
)
95104
self._c = torch.classes.torchvision.Video(path, stream)
96105

97106
def __next__(self):
98-
"""Decodes and returns the next frame of the current stream
107+
"""Decodes and returns the next frame of the current stream.
108+
Frames are encoded as a dict with mandatory
109+
data and pts fields, where data is a tensor, and pts is a
110+
presentation timestamp of the frame expressed in seconds
111+
as a float.
99112
100113
Returns:
101-
(dict): a dictionary with fields ``data`` and ``pts``
102-
containing decoded frame and corresponding timestamp
114+
(dict): a dictionary and containing decoded frame (``data``)
115+
and corresponding timestamp (``pts``) in seconds
103116
104117
"""
105118
frame, pts = self._c.next()

0 commit comments

Comments
 (0)