How to capture 60 FPS at normal speed on Logitech c922x

asked 2019-11-23 12:27:43 -0600

monilogi gravatar image

updated 2019-11-23 13:02:04 -0600

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()
edit retag flag offensive close merge delete

Comments

1

It seems possible that you haven't googled about this and found among others this: https://answers.opencv.org/question/1...

mvuori gravatar imagemvuori ( 2019-11-24 09:31:51 -0600 )edit

@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.

monilogi gravatar imagemonilogi ( 2019-11-25 19:11:01 -0600 )edit