Spaces:
Runtime error
Runtime error
import cv2 | |
def convert_video(video_path): | |
cap = cv2.VideoCapture(video_path) | |
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH) # float | |
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT) # float | |
fps = cap.get(cv2.CAP_PROP_FPS) | |
video_name = video_path.split('/')[-1].split('.')[0] | |
save_name = video_name + '_converted' | |
save_path = video_path.replace(video_name, save_name) | |
vid_writer = cv2.VideoWriter( | |
save_path, cv2.VideoWriter_fourcc(*"mp4v"), fps, (int(width), int(height)) | |
) | |
while True: | |
ret_val, frame = cap.read() | |
if ret_val: | |
vid_writer.write(frame) | |
ch = cv2.waitKey(1) | |
if ch == 27 or ch == ord("q") or ch == ord("Q"): | |
break | |
else: | |
break | |
if __name__ == "__main__": | |
video_path = 'videos/palace.mp4' | |
convert_video(video_path) |