This repository contains a FastAPI-based server for efficient image fetching, validation, and streaming in both static image format and MJPEG streams.
- Image Streaming: Serve static images and MJPEG streams.
- Asynchronous Fetching: Efficient image fetching with configurable FPS rates.
- Validation: Validate and convert images to ensure compatibility.
- Logging: Custom logging configuration for detailed debugging.
- Health Check: Endpoints to monitor the health and status of image streams.
- Python 3.9+
pip
package manager
-
Clone this repository:
git clone https://github.com/markfrancisonly/mjpeg-server.git cd fastapi-image-server
-
Install the required dependencies:
pip install -r requirements.txt
-
Create a
config.yaml
file for server and image configurations. -
Start the server:
python main.py
-
Access endpoints:
- Static image:
/images/{image_id}
- MJPEG stream:
/images/{image_id}/stream
- List all images:
/images
- Health check:
/health
- Static image:
The server uses a config.yaml
file for defining the following:
- Server settings (e.g., timeout, FPS limits).
- Image-specific settings (e.g., URLs, validation methods).
Refer to the provided config.example.yaml
for structure and examples.
Retrieve the latest frame for an image ID:
GET /images/{image_id}
Stream the latest frames in MJPEG format:
GET /images/{image_id}/stream
Get a summary of all configured images:
GET /images
Check the server's status:
GET /health
For production deployment, use a robust ASGI server such as uvicorn
with multiple workers.
uvicorn main:app --host 0.0.0.0 --port 8080 --workers 4
This code needs to be modularized bfore contributions would be meaningful.