我无法在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秒。