{"id":15043525,"url":"https://github.com/tiagoprata/fastapi-frame-stream","last_synced_at":"2025-04-14T21:13:52.994Z","repository":{"id":39713385,"uuid":"507108870","full_name":"TiagoPrata/fastapi-frame-stream","owner":"TiagoPrata","description":"Python package to easily stream individual frames (MJPEG) using FastAPI","archived":false,"fork":false,"pushed_at":"2022-07-07T22:16:09.000Z","size":8368,"stargazers_count":12,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-14T21:13:45.447Z","etag":null,"topics":["fastapi","mjpeg","mjpeg-stream","opencv","python","video-streaming"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/fastapi-frame-stream/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TiagoPrata.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-24T18:31:23.000Z","updated_at":"2024-09-13T16:56:05.000Z","dependencies_parsed_at":"2022-09-20T08:31:25.040Z","dependency_job_id":null,"html_url":"https://github.com/TiagoPrata/fastapi-frame-stream","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TiagoPrata%2Ffastapi-frame-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TiagoPrata%2Ffastapi-frame-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TiagoPrata%2Ffastapi-frame-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TiagoPrata%2Ffastapi-frame-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TiagoPrata","download_url":"https://codeload.github.com/TiagoPrata/fastapi-frame-stream/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248961237,"owners_count":21189993,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastapi","mjpeg","mjpeg-stream","opencv","python","video-streaming"],"created_at":"2024-09-24T20:49:13.342Z","updated_at":"2025-04-14T21:13:52.971Z","avatar_url":"https://github.com/TiagoPrata.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastapi-frame-stream\n\nPackage to easily stream individual frames (MJPEG) using FastAPI.\n\nFastAPI server for publishing and viewing MJPEG streams.\n\nRaw image files and images as base64 strings can be sent to a 'video stream' and then consumed by any client.\n\n## Quick start\n\n### Installing\n\n```cmd\npip install fastapi-frame-stream\n```\n\n#### Requirements\n\n- [FastAPI](https://fastapi.tiangolo.com/)\n- [uvicorn](https://www.uvicorn.org/)\n\n\u003cdetails\u003e\n  \u003csummary\u003e\u003ci\u003eNOTE:\u003c/i\u003e\u003c/summary\u003e\n  This package will also automatically install:\n\n- imutils\n- opencv-python\n- python-miltipart\n\n\u003c/details\u003e\n\n### How to use\n\n#### Server\n\nYou can create a simple FastAPI server where it is possible to publish and get multiple streams.\n\n![usage code](./_readme_imgs/usage_code.svg)\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ci\u003efull code\u003c/i\u003e\u003c/summary\u003e\n\n```python\nfrom fastapi import FastAPI, File, UploadFile\nimport uvicorn\nfrom pydantic import BaseModel\nfrom fastapi_frame_stream import FrameStreamer\n\napp = FastAPI()\nfs = FrameStreamer()\n\nclass InputImg(BaseModel):\n    img_base64str : str\n\n\n@app.post(\"/send_frame_from_string/{stream_id}\")\nasync def send_frame_from_string(stream_id: str, d:InputImg):\n    await fs.send_frame(stream_id, d.img_base64str)\n\n\n@app.post(\"/send_frame_from_file/{stream_id}\")\nasync def send_frame_from_file(stream_id: str, file: UploadFile = File(...)):\n    await fs.send_frame(stream_id, file)\n\n\n@app.get(\"/video_feed/{stream_id}\")\nasync def video_feed(stream_id: str):\n    return fs.get_stream(stream_id)\n\n\nif __name__ == '__main__':\n    uvicorn.run(app, host=\"0.0.0.0\", port=5000)\n```\n\n\u003c/details\u003e\n\n#### Client\n\nAny client can view a published image (MJPEG) stream using a simple ```\u003cimg\u003e``` tag:\n\n![usage code](./_readme_imgs/client_code.svg)\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ci\u003efull code\u003c/i\u003e\u003c/summary\u003e\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003ctitle\u003eTesting fastapi-frame-stream\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003cimg src=\"http://localhost:5000/video_feed/my_new_stream001\"\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n\u003c/details\u003e\n\n#### All together\n\nIt is possible to upload an image file directly...\n\n![Server and client](https://raw.githubusercontent.com/TiagoPrata/fastapi-frame-stream/main/_readme_imgs/usage001.gif)\n\n... or to use any kind of application to convert the frames to base64 and send it to the web server:\n\n![Server and client](https://raw.githubusercontent.com/TiagoPrata/fastapi-frame-stream/main/_readme_imgs/usage002.gif)\n\n\u003ch4\u003e\u003ci\u003eHow it works\u003c/i\u003e\u003c/h4\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003c/summary\u003e\n\nThe frames sent throught the web server are stored in a temporary (in memory) SQLite DB...\n\n![User sending frame](./_readme_imgs/sending_frame.png)\n\n... and the last frame of each stream is retrieved everytime a client wants to visualize the stream.\n\n![Retrieving stream](./_readme_imgs/getting_stream.png)\n\n\u003c/details\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiagoprata%2Ffastapi-frame-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftiagoprata%2Ffastapi-frame-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiagoprata%2Ffastapi-frame-stream/lists"}