cutcutcodec.core.analysis.video.properties.timestamps
Recover the date of all the frames that make up a video stream.
This information is more accurate than the simple fps
but it takes much longer to retrieve since it requires decoding the entire file.
Functions
|
Recover the date of appearance of the frames. |
Details
- cutcutcodec.core.analysis.video.properties.timestamps.get_timestamps_video(filename: Path | str | bytes, index: int = 0, *, backend: str | None = None, interpolate: bool = True) ndarray[None | Fraction][source]
Recover the date of appearance of the frames.
In case the frame rate is perfectly constant, this returns
[0, 1/fps, 2/fps, ..., (n-1)/fps]with n the number of frames present in the video. But in case the frequency of images is not quite constant, this function has more interest.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.
- interpolatebool, optional
If True (default), then the frames whose position is unknown are interpolated from the set of correctly dated frames. If False, the unconfirmed positions are translated as “np.nan”.
Returns
- datesFraction or None
The numpy 1d list containing the dates in seconds, encoded in Fraction. If a position is unknown and interpolate is set to False, the values None are used.
Raises
- MissingStreamError
If the file does not contain a playable video stream.
Examples
>>> from cutcutcodec.core.analysis.video.properties.timestamps import get_timestamps_video >>> get_timestamps_video("cutcutcodec/examples/video.mp4") array([Fraction(0, 1), Fraction(1, 25), Fraction(2, 25), Fraction(3, 25), Fraction(4, 25), Fraction(1, 5), Fraction(6, 25), Fraction(7, 25), Fraction(8, 25), Fraction(9, 25), Fraction(2, 5), Fraction(11, 25), ... Fraction(393, 25), Fraction(394, 25), Fraction(79, 5), Fraction(396, 25), Fraction(397, 25), Fraction(398, 25), Fraction(399, 25)], dtype=object) >>> get_timestamps_video("cutcutcodec/examples/intro.webm") array([Fraction(0, 1), Fraction(33, 1000), Fraction(67, 1000), Fraction(1, 10), Fraction(133, 1000), Fraction(167, 1000), Fraction(1, 5), Fraction(117, 500), Fraction(267, 1000), ... Fraction(961, 100), Fraction(9643, 1000), Fraction(2419, 250), Fraction(971, 100), Fraction(9743, 1000), Fraction(1222, 125)], dtype=object) >>>