OpenCV Solution

According to this source, you can set the buffersize of a cv::VideoCapture object.

cv::VideoCapture cap;
cap.set(CV_CAP_PROP_BUFFERSIZE, 3); // internal buffer will now store only 3 frames

// rest of your code...

There is an important limitation however:

CV_CAP_PROP_BUFFERSIZE Amount of frames stored in internal buffer memory (note: only supported by DC1394 v 2.x backend currently)

Update from comments. In newer versions of OpenCV (3.4+), the limitation seems to be gone and the code uses scoped enumerations:

cv::VideoCapture cap;
cap.set(cv::CAP_PROP_BUFFERSIZE, 3);

Hackaround 1

If the solution does not work, take a look at this post that explains how to hack around the issue.

In a nutshell: the time needed to query a frame is measured; if it is too low, it means the frame was read from the buffer and can be discarded. Continue querying frames until the time measured exceeds a certain limit. When this happens, the buffer was empty and the returned frame is up to date.

(The answer on the linked post shows: returning a frame from the buffer takes about 1/8th the time of returning an up to date frame. Your mileage may vary, of course!)


Hackaround 2

A different solution, inspired by this post, is to create a third thread that grabs frames continuously at high speed to keep the buffer empty. This thread should use the cv::VideoCapture.grab() to avoid overhead.

You could use a simple spin-lock to synchronize reading frames between the real worker thread and the third thread.

Answer from Maarten Bamelis on Stack Overflow
🌐
ProgramCreek
programcreek.com › python › example › 110701 › cv2.CAP_PROP_BUFFERSIZE
Python Examples of cv2.CAP_PROP_BUFFERSIZE
def __init__(self, phone_ip): ip_camera_url = 'http://admin:admin@{}:8081/'.format(phone_ip) self.cap = cv2.VideoCapture(ip_camera_url) # 设置缓存区的大小 self.cap.set(cv2.CAP_PROP_BUFFERSIZE, self.CAP_BUFFER_SIZE) for i in range(self.INIT_JUMP_FRAME_NUM): ret, img = self.cap.read()
🌐
GitHub
github.com › opencv › opencv › issues › 10671
Can't set Buffersize in opencv 3 · Issue #10671 · opencv/opencv
January 23, 2018 - I tried to set the buffersize to minimize the delay in frames (there seems to be a delay of 100 ms in getting any frame) by using the following command in a python code: cap = cv2.VideoCapture(0) a=cap.get(cv2.CAP_PROP_BUFFERSIZE) # CV_CAP_PROP_BUFFERSIZE · print 'Buffersize', a ·
Author: opencv
Discussions

c++ - OpenCV VideoCapture lag due to the capture buffer - Stack Overflow
I am capturing video through a webcam which gives a mjpeg stream. I did the video capture in a worker thread. I start the capture like this: const std::string videoStreamAddress = "http://192.168.... More on stackoverflow.com
🌐 stackoverflow.com
node.js - How to disable Buffer in OpenCV Camera? - Stack Overflow
I have this situation where I use OpenCV to detect faces in front of the camera and do some ML on those faces. The issue that I have is that once I do all the processing, and go to grab the next fr... More on stackoverflow.com
🌐 stackoverflow.com
Can't Set CV_CAP_PROP_BUFFERSIZE
Problem Given an unknown source framerate and unknown frame processing time for each frame, we want to be able to always grab the most recent frame at the time of a read() call. In contrast to trad... More on github.com
🌐 github.com
3
February 13, 2020
how to clear opencv CV_CAP_PROP_BUFFERSIZE - Stack Overflow
always get delay frame after sleep while cv2.read, have any solution to clear the CV_CAP_PROP_BUFFERSIZE More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › opencv › opencv › issues › 23430
I can't set the buffersize in opencv · Issue #23430 · opencv/opencv
March 29, 2023 - # import the opencv library import cv2 import time # define a video capture object myrtmp_addr = "rtmp://172.20.10.5:1935/live" vid = cv2.VideoCapture(myrtmp_addr) succ = vid.set(cv2.CAP_PROP_BUFFERSIZE, 1) print(succ) print(vid.get(cv2.CAP_PROP_BUFFERSIZE)) while(True): if not vid.isOpened(): print("can't open the camera") continue ret, frame = vid.read() if ret is False: print("can't capture the frame") continue cv2.imshow('frame', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break vid.release() # Destroy all the windows cv2.destroyAllWindows()
🌐
OpenCV Q&A Forum
answers.opencv.org › question › 183162 › delay-in-frame-grabbing-with-opencv3-and-ubuntu-1604
Delay in frame grabbing with OpenCV3 and Ubuntu 16.04. - OpenCV Q&A Forum
OpenCV => 3.2 Operating System / Platform => Ubuntu 16.04 Python Detailed description · cap = cv2.VideoCapture(0) a=cap.get(cv2.CAP_PROP_BUFFERSIZE) # CV_CAP_PROP_BUFFERSIZE · print 'Buffersize', a · cap.set(cv2.CAP_PROP_BUFFERSIZE,1) a=cap.get(cv2.CAP_PROP_BUFFERSIZE) # CV_CAP_PROP_BUFFERSIZE ·
🌐
TechOverflow
techoverflow.net › 2022 › 11 › 01 › list-of-all-cv2-cap_prop_-properties-for-opencv-in-python
List of all cv2.CAP_PROP_... properties for OpenCV in Python | TechOverflow
October 31, 2022 - This list can be easily obtained using the following Python code: list_cap_props.py · Copy Download · for v in [k for k in cv2.__dict__.keys() if k.startswith("CAP_PROP")]: print(f"cv2.{v}") cap_props_list.py · Copy Download · cv2.CAP_PROP_APERTURE cv2.CAP_PROP_ARAVIS_AUTOTRIGGER cv2.CAP_PROP_AUTOFOCUS cv2.CAP_PROP_AUTO_EXPOSURE cv2.CAP_PROP_AUTO_WB cv2.CAP_PROP_BACKEND cv2.CAP_PROP_BACKLIGHT cv2.CAP_PROP_BITRATE cv2.CAP_PROP_BRIGHTNESS cv2.CAP_PROP_BUFFERSIZE cv2.CAP_PROP_CHANNEL cv2.CAP_PROP_CODEC_PIXEL_FORMAT cv2.CAP_PROP_CONTRAST cv2.CAP_PROP_CONVERT_RGB cv2.CAP_PROP_DC1394_MAX cv2.CAP
Top answer
1 of 6
49

