https://github.com/ibrahimjspy/ai-speed-ramping
A Flask-based web app that applies AI-powered speed ramping to video clips by analyzing motion using optical flow and dynamically adjusting playback speed with FFmpeg. Upload or link a video to get cinematic speed transitions automatically.
https://github.com/ibrahimjspy/ai-speed-ramping
ai-video computer-vision editing editing-videos ffmpeg flask machine-learning opencv python speed-ramp video-processing
Last synced: 17 days ago
JSON representation
A Flask-based web app that applies AI-powered speed ramping to video clips by analyzing motion using optical flow and dynamically adjusting playback speed with FFmpeg. Upload or link a video to get cinematic speed transitions automatically.
- Host: GitHub
- URL: https://github.com/ibrahimjspy/ai-speed-ramping
- Owner: ibrahimjspy
- Created: 2025-05-13T16:08:18.000Z (17 days ago)
- Default Branch: main
- Last Pushed: 2025-05-13T16:13:39.000Z (17 days ago)
- Last Synced: 2025-05-13T17:29:01.248Z (17 days ago)
- Topics: ai-video, computer-vision, editing, editing-videos, ffmpeg, flask, machine-learning, opencv, python, speed-ramp, video-processing
- Language: Python
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# AI Speed Ramping Flask App
A Flask-based web application that applies **motion-intensityโdriven speed ramping** to video clips using **OpenCV**, **NumPy**, and **FFmpeg**. This app allows users to upload a short video or provide a remote video URL, analyze motion across frames using optical flow, and generate a dynamic playback effectโspeeding up static moments and slowing down action-packed ones.
---
## ๐ง What It Does
This app intelligently alters video playback speed by analyzing how much movement occurs in each segment of the video:
- **Low-motion segments** (e.g., still frames or minimal camera movement) are played faster (up to 2ร).
- **High-motion segments** (e.g., fast action or transitions) are slowed down (down to 0.5ร).
- The result is a cinematic โspeed rampโ effectโcommonly used in sports replays, music videos, and stylistic transitions.---
## ๐ Features
- **๐ฅ Optical Flow Motion Analysis**
Uses OpenCV to compute pixel-level motion between frames.
- **๐งฎ Dynamic Speed Mapping**
Maps each segment to a speed multiplier based on detected motion.- **๐๏ธ FFmpeg Segment Processing**
Applies speed changes per segment and stitches them back into a final video.- **๐ฅ๏ธ Simple Web UI**
Upload your clip via a browser, watch it get transformed, and download the result.- **โ๏ธ Configurable Parameters**
Customize segment duration, minimum/maximum speeds, and file upload limits via `config.py`.- **๐งฉ API Methods**
Two powerful endpoints to programmatically retrieve speed mapping:
- Upload a file and get back the motion-based speed list.
- Send a remote video URL (e.g. S3) and retrieve speed data.---
## ๐งพ Requirements
- Python 3.8+
- [FFmpeg](https://ffmpeg.org/) installed and available in your system PATH
- Virtualenv (recommended)### Python dependencies (`requirements.txt`):
```text
Flask>=2.0
Werkzeug>=2.0
opencv-python>=4.5
numpy>=1.19
moviepy>=1.0
requests>=2.25
````---
## ๐ Project Structure
```
ai-speed-ramping/
โโโ app.py # Flask application entrypoint
โโโ config.py # Global configuration settings
โโโ static/
โ โโโ styles.css # Basic form styling
โโโ templates/
โ โโโ index.html # Upload interface
โ โโโ result.html # Download page
โโโ processing/
โ โโโ analyzer.py # Optical flow motion detection and speed mapping
โ โโโ ffmpeg_utils.py # FFmpeg segment speed changes and merging
โโโ uploads/ # Temporary input files
โโโ output/ # Final processed files
โโโ requirements.txt # Python dependencies
โโโ README.md # This file
```---
## โ๏ธ Configuration
You can configure the app through `config.py`:
```python
UPLOAD_FOLDER = "uploads/"
OUTPUT_FOLDER = "output/"
ALLOWED_EXTENSIONS = {"mp4", "mov", "avi"}
MAX_CONTENT_LENGTH = 50 * 1024 * 1024 # 50 MBMIN_SPEED = 0.5 # Minimum playback speed
MAX_SPEED = 2.0 # Maximum playback speed
SEGMENT_DURATION = 0.5 # Seconds per speed-analyzed segment
```---
## ๐งช Usage
1. **Start the server**
```bash
flask run
```2. **Open your browser**
Navigate to:
`http://127.0.0.1:5000/`3. **Upload a clip**
Choose a video and submit. Wait for processing.4. **Download result**
After processing, download the ramped video with dynamic speed changes.---
## ๐ก API Endpoints
#### `GET /`
Returns the upload form UI.
#### `POST /process`
Uploads a video, applies speed mapping, and returns a download link for the ramped result.
#### `POST /get-speeds`
**Purpose**: Upload a video and receive the speed mapping JSON.
**Form Fields**:
* `file`: Video file
* `segment_duration`: Optional (defaults to `config.py`)
* `min_speed`: Optional
* `max_speed`: Optional**Response**:
```json
{
"speeds": [1.0, 0.6, 2.0, ...],
"segment_duration": 0.5,
"min_speed": 0.5,
"max_speed": 2.0
}
```---
#### `POST /get-speeds-from-url`
**Purpose**: Provide a video URL (e.g., S3 link), download it, and return the motion-based speed map.
**JSON Payload**:
```json
{
"video_url": "https://s3.amazonaws.com/your-bucket/video.mp4",
"segment_duration": 0.5,
"min_speed": 0.5,
"max_speed": 2.0
}
```**Response**:
```json
{
"speeds": [...],
"segment_duration": 0.5,
"min_speed": 0.5,
"max_speed": 2.0
}
```---
## ๐งน Maintenance Tips
* Clean out `uploads/` and `output/` regularly or use a cron job to prevent disk fill-up.
* Make use of the cleanup logic built into new API methods.---
## ๐งช Development
* **Debug Logging**: Adjust print/debug statements in `app.py` or refactor with logging module.
* **Docker Support** (Optional): Add Dockerfile + volume mounting for portability and scalability.---
## ๐ค Contributing
1. Fork this repository
2. Create a feature branch
`git checkout -b feature/YourFeature`
3. Commit your changes
`git commit -am "Add your feature"`
4. Push and create a PRInclude tests or usage examples if adding new logic.
---
## ๐ชช License
MIT License. See [LICENSE](LICENSE) for details.