scikit-video: Video Processing in Python
scikit-video is a Python module for video processing, built on top of scipy, numpy, and relying on external `ffmpeg` or `libav` binaries. It aims to provide an all-in-one solution for research-level video processing, offering both high-level and low-level abstractions for reading, writing, and manipulating video files. The current version is 1.1.11, with development seemingly in maintenance mode since its last major release in 2018.
Warnings
- breaking Incompatibility with recent NumPy versions (>=1.20, especially >=1.24) due to the removal of `numpy.float` and `numpy.int` aliases, causing `AttributeError`.
- gotcha Older installations of `scikit-video` might have used the package name `sk-video`, leading to import conflicts or unexpected behavior if `scikit-video` is installed afterwards.
- gotcha The `skvideo.io.vread` function loads the entire video into memory. For large video files, this can lead to `MemoryError` or system instability.
- gotcha `skvideo.io.vread` can be significantly slower if `num_frames` is not explicitly provided, especially for certain video types, as it may perform multiple passes to auto-detect video properties.
- gotcha Requires external `ffmpeg` or `libav` binaries to be installed and available in the system's PATH. Without them, video I/O operations will fail.
- deprecated The `setup.py` script, used for installing from source, relies on `numpy.distutils`, which is deprecated and removed in Python 3.12 and later, potentially breaking source installations.
Install
-
pip install scikit-video
Imports
- skvideo.io
import skvideo.io
- skvideo.datasets
import skvideo.datasets
- skvideo.utils
import skvideo.utils
Quickstart
import skvideo.io
import skvideo.datasets
import numpy as np
# Get a sample video filename
filename = skvideo.datasets.bigbuckbunny()
# Read the video into a NumPy array
# For larger videos, consider skvideo.io.vreader for frame-by-frame processing
videodata = skvideo.io.vread(filename, num_frames=10) # Read first 10 frames for quick test
print(f"Video data shape: {videodata.shape}")
print(f"Data type: {videodata.dtype}")
# Example: Convert to grayscale (if not already)
if videodata.shape[-1] == 3:
# Simple average for grayscale, or use more advanced conversion
grayscale_video = np.mean(videodata, axis=-1, keepdims=True).astype(videodata.dtype)
print(f"Grayscale video shape: {grayscale_video.shape}")
# To prevent 'module numpy has no attribute float' errors with recent NumPy,
# you might need this workaround before importing anything that uses it if it breaks:
# import numpy
# numpy.float = numpy.float64
# numpy.int = numpy.int_