https://github.com/lddl/mjpeg-rs
Example of simple MJPEG server in Rust
https://github.com/lddl/mjpeg-rs
actix-web mjpeg mjpeg-stream opencv opencv-rust rtsp rust video-streaming
Last synced: about 2 months ago
JSON representation
Example of simple MJPEG server in Rust
- Host: GitHub
- URL: https://github.com/lddl/mjpeg-rs
- Owner: LdDl
- Created: 2022-08-18T19:24:37.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-08-18T20:36:34.000Z (almost 3 years ago)
- Last Synced: 2025-03-27T15:04:18.366Z (2 months ago)
- Topics: actix-web, mjpeg, mjpeg-stream, opencv, opencv-rust, rtsp, rust, video-streaming
- Language: Rust
- Homepage:
- Size: 18.4 MB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MJPEG server in Rust
## Table of Contents
- [About](#about)
- [Usage](#usage)
- [Credits](#credits)## About
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](https://crates.io/crates/image) crate for encoding purposes. Is slows down MJPEG streaming for me drastically. I use [imencode](./src/main.rs#L59) instead.
* Separated thread for MJPEG streaming (proof of concept)
* Bump to latest [actix-web](https://actix.rs/) web framework## Usage
Just modify Rust code in [main](src/main.rs) file to adjust your needs:
```rust
// ...
// 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).
## Credits
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://opencv.org/)
* https://rtsp.stream/ for RTSP stream example
* Rust community and not mentioned authors of other dependencies