I'm trying to record videos usin OpenCV in Python on Ubuntu 16.4. I'm using a Logitec 920 camera. My issue is that when I change the room illumination (from white to red light) or change the frame rate, the duration of the recorded video is altered becoming faster or slower dependingo on the situation. This is the code I'm using:
import numpy as np
import cv2
import time
cam = cv2.VideoCapture(0) # select the camera
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID') # (*'XVID')
out = cv2.VideoWriter('teste6.avi',fourcc, 30.0, (640,480))
# Start time in seconds
t0 = time.time()
while (cam.isOpened()):
ret, frame=cam.read() # read frames
if ret == True:
out.write(frame)
cv2.imshow('video',frame) # plot frames
t1 = time.time() # Current time
dur = t1-t0; # diff time
if dur > 60:
out.release() # Stop video recording
print('end')
if cv2.waitKey(1) & 0xFF== ord('q'): # close window pressing 'q' key
break
cam.release()
cv2.destroyAllWindows()
Any help?