cutcutcodec.core.analysis.video.properties.nb_frames.get_nb_frames

cutcutcodec.core.analysis.video.properties.nb_frames.get_nb_frames(filename: str | bytes | Path, index: int = 0, *, backend: None | str = 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 modules pip3 install ffmpeg-python

    which are using the ffmpeg program in the background.

  • “cv2” : Uses the module pip3 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
>>> get_nb_frames("cutcutcodec/examples/video.mp4")
400
>>> get_nb_frames("cutcutcodec/examples/intro.webm")
294
>>>