Anil-matcha/AI-Youtube-Shorts-Generator
Open-source alternative to Opus Clip, Vidyo.ai, Klap & SubMagic. Turn long-form YouTube videos into viral 9:16 shorts using LLM highlight detection, Whisper transcription, and auto vertical cropping — free, no watermarks, no per-clip credits.
AI‑YouTube‑Shorts‑Generator – What it is
A command‑line / Python library that takes a long‑form YouTube video (or a local video file) and automatically creates short, vertical 9:16 clips ready for TikTok, Instagram Reels or YouTube Shorts. It does this by:
- Downloading the source video.
- Transcribing the audio with Whisper (via MuAPI or a local
faster‑whispermodel). - Running an LLM (OpenAI or Gemini, or MuAPI’s own model) over the transcript to rank moments that are likely to go viral – hooks, emotional peaks, quotable lines, etc.
- Selecting the top‑N highlights, de‑duplicating overlapping candidates.
- Cropping each highlight vertically (auto‑crop API or OpenCV‑based face‑tracking) and exporting MP4 files.
The result includes a short video, a viral‑score, a hook sentence and a one‑sentence reason why the clip should perform well. The whole pipeline can run entirely locally (except for the LLM call) or can be delegated to MuAPI’s hosted endpoints for a zero‑setup “API‑mode”.
Core Features (as described in the README)
- YouTube‑in → vertical‑short‑out – just give a URL, get one or more 9:16 MP4s.
- Two operating modes
--mode api(default): uses MuAPI for download, Whisper transcription, LLM ranking and auto‑crop – no local dependencies beyond Python.--mode local: runsyt‑dlp,faster‑whisper, OpenCV/ffmpeg and calls OpenAI or Gemini for the highlight ranking.
- Virality‑aware highlight selection – the LLM scores clips on hooks, emotional peaks, opinion bombs, revelations, conflict, quotable lines, story peaks, practical value.
- Score, hook, and reasoning are returned for every clip.
- Chunking & deduplication for videos > 30 min so no important moment is missed.
- Custom aspect ratios (9:16, 1:1, or any user‑specified ratio).
- CLI and Python library – can be invoked from the shell or imported (
generate_shorts). - JSON output (
--output‑json) containing the full transcript, candidate highlights and final clip metadata. - Batch processing via
xargson a list of URLs. - MIT‑licensed, self‑hostable – you keep the videos on your own hardware.
How it works (pipeline overview)
| Step | API mode (muapi) |
Local mode |
|---|---|---|
| Download | MuAPI /youtube-download |
yt‑dlp (or direct file path) |
| Transcribe | MuAPI /openai‑whisper (whisper‑1) |
faster‑whisper (CPU or CUDA) |
| Highlight ranking | MuAPI gpt‑5‑mini (virality prompt) |
OpenAI gpt‑4o‑mini or Gemini gemini‑2.5‑flash via the LLM_PROVIDER env var |
| Vertical crop | MuAPI /autocrop (face‑tracking) |
ffmpeg + OpenCV face tracking |
| Output | Hosted URLs | Local MP4 files |
The LLM receives a transcript (timestamped JSON) and a system prompt that defines the “virality framework”. It returns a list of candidate clips with scores and explanatory text. Overlapping candidates (> 50 % overlap) are collapsed, the top‑N are kept, and each segment is cut and re‑framed vertically.
Quick start (self‑hosted)
# 1. Clone & set up
git clone https://github.com/SamurAIGPT/AI-Youtube-Shorts-Generator.git
cd AI-Youtube-Shorts-Generator
python3.10 -m venv venv && source venv/bin/activate
pip install -r requirements.txt # core (API mode)
# pip install -r requirements-local.txt # only if you plan to use --mode local
# 2. Create .env (example)
cat > .env <<EOF
MUAPI_API_KEY=your_muapi_key
# optional for local mode
OPENAI_API_KEY=your_openai_key
EOF
# 3. Generate shorts (API mode – no extra deps)
python main.py "https://www.youtube.com/watch?v=VIDEO_ID"
# 4. Or run locally (requires ffmpeg, yt‑dlp, faster‑whisper)
python main.py "https://www.youtube.com/watch?v=VIDEO_ID" --mode local --num-clips 5
When to use which mode
- API mode – fastest to try, no heavy dependencies, pay‑per‑clip to MuAPI. Ideal for occasional use or prototyping.
- Local mode – gives you full control, no recurring API costs, but you must install
ffmpeg,yt‑dlp,faster‑whisperand have an OpenAI/Gemini key for the LLM step.
Pros & Cons (as inferred from the README)
| Pros | Cons |
|---|---|
| Free and open‑source; only pay for the underlying LLM/Whisper APIs you choose. | Relies on external LLMs for the core highlight ranking – you need an OpenAI or Gemini key (or MuAPI credits). |
| No watermarks or per‑clip limits; unlimited processing on your own hardware. | Local mode can be resource‑heavy (Whisper large models, GPU needed for speed). |
Fully editable virality framework – you can tweak the prompt or highlights.py. |
The quality of the clips depends heavily on the LLM’s prompt; may need prompt tuning for niche content. |
| Supports batch processing and JSON output for automation pipelines. | Only supports YouTube URLs out‑of‑the‑box; other platforms would need custom download code. |
| MIT license – easy to embed in other Python projects. | No GUI; interaction is via CLI or code. |
Who might find this useful?
- Content creators who want to repurpose long videos into Shorts without paying SaaS subscriptions.
- Agencies that need to process many videos automatically.
- Developers building a custom video‑clipping SaaS – they can use the same MuAPI endpoints or the library as a starting point.
- Researchers exploring LLM‑driven video summarisation.
License
MIT – you can freely use, modify and redistribute the code.
Related
- Project
- Project
- Project
- Project