Last active
October 11, 2023 16:00
-
-
Save mattroz/b6b8e881f5971d680905cb0c00bc4d21 to your computer and use it in GitHub Desktop.
opencv video reader/writer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
from pathlib import Path | |
path_to_video = Path("some/path/to/video.mp4") | |
video_handler = cv2.VideoCapture(str(path_to_video)) | |
n_frames = int(video_handler.get(cv2.CAP_PROP_FRAME_COUNT)) | |
w = int(video_handler.get(cv2.CAP_PROP_FRAME_WIDTH)) | |
h = int(video_handler.get(cv2.CAP_PROP_FRAME_HEIGHT)) | |
fps = video_handler.get(cv2.CAP_PROP_FPS) | |
fourcc = cv2.VideoWriter_fourcc(*'mp4v') | |
video_writer = cv2.VideoWriter(str(path_to_save_video), fourcc, fps, (w, h)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment