sunnycloudhust's picture
Add TrafficVision source code and project configuration
6b41115 verified
Raw History Blame Contribute Delete
492 Bytes
from pathlib import Path
import cv2
class VideoWriter:
def __init__(self, path, fps, frame_size):
Path(path).parent.mkdir(parents=True, exist_ok=True)
self.writer = cv2.VideoWriter(str(path), cv2.VideoWriter_fourcc(*"mp4v"), fps, tuple(frame_size))
if not self.writer.isOpened():
raise RuntimeError(f"Cannot create MP4 writer: {path}")
def write(self, frame):
self.writer.write(frame)
def close(self):
self.writer.release()