I know that the VideoWriter
object's FPS should match the FPS of my webcam. My webcam is a Logitech HD Pro Webcam C920 and as you can see, the spec says it has a FPS of 30. Still instead of hardcoding the value, I use cap.get(CV_CAP_PROP_FPS)
(which returns 30.0) to be sure to match the FPS.
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
out = cv2.VideoWriter('output.avi', fourcc, cap.get(CV_CAP_PROP_FPS), (640, 480))
print(cap.get(CV_CAP_PROP_FPS)) # 30.0
This is how I capture each frame of the video:
while(cap.isOpened()):
# Capture frame-by-frame
ret, frame = cap.read()
if ret == True:
out.write(frame)
My problem is that, even with matching FPSs, the output video (output.avi
) has a playback speed of about x3 (according to my non-scientific estimation), which is obviously not what I want. I have tried with different codecs, but the same problem occurs.
There are a couple questions on SO that are addressing this same problem:
OpenCV, captured video runs faster than original camera video!
OpenCV Video capture and fps problem
OpenCV: Video Recording is too fast
http://answers.opencv.org/question/16522/video-recording-is-too-fast/
Most of which suggest to match the FPS of the writer, with the FPS of the webcam, which I did. If I hardcode the FPS to 10, the video playback seems normal, but I don't want to do that, as it has to work generically with many cameras.
I don't really know what to do at this point, but I'll keep searching until I find the solution. Any insight is appreciated!!