0

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()
Yunus Temurlenk
  • 4,085
  • 4
  • 18
  • 39
Goku
  • 23
  • 7
  • Have you looked at moviepy docs? – itprorh66 Apr 21 '21 at 20:09
  • @itprorh66, yes but couldn't understand how to achieve the desired functionality. – Goku Apr 21 '21 at 20:22
  • I don't think it is possible with `moviepy`, the main reason being that `moviepy` is meant to process a video, see also why not to use `moviepy` in the section [do I need moviepy?](https://zulko.github.io/moviepy/getting_started/quick_presentation.html#do-i-need-moviepy). Stating not to use it when `to turn a series of image files into a movie.` (which a stream basically is). I think the approach you have with `opencv` is much more efficient in handling the recording. – Thymen Apr 23 '21 at 09:26

0 Answers0