[open] Help recording webcam video to file via OpenCV
I am currently trying to implement a background video recording process that would run while a movie was played onscreen. Conceptually, everything is in place and ready, the only problem is when I attempt to save the video being recorded to a file, the file is saved without content. Some investigating shows that the main issue behind this error is codecs, or lack there of.
I was able to record the video to file successfully in PsychoPy, and upon investigation saw that there is a DLL folder holding all the binaries necessary for ffmpeg, is there an equivalent location for the compiled version of OpenSesame?
If that is the case with ffmpeg, what I would like to do is utilize ffmpeg binaries to save the video file to mpeg, but I can't determine how to do this without running OpenSesame from source, which at this point in development is not feasible.
Here is my (simplified) code for testing purposes:
import numpy as np import cv2 cap = cv2.VideoCapture(0) # Define the codec and create VideoWriter object fourcc = cv2.cv.CV_FOURCC(*'MJPG') out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480)) i=0 while(cap.isOpened()): ret, frame = cap.read() i += 1 if ret==True: # write the frame out.write(frame) # show frame cv2.imshow('frame',frame) # escape after a few seconds of recording if i > 200: break else: break # Release everything if job is finished cap.release() out.release() cv2.destroyAllWindows()
As a side note, when I run this script, it doesn't show the image being stored to the
frame variable. I assume this is related to the codec issue, but is to some degree irrelevant as we don't want to show the frame during the experiment.