[Python] Capture images from RTSP stream

Discussão em 'Python' iniciado por Stack, Outubro 6, 2024.

  1. Stack

    Stack Membro Participativo

    I want to extract frames from an RTSP camera stream stored with timestamp and date every minute, for 24 hours. How do I go about this? My code:

    imagesFolder = "C:/Users/<user>/documents"
    cap = cv2.VideoCapture("rtsp://username:password@cameraIP/axis-media/media.amp")
    frameRate = cap.get(5) #frame rate
    count = 0

    while cap.isOpened():
    frameId = cap.get(1) # current frame number
    ret, frame = cap.read()

    if (ret != True):
    break
    if (frameId % math.floor(frameRate) == 0):
    filename = imagesFolder + "/image_" + str(datetime.now().strftime("%d-%m-%Y_%I-%M-%S_%p")) + ".jpg"
    cv2.imwrite(filename, frame)

    cap.release()
    print ("Done!")

    cv2.destroyAllWindows()

    Continue reading...

Compartilhe esta Página