0

I want to find a subsitution for cv2.VideoCapture for reading RTSP h264 steam. Seems libvlc is more stable than opencv when decoding h264.

I use such codes:

Instance = vlc.Instance()
player = Instance.media_player_new('--no-xlib')
Media = Instance.media_new('rtsp://admin:abcd1234@192.168.0.207:554')
Media.get_mrl()
player.set_media(Media)
player.play()
time.sleep(1)
player.video_take_snapshot(num=0, psz_filepath='a.png', i_width=1920, i_height=1080)

these can save a frame to file. But it's too slow. I just want to read the frame ndarray in memory ,and do not show the player window. Just like

cap = cv2.VideoCapture(uri) 
cap.read()

How can I do.Thank you

locys
  • 31
  • 1
  • 4
  • cv2.VideoCapture can use ffmpeg or gstreamer under the hood depending on how it was compiled. You can pass it a gstreamer pipeline to make sure it reads your rtsp stream with gstreamer. I'm curious what problems you are running into with cv2.VideoCapture. Rather than using vlc, you could try using ffmpeg or gstreamer as an alternative. – shortcipher3 May 20 '20 at 11:57
  • You might also be interested in reading this: https://stackoverflow.com/questions/11525769/how-do-vlc-and-ffmpeg-work-together – shortcipher3 May 20 '20 at 11:58
  • Actually If I use cv2.VideoCapture read many rtsp channels use threading in one process, Some channel is often stunned, Most importantly program will exit soon with an -xxxx exit code which can not be try...except. I doubt there something wrong within opencv? – locys May 21 '20 at 02:52
  • Did you try using libav? – shortcipher3 May 21 '20 at 20:52

0 Answers0