AI-Youtube-Shorts-Generator

Anil-matchaMIT活跃维护

把长视频自动剪成 9:16 竖屏短视频,用 LLM 挑高光片段、Whisper 转写、自动裁切,免费无水印,替代 Opus Clip 等付费服务。

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.

暂无版本5,906star +94 / 7 天1,073fork同步于 2026-11-10 23:36 UTC

怎么上手

由 README 提炼,执行前请确认
git clone https://github.com/SamurAIGPT/AI-Youtube-Shorts-Generator.git && cd AI-Youtube-Shorts-Generator
pip install -r requirements.txt
python main.py "https://www.youtube.com/watch?v=VIDEO_ID"
硬件要求按 README 说明

README 未给出具体显存要求;本地转写可用 faster-whisper 在 CPU 或 CUDA 上运行,设备由 LOCAL_WHISPER_DEVICE 控制(auto/cpu/cuda),模型可选 tiny 到 large-v3。本地模式需 ffmpeg 在 PATH 中。

需要 CUDA
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

开源版 Opus Clip,把长 YouTube 视频自动剪成带评分的高光竖屏短片

把长视频自动剪成 9:16 竖屏短视频,用 LLM 挑高光片段、Whisper 转写、自动裁切,免费无水印,替代 Opus Clip 等付费服务。

核心能力

  • 用 LLM 按钩子、情绪峰值、金句等病毒性框架给片段打分排序
  • Whisper 转写支持云端或本地 faster-whisper(CPU/CUDA)
  • 超 30 分钟视频自动重叠分块,避免漏掉高光
  • 重叠候选按分数去重,避免产出近似重复片段
  • 本地模式用 OpenCV 人脸跟踪做竖屏自动裁切,支持任意比例

容易踩的坑

