Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

an ip stream has no "end". and you can't "seek" anything there. itdoes not know the future and does not remember the past.

but vcap.read() is actually a combination of grab() and retrieve() . so you should:

  • grab() as often as you can. after say, 5 frames you have reached the latest img, probably.
  • retrieve() and process the img only, when desired (e.g. if you're sure, you have the latest)


vcap = cv2.VideoCapture("rtsp://{IPcam}/12")
ct = 0
while(1):
    ct += 1
    ret = vcap.grab()
    if ct % 5 == 0: # skip some frames
        ret, frame = vcap.retrieve()
        if not ret: break
        time.sleep(0.2)              # <= Simulate processing time
        cv2.imshow('VIDEO', frame)
    if cv2.waitKey(1) == 27:
        break