Just a template code for serving MJPEG stream via OpenCV.
Yes, this repo code is stolen (highly inspired if you want to) from https://github.com/dskkato/mjpeg-rs and in https://github.com/t924417424/mjpeg_rs.
What the purpose then? Well, I've change a couple of things:
- Eliminate use of image crate for encoding purposes. Is slows down MJPEG streaming for me drastically. I use imencode instead.
- Separated thread for MJPEG streaming (proof of concept)
- Bump to latest actix-web web framework
Just modify Rust code in main file to adjust your needs:
// ...
// Path to video (could be rtsp or local video file)
let video_src_path = "rtsp://rtsp.stream/pattern".to_string();
// let video_src_path = "./data/sample_960_540.mp4".to_string();
// ...
// ...
// Change host and port for live streaming if needed
start_mjpeg_streaming("localhost".to_string(), 8090, rx_mjpeg, first_frame_cols, first_frame_rows) {
// ...
Start:
cargo run
Open http://localhost:8090/live in browser and enjoy
There would be opened imshow() object also (don't close it accidenlty since main thread will be terminated).
Thanks to:
- https://github.com/t924417424/mjpeg_rs for inspiring
- https://github.com/dskkato/mjpeg-rs for actix-web based version
- https://actix.rs/ for great Web-framework
- https://github.com/twistedfall/opencv-rust for binding to OpenCV
- https://rtsp.stream/ for RTSP stream example
- Rust community and not mentioned authors of other dependencies