This is a nasty little issue with certain ip cameras. It's especially prominent with ubiquiti cameras. The method I use to deal with it is to have a separate thread (use multiprocess for python) pulling frames faster than the camera framerate and pushing it in to a circular buffer. Then whenever you need a new frame, you pull from the buffer head, not the camera.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…