A FastAPI-based AI video processing API that detects people in a video using YOLOv11 + ByteTrack tracking and generates a dynamic movement heatmap overlay on the video.
This project is designed to run easily in Google Colab and be exposed publicly using ngrok for testing.
- Crowd analysis
- Store analytics
- Smart surveillance
- Movement pattern analysis
- Person detection using YOLO
- Multi-object tracking using ByteTrack
- Dynamic movement heatmap generation
- Video processing API with FastAPI
- Background video processing
- Download processed video
- Public API access using ngrok
- Interactive API testing using Swagger UI
- Python
- FastAPI
- YOLO (Ultralytics)
- ByteTrack
- OpenCV
- PyTorch
- Google Colab
- ngrok
This project is designed to run easily in Google Colab.
Upload the provided notebook to Google Colab.
Or create a new notebook and paste the project code.
Run the setup cells that install all required libraries.
pip install ultralytics
pip install fastapi uvicorn pyngrokInstall ByteTrack dependencies as well.
Start the API server using uvicorn.
uvicorn app:app --host 0.0.0.0 --port 8000This will start the API server inside Colab.
To expose the API publicly you need ngrok.
Create a free account:
After signup:
- Copy your Auth Token
- Go to Google Colab Secrets
- Store the token using the name:
NGROK_TOKENRun the following code inside Colab:
from pyngrok import ngrok
from google.colab import userdata
token = userdata.get('NGROK_TOKEN')
ngrok.set_auth_token(token)
public_url = ngrok.connect(8000)
print("Public URL:", public_url)This will generate a public URL like:
https://abcd-1234.ngrok-free.app
FastAPI automatically generates API documentation.
Open the following URL in your browser:
https://your-ngrok-url/docs
Example:
https://abcd-1234.ngrok-free.app/docs
This will open the Swagger UI interface where you can test the API.
Inside Swagger UI:
Find the endpoint:
POST /processvideo
Click Try it out
Upload your video file and press Execute.
The API will return a response like:
{
"output_file": "outputs/processed_video.mp4",
"status": "Processing started in background"
}The video will now start processing.
Once processing finishes you can download the output video.
Use the endpoint:
GET /download/{filename}
Example:
/download/processed_video.mp4
Important note:
Swagger sometimes cannot properly download video responses.
Therefore it is recommended to open the download endpoint directly in the browser.
Example:
https://your-ngrok-url/download/processed_video.mp4
This will automatically download the processed video.
Pipeline:
Video
↓
YOLO Person Detection
↓
ByteTrack Multi-object Tracking
↓
Track Foot Position
↓
Accumulate Heatmap
↓
Gaussian Blur
↓
Color Map Overlay
↓
Output Video
The heatmap highlights areas where people spend the most time.
POST /processvideo
Upload a video file and start processing.
GET /download/{filename}
Download the processed video once ready.
- Retail store analytics
- Mall foot traffic analysis
- Smart city monitoring
- Event crowd analysis
- Security surveillance
- Real-time webcam heatmap
- Live streaming support
- Multi-class heatmaps
- Web dashboard
- GPU optimization
Muhammad Rehman Ashraf
Computer Vision Developer specializing in:
- AI Video Analytics
- 3D Computer Vision
- Object Tracking
- AR/VR Systems
PIEAS License
Give it a ⭐ on GitHub.