Recording video breaks experiment

Hi,

I am using Windows 11 and the latest PSychoPy version (v2024.1.4). While participants watch a 180 sec video on the screen I want to record their facial expressions. The video component and the code component are part of the same routine. After 180sec the video component force ends the routine. This is the code:

(Begin experiment)

import cv2 as cv

webcam = cv.VideoCapture(0)
fourcc = cv.VideoWriter_fourcc(*'mp4v')
filename = u'data/RECORDING_%s_%s_%s' % (expName, expInfo['participant'], expInfo['date'])
out = cv.VideoWriter('OUTPUT.mp4', fourcc, 20.0, (640, 480))

(Each frame)

while webcam.isOpened():
      
    ret, frame = webcam.read()
    out.write(frame)
    
    c = cv.waitKey(1)
    if c == 27:
        break

webcam.release()
out.release()
cv.destroyAllWindows()

The video is recorded and saved into OUTPUT.mp4. However, the experiment just stops. That is, the 180sec video is not shown, presumably because Psychopy is busy recording the video (which works fine until I ESC the experiment; then it is saved) and the experiment is not continued as planned. I want to run the code and record the video in the background as long as the routine is current. This would result in a 180sec recorded video.

Thanks in advance!
Sebb

Hi Sebb,

Is there a reason that you are choosing to use code rather than the camera component in PsychoPy builder? The camera component should achieve what you need here as well.

Thanks!
Becca

Hi Becca,

thanks for your reply! I tried it out but then discarded it due to performance issues. As I explained, I simultaneously need to display a stimulus video of 180 sec. and record a video. The camera component would fulfill that task but not without needing 3-4 additional minutes to actually save the video as a file. During that time the experiment would not be continued. Moreover, the design is repeated three more times, so that I would end up with four videos of 180sec each. But instead I got four videos of varying length 180, 360, 540, 720 sec where the fourth video would be comprised of all four recordings made with increasing time needed to save the video.

I attributed these performance issues to the fact that the camera component is still flagged as “beta” but if you have any idea how to improve performance I’d be glad to hear!

Best, Sebastian