Make a WebSocket Stream
Nvision with Streaming Videos
Last updated
Nvision with Streaming Videos
Last updated
WebSocket stream is another way to submit images to the Nvision service. To use the WebSocket stream, the easiest way is to use our provided SDK, see JavaScript SDK.
Consider using the WebSocket stream if you need to continuously submit images (i.e., frames of the video stream).
To use Nvision with streaming videos, your application needs to implement the following:
Stream video frames to Nvision service: Develop websocket stream using SDK.
Get results from the WebSocket via WebHook: Create a webhook url to receive HTTP callback.
Set up callback endpoints: in the Nvision service page.
In this quickstart, we present an end-to-end use case of how to stream video frames from edge services and set up your backend service to receive the results.
Some application need to be run as a Headless agent on edge compute. For example, you develop a headless agent running on a RaspberryPi to read video frames from CCTV and submit them to the Nvision service as the following diagram.
Initialize your NPM project, then install @nipacloud/nvision
and opencv4nodejs
using npm
or yarn
command.
To get results, you need to configure a Webhook endpoint to your service. Webhook is a user-defined HTTP callback endpoint.
Headless Agent
For testing webhook integration, we use ngrok to create a secure tunnel on local machine along with public URLs for exposing local web server.
By running this command ngrok http 3000
, you will get public URLs as follows:
As the socket protocol is used, we provide a custom callback endpoint configuration that allows you to have independent backends for receiving and analyzing prediction results.
WebSocket Streaming Callback URL
Now, input your exposed URL to the WebSocket streaming callback URL in service's setting.
Lastly, when the image is processed, the Nvision service will make a HTTP request to the specified endpoint with the prediction results structured as follow.
Method: POST
Body: The request body will be provided as
Output Logs from Streaming agent (left) and Webhook callback (right)