I'm trying to build an application where I need to show live camera streams to a user, as well as record those streams. I need to do it for multiple cameras (currently I'm starting with one only).
I'm able to achieve this requirement using opencv
library, but I've been told by senior to use opencv
only for live camera stream and use moviepy
to record them. Now, I don't know how to how to handle the latter.
I looked for answers on google and stack overflow, but didn't find any. Please help if you know how to record using moviepy
.
Below is the code using opencv
:
import numpy as np
import cv2
cap = cv2.VideoCapture("rtsp://admin:vaaan@123@192.168.1.51/Streaming/Channels/2")
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640, 480))
while(True):
ret, frame = cap.read()
# output the frame
out.write(frame)
cv2.imshow('Original', frame)
if cv2.waitKey(1) & 0xFF == ord('a'):
break
cap.release()
out.release()
cv2.destroyAllWindows()