cv2:无法创建特定时长的视频

时间:2020-02-19 15:31:29

标签: python-3.x cv2 psychopy

我无法在PsychoPy中创建持续30秒的网络摄像头视频。相反,该视频的时长约为43秒。我的代码如下(略作编辑):

from psychopy import locale_setup, visual, core, event, data, gui, microphone
import cv2

#Set up Timer:
trialTimer = core.Clock()

#Begin Video Recording:
cap = cv2.VideoCapture(0 + cv2.CAP_DSHOW)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('{}.avi'.format(video_path),fourcc, 20.0, (640,480))

trialTimer.reset()

while trialTimer.getTime() < 30:
    ret, frame = cap.read()
    out.write(frame)

#Stop video recording:
cap.release()
out.release()
cv2.destroyAllWindows()

视频循环清晰(即不太快或太慢),因此我不确定如何调整以使视频长度缩短到30秒。

0 个答案:

没有答案