Read Frames from RTSP Stream in Python

前端 未结 6 460
旧巷少年郎
旧巷少年郎 2020-12-13 16:12

I have recently set up a Raspberry Pi camera and am streaming the frames over RTSP. While it may not be completely necessary, here is the command I am using the broadcast th

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 16:40

    Hi reading frames from video can be achieved using python and OpenCV . Below is the sample code. Works fine with python and opencv2 version.

    import cv2
    import os
    #Below code will capture the video frames and will sve it a folder (in current working directory)
    
    dirname = 'myfolder'
    #video path
    cap = cv2.VideoCapture("TestVideo.mp4")
    count = 0
    while(cap.isOpened()):
        ret, frame = cap.read()
        if not ret:
            break
        else:
            cv2.imshow('frame', frame)
            #The received "frame" will be saved. Or you can manipulate "frame" as per your needs.
            name = "rec_frame"+str(count)+".jpg"
            cv2.imwrite(os.path.join(dirname,name), frame)
            count += 1
        if cv2.waitKey(20) & 0xFF == ord('q'):
            break
    cap.release()
    cv2.destroyAllWindows()
    

提交回复
热议问题