cutcutcodec.core.analysis.video.properties.duration.get_duration_video¶
- cutcutcodec.core.analysis.video.properties.duration.get_duration_video(filename: Path | str | bytes, index: int = 0, *, backend: str | None = None, accurate: bool = False) Fraction[source]¶
Recovers the total duration of a video stream.
The duration includes the display time of 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
ffmpegprogram in the background.‘cv2’ : Uses the module
pip 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 >>> from cutcutcodec.utils import get_project_root >>> video = get_project_root() / "media" / "video" / "intro.webm" >>> get_duration_video(video) Fraction(9809, 1000) >>>