cutcutcodec.core.io.read_av.FrameAnticipator¶
- class cutcutcodec.core.io.read_av.FrameAnticipator(filename: Path, idx: int, av_kwargs: dict[str])[source]¶
Accurate and predictive reader of raw frames.
Initialise the Anticipator.
Parameters¶
- filenamepathlib.Path
The path of the video file.
- idxint
The absolute index of the video stream, including the position of all the other streams.
- av_kwargsdict
Transmitted to
av.open.
- property curr_frame: VideoFrame¶
Return the frame at the current position.
- get_current_range() tuple[Fraction, Fraction][source]¶
Return the time interval cover by the current frame.
- snapshot(timestamp: Fraction) VideoFrame[source]¶
Return a video frame at the required timestamp.
Examples¶
>>> from fractions import Fraction >>> from cutcutcodec.core.io.read_av import FrameAnticipator >>> from cutcutcodec.utils import get_project_root >>> video = get_project_root() / "media" / "video" / "intro.webm" >>> frame_anticipator = FrameAnticipator(video, 0, {}) >>> frame_anticipator.snapshot(Fraction(0)) <av.VideoFrame, pts=0 yuv420p 1280x720 at ...> >>> frame_anticipator.snapshot(Fraction(1)) <av.VideoFrame, pts=968 yuv420p 1280x720 at ...> >>> frame_anticipator.snapshot(Fraction(2)) <av.VideoFrame, pts=1969 yuv420p 1280x720 at ...> >>> frame_anticipator.snapshot(Fraction(3)) <av.VideoFrame, pts=2970 yuv420p 1280x720 at ...> >>> frame_anticipator.snapshot(Fraction(4)) <av.VideoFrame, pts=3971 yuv420p 1280x720 at ...> >>>