OpenCV Solution

According to this source, you can set the buffersize of a cv::VideoCapture object.

cv::VideoCapture cap;
cap.set(CV_CAP_PROP_BUFFERSIZE, 3); // internal buffer will now store only 3 frames

// rest of your code...

There is an important limitation however:

CV_CAP_PROP_BUFFERSIZE Amount of frames stored in internal buffer memory (note: only supported by DC1394 v 2.x backend currently)

Update from comments. In newer versions of OpenCV (3.4+), the limitation seems to be gone and the code uses scoped enumerations:

cv::VideoCapture cap;
cap.set(cv::CAP_PROP_BUFFERSIZE, 3);

Hackaround 1

If the solution does not work, take a look at this post that explains how to hack around the issue.

In a nutshell: the time needed to query a frame is measured; if it is too low, it means the frame was read from the buffer and can be discarded. Continue querying frames until the time measured exceeds a certain limit. When this happens, the buffer was empty and the returned frame is up to date.

(The answer on the linked post shows: returning a frame from the buffer takes about 1/8th the time of returning an up to date frame. Your mileage may vary, of course!)


Hackaround 2

A different solution, inspired by this post, is to create a third thread that grabs frames continuously at high speed to keep the buffer empty. This thread should use the cv::VideoCapture.grab() to avoid overhead.

You could use a simple spin-lock to synchronize reading frames between the real worker thread and the third thread.

2 of 6
6

Guys this is pretty stupid and nasty solution, but accepted answer didn't helped me for some reasons. (Code in python but the essence pretty clear)

# vcap.set(cv2.CAP_PROP_BUFFERSIZE, 1)
data = np.zeros((1140, 2560))
image = plt.imshow(data)

while True:
    vcap = cv2.VideoCapture("rtsp://admin:@192.168.3.231")
    ret, frame = vcap.read()
    image.set_data(frame)
    plt.pause(0.5) # any other consuming operation
    vcap.release()
Top answer
1 of 3
21

Whether CAP_PROP_BUFFERSIZE is supported appears quite operating system and backend-specific. E.g., the 2.4 docs state it is "only supported by DC1394 [Firewire] v 2.x backend currently," and for backend V4L, according to the code, support was added only on 9 Mar 2018.

The easiest non-brittle way to disable the buffer is using a separate thread; for details, see my comments under Piotr Kurowski's answer. Here Python code that uses a separate thread to implement a bufferless VideoCapture: (I did not have a opencv4nodejs environment.)

import cv2, Queue, threading, time

