-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocess_video.py
31 lines (25 loc) · 900 Bytes
/
process_video.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import cv2
def process_video(input_path, output_path):
cap = cv2.VideoCapture(input_path)
if not cap.isOpened():
print(f"Error: Cannot open video file {input_path}")
return
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
fps = cap.get(cv2.CAP_PROP_FPS)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
print(f"Width: {width}; Height: {height}; FPS: {fps}")
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
if not out.isOpened():
print(f"Error: Cannot open video writer {output_path}")
return
frame_count = 0
while True:
ret, frame = cap.read()
if not ret:
break
out.write(frame)
frame_count += 1
cap.release()
out.release()
process_video("videos/testvideo3.mp4", "videos/newvid.mp4")