fastapi-frame-stream
Package to easily stream individual frames (MJPEG) using FastAPI.
FastAPI server for publishing and viewing MJPEG streams.
Raw image files and images as base64 strings can be sent to a 'video stream' and then consumed by any client.
Quick start
Installing
pip install fastapi-frame-stream
Requirements
NOTE:
This package will also automatically install:- imutils
- opencv-python
- python-miltipart
How to use
Server
You can create a simple FastAPI server where it is possible to publish and get multiple streams.
full code
from fastapi import FastAPI, File, UploadFile
import uvicorn
from pydantic import BaseModel
from fastapi_frame_stream import FrameStreamer
app = FastAPI()
fs = FrameStreamer()
class InputImg(BaseModel):
img_base64str : str
@app.post("/send_frame_from_string/{stream_id}")
async def send_frame_from_string(stream_id: str, d:InputImg):
await fs.send_frame(stream_id, d.img_base64str)
@app.post("/send_frame_from_file/{stream_id}")
async def send_frame_from_file(stream_id: str, file: UploadFile = File(...)):
await fs.send_frame(stream_id, file)
@app.get("/video_feed/{stream_id}")
async def video_feed(stream_id: str):
return fs.get_stream(stream_id)
if __name__ == '__main__':
uvicorn.run(app, host="0.0.0.0", port=5000)
Client
Any client can view a published image (MJPEG) stream using a simple <img> tag:
full code
<!DOCTYPE html>
<html lang="en">
<head>
<title>Testing fastapi-frame-stream</title>
</head>
<body>
<img src="http://localhost:5000/video_feed/my_new_stream001">
</body>
</html>
All together
It is possible to upload an image file directly...
... or to use any kind of application to convert the frames to base64 and send it to the web server:
How it works
The frames sent throught the web server are stored in a temporary (in memory) SQLite DB...
... and the last frame of each stream is retrieved everytime a client wants to visualize the stream.
Metadata
Release files for fastapi-frame-stream 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi_frame_stream-0.1.1.tar.gz | 5.3 kB | Without provenance | Details for fastapi_frame_stream-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_frame_stream-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for fastapi_frame_stream-0.1.1-py3-none-any.whl |
Total release size: 11.0 kB
Release files / fastapi_frame_stream-0.1.1.tar.gz
| Download URL | fastapi_frame_stream-0.1.1.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
05aaae2405cce97b135948e50ce3ec77fd9afce8b6c5b9cdb26bc83e46f6045e
|
|
BLAKE2b-256 checksum How to use checksums |
4736b0e9ef4c0cf2f955e08c29c4d4593177817febda0e1de998bc9c4fd35211
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.5
|
Release files / fastapi_frame_stream-0.1.1-py3-none-any.whl
| Download URL | fastapi_frame_stream-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
98fcc207b8b4c360519dc8d17419f19624d345709c36ca0c501b79c8e179b053
|
|
BLAKE2b-256 checksum How to use checksums |
1157cada76bf1a47a0481a9b8baa4cc0aa3efd47e7530c140e0efd30a4518a45
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.5
|
Security for fastapi-frame-stream 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.