# bufferless VideoCapture
class VideoCapture:

  def __init__(self, name):
    self.cap = cv2.VideoCapture(name)
    self.q = Queue.Queue()
    t = threading.Thread(target=self._reader)
    t.daemon = True
    t.start()

  # read frames as soon as they are available, keeping only most recent one
  def _reader(self):
    while True:
      ret, frame = self.cap.read()
      if not ret:
        break
      if not self.q.empty():
        try:
          self.q.get_nowait()   # discard previous (unprocessed) frame
        except Queue.Empty:
          pass
      self.q.put(frame)

  def read(self):
    return self.q.get()

cap = VideoCapture(0)
while True:
  frame = cap.read()
  time.sleep(.5)   # simulate long processing
  cv2.imshow("frame", frame)
  if chr(cv2.waitKey(1)&255) == 'q':
    break

The frame reader thread is encapsulated inside the custom VideoCapture class, and communication with the main thread is via a queue.

This answer suggests using cap.grab() in a reader thread, but the docs do not guarantee that grab() clears the buffer, so this may work in some cases but not in others.

2 of 3
2

I set cap value after reading each frame to None and my problem solved in this way:

import cv2
from PyQt5.QtCore import QThread

if __name__ == '__main__':
while True:
    cap = cv2.VideoCapture(0)
    ret, frame = cap.read()
    cv2.imshow('A', frame)
    cv2.waitKey(0)

    print('sleep!')
    QThread.sleep(5)
    print('wake up!')
    cap = None
