Camera recording overwrites output

Hi! I am designing a picture description task where participants describe the picture they see on the screen. While describing, their video and voice are being recorded, and they can see themselves in the camera frame. I want to save the videos for each participant, but I only get the recording of the last one. How can I save the output for each participant? I am new to the community. I hope my question was clear.

My code is:
for begin experiment:

import numpy as np
import cv2  # this is the OpenCV library for computer vision
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640,  480))
webCam = cv2.VideoCapture(0)  # connect to the zeroth video camera

for each frame:

returnVal, frame = webCam.read()
thisMovieFrame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)/255.0
out.write(frame)

Hi @eylul4, I never did this, but from reading your code I suspect that you need a variable filename. Otherwise, it gets overwritten each time there is a new output. Maybe

out = cv2.VideoWriter(participant + '_output.avi', fourcc, 20.0, (640,  480))

does the trick?

Hi @ajus, thank you for your answer! I tried it, but the experiment crashed with the warning:

“name ‘thisMovieFrame’ is not defined.” (it is the name of the variable for video recording)

Do you use the the variable participant?

Yes, I misunderstood the code first. After I put “expInfo” the code worked like a charm :slight_smile: Thank you very much! The final code is like this:

out = cv2.VideoWriter(expInfo['participant'] + '_output.avi', fourcc, 20.0, (640, 480))

1 Like

Ah yes, my mistake. Great that it works now!