I need to serve real-time graphs and I would like to deliver a mjpeg stream over http (so that it is easy to include the graphs in a web-page by using a plain tag).
Is it possible to create an mjpeg stream from multiple jpeg images, in realtime ?
My strategy is:
Output the correct http headers:
Cache-Control:no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0 Connection:close Content-Type:multipart/x-mixed-replace;boundary=boundarydonotcross Expires:Mon, 3 Jan 2000 12:34:56 GMT Pragma:no-cache Server:MJPG-Streamer/0.2
(got it from a
curl -I {on a mjpeg-streamer instance}
, but this seems strange)Simply yield the successive jpeg images binaries, taking care to:
prepend the correct headers at the beginning of the stream (as mjpeg-streamer does):
Content-Type: image/jpeg Content-Length: 5427 X-Timestamp: 3927662.086099
append the boundary string at the end of each jpeg streams.
--boudary--
Questions:
Have you done that,
do you know a python module that does that,
do you think it would work,
have you got any advice ?
You may use Flask framework to do this.
It is not only for mjpeg.
I adapted some code from here: https://blog.miguelgrinberg.com/post/video-streaming-with-flask
APP.py
base_camera.py
camera.py
I got it working as a proof-of-concept: https://github.com/damiencorpataux/pymjpeg
For memory: