I have the following setup:
A node server that is receiving a video stream from a client. The clients can view the video stream through a WebSocket at ws://1.2.3.4:8888.
Now, I would like to use OpenCV (Python) in order to capture frames from that stream. I tried using cap = cv2.VideoCapture('ws://1.2.3.4:8888/') and it does not work. Gives me an error (note: the socket works; I tried displaying the stream on a canvas).
My question is, is there any way for me to read (in Python) frame-by-frame the stream that is available through WebSocket? Preferably using OpenCV Python?
I have tried many things, but none work.
Below is the code which gets me connected to the stream but how can I capture an image from that stream.
Thank you for your help in advance!
import asyncio
import pathlib
import ssl
import websockets
# ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
# # localhost_pem = pathlib.Path(__file__).with_name("localhost.pem")
# ssl_context.load_verify_locations(localhost_pem)
async def hello():
uri = "ws://192.168.0.102:8080"
async with websockets.connect(uri) as websocket:
print('hello')
asyncio.get_event_loop().run_until_complete(hello())