我制作了一个简短的脚本,它是一个rubik的立方体定时器的开始,但是当我回放录制的视频时,速度非常快。Python OpenCV视频录制快转
我的摄像头是'Creative Labs Live! Cam Chat HD',分辨率为1280 * 720像素,边注;当我尝试在该分辨率下运行脚本编码播放失败时,帧速率为30 fps。
下面是显示效果的代码和视频链接。
from time import clock as t
import time
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*"XVID")
out = cv2.VideoWriter("output.avi", fourcc, 30.0, (640, 480))
timing = False
while True:
ret, frame = cap.read()
#frame = cv2.flip(frame, 1)
cv2.imshow("frame", frame)
if timing:
out.write(frame)
if cv2.waitKey(1) & 0xFF == ord(" "):
if timing:
after = t()
break
else:
timing = True
start = t()
cap.release()
out.release()
cv2.destroyAllWindows()
print(after - start)
Example of the accelerated video.
对于开始,改变硬编码的每秒30帧到20也许并告诉我们结果 – Aleksandar