I'm new to web development and have been trying to solve a problem for some time but no luck. I'm using React and Django
The thing is, there is a 3rd party application that performs some image processing using opencv on video frames and I've to display those encoded frames on the web browser.
I want to receive those frames using Django API, decode them, and display them using React JS, also returning a response with every frame to that 3rd party app.
I've prepared a flowchart of how things should work but haven't been able to start at all.
Flowchart:

The outcome on the browser should appear something like this.
Outcome:

Need to know how to approach this, shall I use WebSockets or can I send the encoded frames directly to React taking Django out of the picture.
cv2.imencode('.jpg', frame) encoded format along with some other data in a JSON packet.You seem to be dealing with a video stream in MJPEG format (Motion JPEG). It is a sequence of JPEG frames without any inter-frame compression.
You typically can capture the MJPEG stream from the frontend. But if the third-party accesses the IP camera directly without caching layer, you might effectively DDOS it with very little traffic. I managed to slow down my localhost webcam MJPEG server by just using a handful of receivers.
Also, you directly expose your third-party source to your users. And the third party can monitor your users.
Passing the stream through your own backend is more costly on resources. You make minimum requests per frame to the third-party server but have to serve the stream to all your clients.
If your frontend is going to be used by you only, go for the backend-free solution. If you have enough resources for the backend, you expect more clients, and you don't want to expose your clients to the third party, serve the MJPEG in the backend.
As for technical part, there are plenty out-of-the-box solutions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With