How to capture 60 FPS at normal speed on Logitech c922x
The code below writes a .avi file and displays the FPS in the terminal. However, the terminal only outputs the FPS as 30 FPS. Also, the video playback is too fast. What am I doing wrong? Any suggestions are welcome!
import cv2
import time as time
import os
filename = 'video.avi'
frames_per_seconds = 60
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FPS, frames_per_seconds)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
framecount = 0
prevMillis = 0
print(cap.get(5))
def fpsCount():
global prevMillis
global framecount
millis = int(round(time.time() * 1000))
framecount += 1
if millis - prevMillis > 1000:
print(framecount)
prevMillis = millis
framecount = 0
video_type_cv2 = 'avi'
save_path = os.path.join('', filename)
out = cv2.VideoWriter(save_path, cv2.VideoWriter_fourcc(*'PIM1'), frames_per_seconds, (1280, 720))
while True:
__, frame = cap.read()
out.write(frame)
cv2.imshow("Image", frame)
fpsCount()
k = cv2.waitKey(1) & 0xff
if k == 27:
break
cap.release()
out.release()
cv2.destroyAllWindows()
It seems possible that you haven't googled about this and found among others this: https://answers.opencv.org/question/1...
@mvuori I've tried cap.set(cv2.CAP_DSHOW, 0), cap.set(cv2.CAP_ANY, 0), cap.set(cv2.CAP_FFMPEG, 0) and they all give me a frame rate of ~30 fps. Perhaps there's an additional 'set' that I need to pass in? Also, if it makes any difference, I'm on a Mac.