我製作了一個簡短的腳本,它是一個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