cutcutcodec.core.io.read_ffmpeg.frame_dates

cutcutcodec.core.io.read_ffmpeg.frame_dates(frame: Frame) tuple[Fraction, None | Fraction][source]

Return the accurate time interval of the given frame.

Parameters

frameav.frame.Frame

The audio or video frame witch we extract the timing information.

Returns

t_startFraction

The display time of the frame. for audio frame, it corressponds to the time of the first sample.

t_endFraction or None

For audio frame only, the time to switch off the last sample. Return None for video frame.

Examples

>>> import av
>>> from cutcutcodec.core.io.read_ffmpeg import frame_dates
>>> from cutcutcodec.utils import get_project_root
>>> video = get_project_root().parent / "media" / "video" / "intro.webm"
>>> with av.open(video) as av_container:
...     frame_dates(next(av_container.decode(av_container.streams.video[0])))
...     frame_dates(next(av_container.decode(av_container.streams.video[0])))
...
(Fraction(0, 1), None)
(Fraction(33, 1000), None)
>>> audio = get_project_root().parent / "media" / "audio" / "narration_5_1.oga"
>>> with av.open(audio) as av_container:
...     frame_dates(next(av_container.decode(av_container.streams.audio[0])))
...     frame_dates(next(av_container.decode(av_container.streams.audio[0])))
...
(Fraction(0, 1), Fraction(4, 125))
(Fraction(4, 125), Fraction(8, 125))
>>>

Notes

For audio frame, include the duration of the last sample. For video frame, the duration of the frame is unknown.