nncore.video

IO

class nncore.video.io.VideoReader(path, cache_size=16)[source]

A helper class for processing videos.

This 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.

Parameters:
  • path (str) – Path to the video.

  • cache_size (int, optional) – Maximum number of frames to cache. Default: 16.

dump_frames(out_dir, size=None, scale=None, interpolation='bilinear', template='img_{:05d}.jpg', interval=1, start=0, max_num=-1, progress=False, raise_error=True)[source]

Dump the video to resized frame images.

Parameters:
  • out_dir (str) – The output directory.

  • size (tuple[int] | None, optional) – The target frame size in the form of (width, height). Default: None.

  • scale (int | tuple[int] | None, optional) – The scaling factor or the maximum size. If it is a number, the image will be rescaled by this factor. When it is a tuple containing 2 numbers, the image will be rescaled as large as possible within the scale. In this case, -1 means infinity. Default: None.

  • interpolation (str | int, optional) – Interpolation method. Currently supported methods include nearest, bilinear, bicubic, area, and lanczos. Default: bilinear.

  • template (str, optional) – Filename template. Default: 'img_{:05d}.jpg'.

  • interval (int, optional) – The interval of dumped frames. Default: 1.

  • start (int, optional) – The starting frame index. Default: 0.

  • max_num (int, optional) – The maximum number of frames to be dumped. Default: -1.

  • progress (bool, optional) – Whether to display the progress bar. Default: False.

  • raise_error (bool, optional) – Whether to raise an error if a frame is not successfully decoded. Default: True.