cutcutcodec.core.analysis.video.properties.nb_frames.get_nb_frames
- cutcutcodec.core.analysis.video.properties.nb_frames.get_nb_frames(filename: Path | str | bytes, index: int = 0, *, backend: str | None = None, accurate: bool = False) int[source]
Recovers the number of frames present in a video stream.
Parameters
- filenamepathlike
The pathlike of the file containing a video stream.
- indexint
The relative index of the video stream being considered, by default the first stream encountered is selected.
- backendstr, optional
None (default) : Try to read the stream by trying differents backends.
‘ffmpeg’ : Uses the
ffmpegprogram in the background.‘cv2’ : Uses the module
pip install opencv-contrib-python-headless.
- accurateboolean, optional
If True, recovers the number of frames by fully decoding all the frames in the video. It is very accurate but very slow. If False (default), first tries to get the frame count from the file metadata. It’s not accurate but very fast.
Returns
- nbrint
The number of readed frames.
Raises
- MissingStreamError
If the file does not contain a playable video stream.
- MissingInformation
If the information is unavailable.
Examples
>>> from cutcutcodec.core.analysis.video.properties.nb_frames import get_nb_frames >>> from cutcutcodec.utils import get_project_root >>> video = get_project_root().parent / "media" / "video" / "intro.webm" >>> get_nb_frames(video) 294 >>>