cutcutcodec.core.analysis.video.properties.duration

Find the duration of a video stream.

This allows not only the characteristics of the files but also the tags if there are any.

Functions

get_duration_video(filename[, index, ...])

Recovers the total duration of a video stream.

Details

cutcutcodec.core.analysis.video.properties.duration.get_duration_video(filename: str | bytes | Path, index: int = 0, *, backend: None | str = None, accurate: bool = False) Fraction[source]

Recovers the total duration of a video stream.

The duration includes the display time o the last frame.

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 video 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, default=False

If True, recovers the duration by fully decoding all the frames in the video. It is very accurate but very slow. If False (default), first tries to get the duration from the file metadata. It’s not accurate but very fast.

Returns

durationFraction

The total duration of the considerated video stream.

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.duration import get_duration_video
>>> get_duration_video("cutcutcodec/examples/video.mp4")
Fraction(16, 1)
>>> get_duration_video("cutcutcodec/examples/intro.webm")
Fraction(9809, 1000)
>>>