This project is a FastAPI application that streams video frames over a WebSocket connection. The frames are captured from a video file and sent to connected clients in real-time.
The project consists of the following files:
computer_vision_example/
├── app.py
├── index.html
├── utils/
│ └── logger.py
├── routes/
│ └── video.py
├── services/
│ └── video_service.py
└── tests/
├── init.py
├── test_video_service.py
└── test_websocket.pysequenceDiagram
participant Browser
participant HTML
participant FastAPI
participant VideoService
Browser->>HTML: Open index.html
HTML->>Browser: Render page with WebSocket client
Browser->>FastAPI: WebSocket connection to /ws_video
FastAPI->>VideoService: Call process_video()
VideoService->>FastAPI: Stream video frames
FastAPI->>Browser: Send video frame
loop While WebSocket is open
Browser->>FastAPI: WebSocket connection open
FastAPI->>VideoService: Read next frame
VideoService->>FastAPI: Stream video frame
FastAPI->>Browser: Send video frame
end
Browser->>FastAPI: WebSocket connection closed
FastAPI->>VideoService: Stop streaming
Make sure you have Python installed. Then, install the required packages using pip:
python -m pip install --upgrade pip
python.exe -m pip install -r requirements.txtStart the FastAPI application using Uvicorn:
cd computer_vision_example/
uvicorn app:app --workers 4 --reload
python -m http.server 8001The application will be available at http://localhost:8000.
Run the tests using the following command:
pytest tests/- Open the application in a web browser at
http://localhost:8000. - Click the
Startbutton to start the video stream. - Click the
Stopbutton to stop the video stream. - Click the
Clearbutton to clear the video stream. - Click the
Downloadbutton to download the video stream as a file. - Click the
Savebutton to save the video stream as a file. - Click the
Loadbutton to load a video file. - Click the
Uploadbutton to upload a video file. - Click the
Playbutton to play the video stream. - Click the
Pausebutton to pause the video stream. - Click the
Seekbutton to seek to a specific frame in the video stream. - Click the
Forwardbutton to move forward in the video stream. - Click the
Backwardbutton to move backward in the video stream. - Click the
Speedbutton to change the speed of the video stream. - Click the
Volumebutton to change the volume of the video stream. - Click the
Mutebutton to mute the video stream. - Click the
Unmutebutton to unmute the video stream. - Click the
Fullscreenbutton to enter fullscreen mode. - Click the
Exit Fullscreenbutton to exit fullscreen mode. - Click the
Settingsbutton to change the video stream settings. - Click the
Aboutbutton to view information about the video stream. - Click the
Helpbutton to view help information about the video stream. - Click the
Closebutton to close the video stream. - Click the
Exitbutton to exit the video stream. - Click the
Refreshbutton to refresh the video stream. - Click the
Reloadbutton to reload the video stream. - Click the
Resetbutton to reset the video stream. - Click the
Clear Cachebutton to clear the video stream cache. - Click the
Clear Cookiesbutton to clear the video stream cookies. - Click the
Clear Storagebutton to clear the video stream storage. - Click the
Clear Historybutton to clear the video stream history. - Click the
Clear Databutton to clear the video stream data. - Click the
Clear Allbutton to clear all video stream data.
This project is licensed under the MIT License - see the LICENSE file for details.