Search code examples
pythonpython-3.xopencvframe-rate

Decrease FPS of a camera using python


I'm reading frames from a camera which displays which has original fps set to 25. I'm trying to reduce the FPS of this to about 6-7.

I'm reading multiple cameras at the same time and appending the frames to the respective camera's deque. I've used threading here.

So, far I'm doing this but no luck

while True:
    try:
        # Read next frame from stream and insert into deque
        status, frame = self.capture.read()
        frame = cv2.resize(frame, (640, 360))

        if status:
            self.deque.append(frame)
        else:
            self.capture.release()
            self.online = False

Solution

  • frame_count = 1
            
    while True:
        try:
        # Read next frame from stream and insert into deque
        status, frame = self.capture.read()
                        
        if frame_count % 4 == 0:
            frame = cv2.resize(frame, (640, 360))
    
            if status:
                self.deque.append(frame)
            else:
                self.capture.release()
                self.online = False
        frame_count += 1