1
1
import torch
2
+ from typing import Any , Dict , Iterator
2
3
3
4
from ._video_opt import (
4
5
Timebase ,
33
34
34
35
if _HAS_VIDEO_OPT :
35
36
36
- def _has_video_opt ():
37
+ def _has_video_opt () -> bool :
37
38
return True
38
39
39
40
40
41
else :
41
42
42
- def _has_video_opt ():
43
+ def _has_video_opt () -> bool :
43
44
return False
44
45
45
46
@@ -99,7 +100,7 @@ class VideoReader:
99
100
Currently available options include ``['video', 'audio']``
100
101
"""
101
102
102
- def __init__ (self , path , stream = "video" ):
103
+ def __init__ (self , path : str , stream : str = "video" ) -> None :
103
104
if not _has_video_opt ():
104
105
raise RuntimeError (
105
106
"Not compiled with video_reader support, "
@@ -109,7 +110,7 @@ def __init__(self, path, stream="video"):
109
110
)
110
111
self ._c = torch .classes .torchvision .Video (path , stream )
111
112
112
- def __next__ (self ):
113
+ def __next__ (self ) -> Dict [ str , Any ] :
113
114
"""Decodes and returns the next frame of the current stream.
114
115
Frames are encoded as a dict with mandatory
115
116
data and pts fields, where data is a tensor, and pts is a
@@ -126,10 +127,10 @@ def __next__(self):
126
127
raise StopIteration
127
128
return {"data" : frame , "pts" : pts }
128
129
129
- def __iter__ (self ):
130
+ def __iter__ (self ) -> Iterator [ 'VideoReader' ] :
130
131
return self
131
132
132
- def seek (self , time_s : float ):
133
+ def seek (self , time_s : float ) -> 'VideoReader' :
133
134
"""Seek within current stream.
134
135
135
136
Args:
@@ -144,15 +145,15 @@ def seek(self, time_s: float):
144
145
self ._c .seek (time_s )
145
146
return self
146
147
147
- def get_metadata (self ):
148
+ def get_metadata (self ) -> Dict [ str , Any ] :
148
149
"""Returns video metadata
149
150
150
151
Returns:
151
152
(dict): dictionary containing duration and frame rate for every stream
152
153
"""
153
154
return self ._c .get_metadata ()
154
155
155
- def set_current_stream (self , stream : str ):
156
+ def set_current_stream (self , stream : str ) -> bool :
156
157
"""Set current stream.
157
158
Explicitly define the stream we are operating on.
158
159
0 commit comments