Video reader
- class expert.data.video_reader.Cache(capacity: int)[source]
Bases:
objectCaching class for decoding videos.
If the same video frame is cached and used a second time, there is no need to decode it twice.
- Parameters
capacity (int) – Buffer size for storing frames.
- Raises
ValueError – If “capacity” is not a positive integer.
- class expert.data.video_reader.VideoReader(filename: Optional[Union[str, os.PathLike]], cache_capacity: Optional[int] = 10)[source]
Bases:
objectClass for decoding video to a list object.
This video wrapper class decodes the video and provides access to frames.
- Parameters
filename (str | PathLike) – Path to local video file.
cache_capacity (int, optional) – Buffer size for storing frames. Defaults to 10.
- Raises
IndexError – If the entered frame index is outside the allowed range of integer values.
IndexError – If the entered frame index is out of range.
StopIteration – If the end of the video has been reached.
- property vcap: cv2.VideoCapture
Get VideoCapture object.
- Returns
Raw VideoCapture object.
- Return type
cv2.VideoCapture
- property opened: bool
Check whether the video is opened.
- Returns
Indicate whether the video is opened.
- Return type
bool
- property width: int
Get width of video frames.
- Returns
Width of video frames.
- Return type
int
- property height: int
Get height of video frames.
- Returns
Height of video frames.
- Return type
int
- property resolution: Tuple[int, int]
Get Video resolution (width, height).
- Returns
Video resolution (width, height).
- Return type
Tuple
- property fps: float
Get FPS of the video.
- Returns
FPS of the video.
- Return type
float
- property frame_cnt: int
Get total number frames.
- Returns
Total frames of the video.
- Return type
int
- property fourcc: str
Get four character code.
- Returns
“Four character code” of the video.
- Return type
str
- property position: int
Get current cursor position.
- Returns
Current cursor position, indicating frame decoded.
- Return type
int
- read() Optional[numpy.ndarray][source]
Read the next frame.
If the next frame have been decoded before and in the cache, then return it directly, otherwise decode, cache and return it.
- Returns
Returns the frame if successful, otherwise returns None.
- Return type
ndarray or None