video2frames
video2frames(video_path: str | Path, frame_per_sec: int | None = None) -> list[np.ndarray]
-
Description: Extracts frames from a video. Supported video formats include
.MOV,.MP4,.AVI,.WEBM,.3GP, and.MKV. -
Parameters
- video_path (
str | Path): The path to the video file. - frame_per_sec (
int | None): The number of frames to extract per second. IfNone, all frames are extracted.
- video_path (
-
Returns
- list[np.ndarray]: A list of frames. Returns an empty list if the video cannot be opened.
-
Exceptions
- TypeError:
video_pathdoes not exist or has an unsupported file extension. - ValueError:
frame_per_sec <= 0.
- TypeError:
-
Example
import capybara as cb
frames = cb.video2frames('video.mp4', frame_per_sec=1)
for i, frame in enumerate(frames):
cb.imwrite(frame, f'{i}.jpg')