fastapi-frame-stream-0.1.1
توضیحات
Package to easily stream individual frames (MJPEG) using FastAPI
| ویژگی | مقدار |
|---|---|
| سیستم عامل | OS Independent |
| نام فایل | fastapi-frame-stream-0.1.1 |
| نام | fastapi-frame-stream |
| نسخه کتابخانه | 0.1.1 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Tiago Prata |
| ایمیل نویسنده | prataaa@hotmail.com |
| آدرس صفحه اصلی | https://github.com/TiagoPrata/fastapi-frame-stream |
| آدرس اینترنتی | https://pypi.org/project/fastapi-frame-stream/ |
| مجوز | - |
# 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
```cmd
pip install fastapi-frame-stream
```
#### Requirements
- [FastAPI](https://fastapi.tiangolo.com/)
- [uvicorn](https://www.uvicorn.org/)
<details>
<summary><i>NOTE:</i></summary>
This package will also automatically install:
- imutils
- opencv-python
- python-miltipart
</details>
### How to use
#### Server
You can create a simple FastAPI server where it is possible to publish and get multiple streams.

<details>
<summary><i>full code</i></summary>
```python
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)
```
</details>
#### Client
Any client can view a published image (MJPEG) stream using a simple ```<img>``` tag:

<details>
<summary><i>full code</i></summary>
```html
<!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>
```
</details>
#### 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:

<h4><i>How it works</i></h4>
<details>
<summary></summary>
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.

</details>
نیازمندی
| مقدار | نام |
|---|---|
| - | imutils |
| - | opencv-python |
| - | python-multipart |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.7 | Python |
نحوه نصب
نصب پکیج whl fastapi-frame-stream-0.1.1:
pip install fastapi-frame-stream-0.1.1.whl
نصب پکیج tar.gz fastapi-frame-stream-0.1.1:
pip install fastapi-frame-stream-0.1.1.tar.gz