Shortcuts

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.

property fourcc

“Four character code” of the video.

Type

str

property fps

FPS of the video.

Type

float

property frame_cnt

Total frames of the video.

Type

int

get_frame(frame_id)[源代码]

Get frame by index.

参数

frame_id (int) – Index of the expected frame, 0-based.

返回

Return the frame if successful, otherwise None.

返回类型

ndarray or None

property height

Height of video frames.

Type

int

property opened

Indicate whether the video is opened.

Type

bool

property position

Current cursor position, indicating frame decoded.

Type

int

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 resolution

Video resolution (width, height).

Type

tuple

property vcap

The raw VideoCapture object.

Type

cv2.VideoCapture

property width

Width of video frames.

Type

int

Read the Docs v: stable
Versions
latest
stable
2.x
v2.0.1
v2.0.0
1.x
v1.7.1
v1.7.0
v1.6.2
v1.6.1
v1.6.0
v1.5.3
v1.5.2_a
v1.5.1
v1.5.0
v1.4.8
v1.4.7
v1.4.6
v1.4.5
v1.4.4
v1.4.3
v1.4.2
v1.4.1
v1.4.0
v1.3.18
v1.3.17
v1.3.16
v1.3.15
v1.3.14
v1.3.13
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.