Anoop Maurya
Anoop Maurya

Reputation: 1

How to record video rtsp and save video for 5 minutes using python and opencv

How to record video rtsp and save video for 5 minutes using python and opencv

i m using to record some of the code but for 5 minutes using clas and function video is very tuff to download for 5 minutes.

Upvotes: -2

Views: 2790

Answers (1)

David Moruzzi
David Moruzzi

Reputation: 130

You will need to import cv2. You may need to execute pip install opencv-python to install the module for importation.

import cv2
import time

# open video stream
cap = cv2.VideoCapture('rtsp://127.0.0.1/stream')

# set video resolution
cap.set(3, 640)
cap.set(4, 480)

# set video codec
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640, 480))

# start timer
start_time = time.time()

while (int(time.time() - start_time) < 300):
    ret, frame = cap.read()
    if ret == True:
        out.write(frame)
        cv2.imshow('frame', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

# release resources
cap.release()
out.release()
cv2.destroyAllWindows()

Upvotes: 0

Related Questions