VLC Get Frame For OpenCV

asked 2019-09-26 07:46:59 -0500

Hi there,

I am using libVLC with python in my Raspberry Pi 3 B and getting RTSP stream. I also want to process every frame in stream then save processed frames as video file. I worked with OpenCV before. So I know how to process frames and how to save as video file. Bu I don't know how to get frames from VLC for process.

 rtsp_server = 'rtsp://[IP_OF_CAMERA]/...'
i = vlc.Instance("--vout=dummy --sout-mux-caching=<>")
player = i.media_player_new()
player = vlc.MediaPlayer(rtsp_server)

This is how I am getting stream from RTSP. I found something like my problem in bottom of https://stackoverflow.com/questions/5... 96151 page. But I can't understand how to do that. For now, I save frames with "take snapshot" and I read them with OpenCV then try to save as video.

while True:
    player.video_take_snapshot(0, '/home/pi/Desktop/snapshot1.png', 0, 0)
    frame = cv2.imread('/home/pi/Desktop/snapshot1.png', 0)
    if frame is None:
        print("NO FRAME")

    cv2.imshow('Camera1', frame)

    if (cv2.waitKey(10) & 0xFF) == 27: #esc key ends process

That is rest of my code. In this case, I got almost 10 second delay in stream. I tried to get RTSP stream with OpenCV but I couldn't. I tried to get frames from VLC with callbacks or functions but I couldn't that either. Do you know anything how to get frame for OpenCV? Or have any idea?


edit retag flag offensive close merge delete


What happen if you rem it out both cap.release()? And put cap.release() at bottom to cv2.destroyAllWindows()

supra56 gravatar imagesupra56 ( 2019-09-26 12:12:32 -0500 )edit