VideoReader¶
- class mmcv.video.VideoReader(filename, cache_capacity=10)[源代码]¶
Video class with similar usage to a list object.
This video wrapper class provides convenient apis to access frames. There exists an issue of OpenCV’s VideoCapture class that jumping to a certain frame may be inaccurate. It is fixed in this class by checking the position after jumping each time. Cache is used when decoding videos. So if the same frame is visited for the second time, there is no need to decode again if it is stored in the cache.
实际案例
>>> import mmcv >>> v = mmcv.VideoReader('sample.mp4') >>> len(v) # get the total frame number with `len()` 120 >>> for img in v: # v is iterable >>> mmcv.imshow(img) >>> v[5] # get the 6th frame
- current_frame()[源代码]¶
Get the current frame (frame that is just visited).
- 返回
If the video is fresh, return None, otherwise return the frame.
- 返回类型
ndarray or None
- cvt2frames(frame_dir, file_start=0, filename_tmpl='{:06d}.jpg', start=0, max_num=0, show_progress=True)[源代码]¶
Convert a video to frame images.
- 参数
frame_dir (str) – Output directory to store all the frame images.
file_start (int) – Filenames will start from the specified number.
filename_tmpl (str) – Filename template with the index as the placeholder.
start (int) – The starting frame index.
max_num (int) – Maximum number of frames to be written.
show_progress (bool) – Whether to show a progress bar.
- read()[源代码]¶
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.
- 返回
Return the frame if successful, otherwise None.
- 返回类型
ndarray or None
- property vcap¶
The raw VideoCapture object.
- Type
cv2.VideoCapture