2

I'm using VLC media player to stream .mp4 video using http. Streaming works fine (i was able to attach to this stream using another instance of VLC). Now I want to connect to this stream using OpenCV with python 2.7 and get video frame by frame.

This is modified tutorial code (which works perfectly fine with local file):

<code>
import numpy as np
import cv2    
address = '10.0.0.71' # this is my stream ip address
port = 8080 # this is stream port

# should I use socket somehow?
# found this somewhere, no idea what this do
# import socket
# msocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) 
# msocket.connect((address, port))

cap = cv2.VideoCapture('file.mp4') # how to use VideoCapture with online stream?     

# just showing video to screen
while(cap.isOpened()):
    ret, frame = cap.read()
    cv2.imshow('frame', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

Please help.

msw
  • 95
  • 1
  • 6

2 Answers2

3

http://answers.opencv.org/question/24154/how-to-using-opencv-api-get-web-video-stream/

You should be able to just cap = cv2.VideoCapture('yourStreamURIHere')

If you need to login to the stream, for example some stream at 127.0.0.1 with username: hello, password: goodbye:

cap = cv2.VideoCapture('http://hello:goodbye@127.0.0.1/?action=stream?otherparamshere)
kev
  • 46
  • 2
0

I'm kind of late but I've created powerful & threaded VidGear Video Processing python library that now provides NetGear API, which is exclusively designed to transfer video frames synchronously between interconnecting systems over the network in real-time through ZmQ messaging system. For usage example, check my detailed answer here: https://stackoverflow.com/a/57205019/10158117

abhiTronix
  • 1,248
  • 13
  • 17