Download DeepFakeAI/capturer.py from 17imred/v: direct link, hf CLI and curl.
- Browser
- Download file 627 Bytes
-
https://huggingface.co/spaces/17imred/v/resolve/main/DeepFakeAI/capturer.py
- Command line
-
hf download hf://spaces/17imred/v/DeepFakeAI/capturer.py
-
curl -L -o capturer.py https://huggingface.co/spaces/17imred/v/resolve/main/DeepFakeAI/capturer.py
627 Bytes
| from typing import Optional | |
| import cv2 | |
| from DeepFakeAI.typing import Frame | |
| def get_video_frame(video_path : str, frame_number : int = 0) -> Optional[Frame]: | |
| capture = cv2.VideoCapture(video_path) | |
| frame_total = capture.get(cv2.CAP_PROP_FRAME_COUNT) | |
| capture.set(cv2.CAP_PROP_POS_FRAMES, min(frame_total, frame_number - 1)) | |
| has_frame, frame = capture.read() | |
| capture.release() | |
| if has_frame: | |
| return frame | |
| return None | |
| def get_video_frame_total(video_path : str) -> int: | |
| capture = cv2.VideoCapture(video_path) | |
| video_frame_total = int(capture.get(cv2.CAP_PROP_FRAME_COUNT)) | |
| capture.release() | |
| return video_frame_total | |