I am doing a minor research project for my Master's Degree and don't have much experience with programming, but I need to record myself juggling and then track the balls. Unfortunately, I am having trouble at the first stage. This is the code I am using to record
import numpy as np
import cv2
cap = cv2.VideoCapture(1)
# Define the codec and create VideoWriter object
out = cv2.VideoWriter('C:/Users/Sean/Videos/output1.avi', -1, 30.0, (640,480))
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()
I am using -1 for the fourcc to choose my own codec (Intel IYUV). I am using a Logitech C920 camera for this. If I record a very short video (~30 seconds) I can watch the video and open it in opencv with no issues. When I record longer videos, I cannot open the file. I have tried watching it in Windows Media Player which shows me that the first ~6 minutes of a 10 minute video is a multi-colored screen with shadows of me juggling in the background. The last 4 minutes is fine. What am I doing wrong?