默认 api 模式必须配置 MUAPI_API_KEY,否则无法下载、转写和裁切;本地模式需额外执行 pip install -r requirements-local.txt 并安装 ffmpeg;本地模式仍需 OPENAI_API_KEY 或 GEMINI_API_KEY 做高光排序,并非完全离线。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    AI YouTube Shorts Generator

    Powered by MuAPI

    The open-source alternative to Opus Clip, Vidyo.ai, Klap, SubMagic, 2short.ai, and other AI clipping tools. Drop in any long-form YouTube video and get back ranked, viral-ready 9:16 shorts — for free, with no per-clip credits, no watermarks, and full control over the highlight algorithm.

    Built for creators, agencies, and developers who don't want to pay $20–$300/month or be capped on minutes processed. Uses GPT-class LLM highlight detection and Whisper transcription to extract the most viral-worthy moments and auto-crop them vertically for TikTok, Reels, and Shorts.

    Building your own Opus Clip–style SaaS? Skip the infra and ship on the same APIs that power this repo:

    longshorts

    🎨 Explore 50+ more open-source AI apps →

    Why Use This Instead of Opus Clip / Vidyo.ai / Klap?

    This repoOpus Clip / Vidyo.ai / Klap / SubMagic
    PriceFree + open source (pay only for API usage)$20–$300/month subscriptions
    Per-clip creditsNone — process unlimited videosMonthly minute caps, overage fees
    WatermarksNeverOn free tiers
    Highlight algorithmFully editable virality frameworkBlack box
    Output formatAny aspect ratio, any resolutionLocked presets
    Batch processingxargs an entire URL listManual upload one-by-one
    JSON / API outputBuilt-in (--output-json)Limited or paid tier only
    Self-hostableYes — runs on your machine or serverSaaS only, your videos sit on their servers
    White-label / embeddableYes — MIT licensed, import as Python libNo

    Features

    • 🎬 YouTube In, Vertical Out: Hand it any YouTube URL — get back N viral-ready 9:16 mp4s
    • 🔀 Two Modes — API (fast) or Local (offline): Default --mode api uses MuAPI for download/transcription/cropping; --mode local runs entirely on your machine with yt-dlp, faster-whisper, and ffmpeg/opencv, and lets you pick OpenAI or Gemini for highlight ranking
    • 🤖 Virality-Aware Highlight Selection: Clips ranked on hooks, emotional peaks, opinion bombs, revelation moments, conflict, quotable lines, story peaks, and practical value — not just generic "interesting"
    • 📈 Score + Hook + Reason for Every Clip: Each highlight comes with a viral score, an opening hook line, and a one-sentence explanation of why it works
    • 🎤 Whisper Transcription, Your Choice: Cloud (/openai-whisper via MuAPI) or local (faster-whisper, CPU or CUDA) — same downstream output shape
    • 🧩 Long-Video Aware: Videos over 30 minutes are auto-chunked with overlap so nothing gets missed
    • ♻️ Smart Dedupe: Overlapping highlights are collapsed by score so you never get two near-duplicate clips
    • 🎯 Smart Vertical Crop: API mode uses MuAPI's auto-crop; local mode runs OpenCV face tracking with motion smoothing
    • 📱 Any Aspect Ratio: 9:16 for TikTok/Reels/Shorts, 1:1 for square, anything else by flag
    • 🧰 CLI + Python Library: Use it from the shell or import generate_shorts(...) into your own pipeline
    • 📦 JSON Output: --output-json dumps the full result (transcript + every candidate highlight + final clip URLs/paths) for downstream automation

    Quick Start (No Setup)

    Don't want to self-host? The AI Clipping API gives you the same Opus Clip–style pipeline as a single HTTP call — no Python, no dependencies, pay-per-clip instead of monthly subscriptions.


    Installation (Self-Hosted)

    Prerequisites

    • Python 3.10+
    • For API mode (default): a MuAPI key — powers download, transcription, highlight ranking, and clipping in a single dependency
    • For Local mode (--mode local): ffmpeg on your PATH and an LLM API key (OPENAI_API_KEY or GEMINI_API_KEY; only the LLM step is remote)

    Steps

    1. Clone the repository:

      git clone https://github.com/SamurAIGPT/AI-Youtube-Shorts-Generator.git
      cd AI-Youtube-Shorts-Generator
      
    2. Create and activate a virtual environment:

      python3.10 -m venv venv
      source venv/bin/activate
      
    3. Install Python dependencies:

      pip install -r requirements.txt
      # Only if you plan to use --mode local:
      pip install -r requirements-local.txt
      
    4. Set up environment variables:

      Create a .env file in the project root:

      # API mode (default)
      MUAPI_API_KEY=your_muapi_key_here
      
      # Local mode (--mode local)
      LLM_PROVIDER=openai         # openai or gemini
      OPENAI_API_KEY=your_openai_key_here
      OPENAI_MODEL=gpt-4o-mini          # optional, default gpt-4o-mini
      GEMINI_API_KEY=your_gemini_key_here
      GEMINI_MODEL=gemini-2.5-flash      # optional, default gemini-2.5-flash
      LOCAL_WHISPER_MODEL=base          # tiny / base / small / medium / large-v3
      LOCAL_WHISPER_DEVICE=auto         # auto / cpu / cuda
      LOCAL_OUTPUT_DIR=output           # where local mp4s land
      

    Usage

    Single video (API mode — default)

    python main.py "https://www.youtube.com/watch?v=VIDEO_ID"
    

    Single video (Local mode — runs offline except for the LLM call)

    python main.py "https://www.youtube.com/watch?v=VIDEO_ID" --mode local
    

    Local mode writes the rendered shorts to ./output/short_01.mp4, short_02.mp4, … (override with LOCAL_OUTPUT_DIR).

    With options

    python main.py "https://www.youtube.com/watch?v=VIDEO_ID" \
        --mode api \
        --num-clips 5 \
        --aspect-ratio 9:16 \
        --output-json result.json
    

    Local file or path

    In --mode local, you can pass a file:// URL or a direct filesystem path and skip YouTube entirely:

    python main.py "/Users/you/Videos/input.mp4" --mode local
    python main.py "file:///Users/you/Videos/input.mp4" --mode local
    

    The Python API works the same way:

    from shorts_generator import generate_shorts
    
    result = generate_shorts(
        "/Users/you/Videos/input.mp4",
        num_clips=5,
        aspect_ratio="9:16",
        mode="local",
    )
    for short in result["shorts"]:
        print(short["score"], short["title"], short["clip_url"])
    

    Local transcription is cached as an .srt file in LOCAL_OUTPUT_DIR using the video's base name. If the cache already exists and is newer than the source file, the app reuses it instead of running Whisper again.

    Local downloads are also cached in LOCAL_OUTPUT_DIR as source_<youtube_id>.mp4 when the input is a YouTube URL. If that file already exists, the app skips yt-dlp and reuses the cached video.

    Batch processing

    Create a urls.txt file with one URL per line, then:

    xargs -a urls.txt -I{} python main.py "{}"
    

    CLI flags

    FlagDefaultNotes
    --modeapiapi (MuAPI, fast, no setup) or local (remote URL, file://, or local path + faster-whisper + LLM provider + ffmpeg)
    --num-clips3How many shorts to render
    --aspect-ratio9:16Any ratio; 9:16 for TikTok/Reels, 1:1 for square
    --format720Source download resolution: 360 / 480 / 720 / 1080
    --languageautoForce Whisper language code (e.g. en)
    --output-json—Dump the full result (transcript + all candidates) to a file

    API mode vs Local mode

    StepAPI mode (--mode api)Local mode (--mode local)
    DownloadMuAPI /youtube-downloadyt-dlp for remote URLs, direct file path for local inputs
    TranscriptionMuAPI /openai-whisperfaster-whisper (CPU or CUDA)
    Highlight LLMMuAPI gpt-5-miniLLM_PROVIDER=openai uses OpenAI (gpt-4o-mini by default), LLM_PROVIDER=gemini uses Gemini (gemini-2.5-flash by default)
    Vertical cropMuAPI /autocropffmpeg + OpenCV face tracking
    Outputhosted URLslocal mp4 paths
    Required keysMUAPI_API_KEYOPENAI_API_KEY or GEMINI_API_KEY (+ ffmpeg on PATH)

    How It Works

    1. Download: Fetches the source video from YouTube
    2. Transcribe: MuAPI /openai-whisper produces a timestamped transcript (verbose_json segments)
    3. Detect content type: An LLM classifies the video (podcast, interview, tutorial, vlog, etc.) and density, so the prompt can be tuned per content style
    4. Long-video chunking: Videos > 30 min are split into 20-min overlapping chunks
    5. Highlight ranking: An LLM scans the transcript through a virality framework — hook moments, emotional peaks, opinion bombs, revelations, conflict, quotables, story peaks, practical value — and emits ranked candidates with scores 0–100
    6. Dedupe: Overlapping candidates are collapsed by score (>50% overlap → keep the higher score)
    7. Top-N selection: The top --num-clips candidates are selected
    8. Auto-crop: Each highlight is rendered as a vertical short at the requested aspect ratio

    Output: a list of mp4 URLs plus, for each clip, its title, viral score, hook sentence, and a one-line reason explaining why it should perform.

    Output

    Console output looks like:

    ========================================================================
    Highlights:    7 candidates → kept top 3
    ========================================================================
    
    #1  score=92  124.3s → 187.6s
         title:  The one mistake that cost me $50K
         hook:   "Nobody talks about this, but it killed my first startup..."
         clip:   https://.../short_1.mp4
    
    #2  score=88  ...
    

    --output-json result.json produces:

    {
      "source_video_url": "...",
      "transcript": { "duration": 1873.4, "segments": [...] },
      "highlights": [ {...}, {...}, ... ],
      "shorts": [
        {
          "title": "...",
          "start_time": 124.3,
          "end_time": 187.6,
          "score": 92,
          "hook_sentence": "...",
          "virality_reason": "...",
          "clip_url": "https://.../short_1.mp4"
        }
      ]
    }
    

    Configuration

    Highlight selection criteria

    Edit shorts_generator/highlights.py:

    • Virality framework: VIRALITY_CRITERIA — the ranked list of signals the LLM optimizes for
    • System prompt: HIGHLIGHT_SYSTEM_PROMPT — duration sweet spot, hook rules, JSON schema
    • Chunk size: CHUNK_SIZE_SECONDS (default 1200) — chunk length for long videos
    • Long-video threshold: LONG_VIDEO_THRESHOLD (default 1800) — videos longer than this are chunked
    • Chunk overlap: CHUNK_OVERLAP_SECONDS (default 60) — overlap between chunks so cross-boundary clips aren't missed

    Polling / timeout

    Edit shorts_generator/config.py (or set env vars):

    • MUAPI_POLL_INTERVAL (default 5s) — seconds between job-status polls
    • MUAPI_POLL_TIMEOUT (default 1800s) — give up after this long

    Whisper transcription

    Audio is transcribed by MuAPI's /openai-whisper endpoint (server-side whisper-1). Pass --language <code> to lock the recognition to a specific language; otherwise it auto-detects.

    Project Structure

    AI-Youtube-Shorts-Generator/
    ├── main.py                       CLI entry point
    ├── requirements.txt              core deps (api mode)
    ├── requirements-local.txt        optional deps for --mode local
    ├── .env.example
    └── shorts_generator/
        ├── config.py                 env / settings (MuAPI + local LLM + Whisper)
        ├── muapi.py                  generic submit + poll wrapper
        ├── downloader.py             API mode: YouTube download via MuAPI
        ├── transcriber.py            API mode: MuAPI /openai-whisper client
        ├── highlights.py             shared LLM virality ranking (pluggable backend)
        ├── clipper.py                API mode: MuAPI /autocrop
        ├── pipeline.py               mode dispatcher (api ↔ local)
        └── local/                    --mode local backends (offline)
            ├── downloader.py         yt-dlp download
            ├── transcriber.py        faster-whisper transcription
            ├── llm.py                OpenAI or Gemini client selector
            └── clipper.py            ffmpeg cut + OpenCV vertical crop
    

    Troubleshooting

    Whisper produced no segments

    The video may have no detectable speech, or it may be in a language Whisper struggles with. Try passing --language en (or the correct ISO-639-1 code) to skip auto-detection.

    Looking for better results?

    The AI Clipping API uses an improved algorithm that produces higher-quality clips with better highlight detection.

    Contributing

    Contributions are welcome! Please fork the repository and submit a pull request.

    License

    This project is licensed under the MIT License.

    Related Projects