代码实现
vid = cv2.VideoCapture(video_path)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
fps = vid.get(cv2.CAP_PROP_FPS)
size = (int(vid.get(cv2.CAP_PROP_FRAME_WIDTH)), int(vid.get(cv2.CAP_PROP_FRAME_HEIGHT)))
out = cv2.VideoWriter('camera_test.avi', fourcc, fps, size)
while True:
return_value, frame = vid.read()
if return_value:
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
image = Image.fromarray(frame)
else:
raise ValueError("No image!")
result = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
out.write(result)
cv2.imshow("result", result)
if cv2.waitKey(1) & 0xFF == ord('q'): break