🌐
RTSPLink
rtsplink.com › home › knowledge hub › troubleshooting › fixing python opencv rtsp buffer lag & frame accumulation
Fixing Python OpenCV RTSP Buffer Lag & Frame Accumulation | RTSPLink
August 15, 2026 - Python FixCopy · import os import ...st?token=demo", cv2.CAP_FFMPEG) cap.set(cv2.CAP_PROP_BUFFERSIZE, 1) Generate free authenticated RTSP links with unlimited bandwidth and inspect frame timestamps in seconds.Generate Free RTSP Link ·...
Find elsewhere
🌐
GitHub
github.com › statueofmike › rtsp › issues › 13
Can't Set CV_CAP_PROP_BUFFERSIZE · Issue #13 · dactylroot/rtsp
February 13, 2020 - Ideally we could follow cap.set(CV_CAP_PROP_BUFFERSIZE,1) and then always have the most recent frame available. Unfortunately, contrary to this suggestion, we don't appear to be able to set this property in Python: In : cap.set(cv2.CAP_PROP_BUFFERSIZE,1) Out: False ·
Author: dactylroot
🌐
Cloudinary
cloudinary.com › home › getting started with cv2 video capture in python
Getting Started with cv2 Video Capture in Python | Cloudinary
April 12, 2026 - Reduce Latency in Live Streams If using an IP camera or network stream, adjust the buffer size (cv2.CAP_PROP_BUFFERSIZE) to lower latency.
🌐
Stack Overflow
stackoverflow.com › questions › 54121253 › how-to-clear-opencv-cv-cap-prop-buffersize
how to clear opencv CV_CAP_PROP_BUFFERSIZE - Stack Overflow
always get delay frame after sleep while cv2.read, have any solution to clear the CV_CAP_PROP_BUFFERSIZE while 1: ret, frame = capture_list[i].read() print(' [%d] %s' % (i, ret)) print(
🌐
Unihiker
unihiker.com › wiki › LanguageReference › USBDevices › USB_Carema
USB Camera - UNIHIKER Documentation
cap = cv2.VideoCapture(0) # Set the camera buffer to 1, to decrease the latency. cap.set(cv2.CAP_PROP_BUFFERSIZE, 1) # Set the windows to be full screen. cv2.namedWindow('winname',cv2.WND_PROP_FULLSCREEN) # Set the windows to be full screen. cv2.setWindowProperty('winname',cv2.WND_PROP_FULLSCREEN, ...
🌐
CSDN
devpress.csdn.net › python › 6304568e7e6682346619a208.html
How to get the latest frame from capture device (camera) in opencv_python_Mangs-Python
August 23, 2022 - cap.set(cv2.CAP_PROP_BUFFERSIZE, 0) # python # opencv · 向您推荐>>百度飞桨AI Studio社区 · 学AI,认准AI Studio!GPU算力,限时免费领,邀请好友解锁更多惊喜福利 >>> 加入社区 · 更多推荐 · · 求助!为什么用InsCode部署会出现无限重定向? ·
🌐
OpenCV
forum.opencv.org › c++
CV_CAP_PROP_BUFFERSIZE when playing movie - C++ - OpenCV
February 10, 2022 - I’m sorry if my words are difficult to understand as this is my first post to such a professional form and I’m not a native speaker of English . I have three questions about CV_CAP_PROP_BUFFERSIZ. 1>Does X.set(CV_CAP_PROP_BUFFERSIZE,n) also work when X is a movie object, not captures from ...
🌐
Jancy Standard Library
vovkos.github.io › doxyrest-showcase › opencv › sphinx_rtd_theme › enum_cv_VideoCaptureProperties.html
enum cv::VideoCaptureProperties — OpenCV Documentation
#include <videoio.hpp> enum ... =32, CAP_PROP_PAN =33, CAP_PROP_TILT =34, CAP_PROP_ROLL =35, CAP_PROP_IRIS =36, CAP_PROP_SETTINGS =37, CAP_PROP_BUFFERSIZE =38, CAP_PROP_AUTOFOCUS =39, };...
🌐
Reddit
reddit.com › r/opencv › [question] how do i get a fresh frame taken after calling cv.videocapture.read ?
r/opencv on Reddit: [Question] How do I get a fresh frame taken AFTER calling cv.VideoCapture.read ?
August 14, 2021 -

I'm reading a frame from a usb webcam, but I need the frame to be guaranteed to be taken by the camera after I request it. Unfortunately, I get the last buffed frame. What I'm doing now is calling read twice, once to flush the buffer, and once to wait for and get another image. This works pretty well but seems to fail 2% of the time or so, and cuts my frame rate in half (under ideal circumstances it would be slower but not by that much if I'm thinking clearly). I just don't understand what it's actually doing. How do I make sure to get the next available frame that wasn't taken before I called cv.VideoCapture.read ?

Top answer
1 of 2
1
Do a search for CAP_PROP_BUFFERSIZE. You want to set this to 1. For example: https://stackoverflow.com/a/63057626/13022
2 of 2
1
There are two possibilities here: Reduce the frame buffer length to 1, so you can only ever have the latest frame (unfortunately not always obvious or even possible to do, and sometimes costs framerate (e.g. achieving it by only requesting stills when you need them isn’t always a viable solution if you want to stream and process video)) grab frames repeatedly in the background at faster than the video framerate and then only retrieve the latest frame when you need your next one If you’re using Python you can do option 2 with the Camera class of my library pythonic-cv , which uses a thread for grabbing frames and provides an iterator that retrieves just the latest frame when you need it/ask for it. If you’re not using python then you can set up your own thread for that, or if you know how long your processing tends to take you can potentially add grabs at multiple points throughout, which is likely easier to set up when starting out but harder to maintain as you change your processing or add extra functionality around it. Edit: as a note, a read in OpenCV is just a grab followed by a retrieve, which is often convenient if you need to view/process every frame that you get. It’s useful to split out the calls if you don’t need some of the frames (grab just says “I want a frame”, retrieve actually decides it into an array of pixels in memory), or if you’re doing things where the timing of when each image is taken needs to be precise relative to something else (e.g. for a stereo camera setup you want both images taken at exactly the same time, so don’t want to decode one before starting to take the next one)
🌐
OpenCV
docs.opencv.org › 4.13.0 › d4 › d15 › group__videoio__flags__base.html
OpenCV: Flags for video I/O
cv::VideoCapture API backends identifier · Select preferred API for a capture object. To be used in the VideoCapture::VideoCapture() constructor or VideoCapture::open()
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-get-properties-of-python-cv2-videocapture-object
How to get properties of Python cv2.VideoCapture object ? - GeeksforGeeks
July 23, 2025 - Let us see how we can get the properties from the cv2.VideoCapture objects and understand how they work. cv2.VideoCapture is a function of openCV library(used for computer vision, machine learning, and image processing) which allows working with video either by capturing via live webcam or by a video file. To know more about this function, refer to this link. Before we start, make sure to install the OpenCV library on Python 3.X.
🌐
GitHub
github.com › opencv › opencv › issues › 26250
Windows get camera cv2.CAP_PROP_FPS incorrect value for low fps. · Issue #26250 · opencv/opencv
October 4, 2024 - Self built Opencv 4.10 for windows with python. OpenCV for Windows reports incorrect FPS if Camera was read before and low FPS was set. from datetime import datetime,timedelta import cv2 cap = cv2.VideoCapture(0) cap.grab() # Remove this line to get correct real FPS cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640) cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480) cap.set(cv2.CAP_PROP_BUFFERSIZE, 1) cap.set(cv2.CAP_PROP_FPS, 2) # Set low FPS print("Real fps: ", cap.get(cv2.CAP_PROP_FPS)) for i in range(100): cv2.waitKey(1) cap.grab() # Grab a frame now = datetime.now() print(f'{now.strftime("%M:%S")} ') Typical output: Click to expand ·