SaarD00
AI-Youtube-Shorts-Generator
Python

Infinite content, zero manual editing. A fully automated 'faceless' video factory that turns trending topics into engaging YouTube Shorts using Gemini AI, Edge-TTS, and dynamic FFmpeg editing

Last updated Jul 8, 2026
169
Stars
40
Forks
0
Issues
+4
Stars/day
Attention Score
78
Language breakdown
No language data available.
โ–ธ Files click to expand
README

๐ŸŽฌ AutoShorts AI: The Automated Faceless Video Generator

Views

AutoShorts AI is a Python pipeline that creates viral-style "Faceless" YouTube Shorts and TikToks from a topic. It handles the production chain: AI topic/script generation, voiceover generation, stock footage sourcing, and FFmpeg editing with transitions and avatar injection.


โœจ Key Features

  • ๐Ÿง  Intelligent Scriptwriting: Uses Google Gemini 2.0 Flash to write engaging, "Edutainment" style scripts (Vox/Kurzgesagt style) with strict storytelling structures (Hook โ†’ Context โ†’ Mechanism โ†’ Twist).
  • ๐Ÿ—ฃ๏ธ Voiceovers: Generates narration with edge-tts.
  • ๐ŸŽž๏ธ Dual-Visual System: Automatically searches and downloads two distinct stock videos per scene from Pexels, creating a dynamic "A/B Split" visual style to maximize viewer retention.
  • โœ‚๏ธ Advanced FFmpeg Editing:
  • Smart Trimming: Syncs video perfectly to audio duration.
  • A/B Splitting: Cuts every scene in half, switching visuals mid-sentence.
  • Pro Transitions: Randomly applies xfade (fade, slide, wipes) between scenes.
  • Silence Removal: Automatically trims dead air from AI voice generation.
  • ๐Ÿค– Random Avatar Injection: Automatically inserts a custom "Avatar/Mascot" video into a random middle scene to build channel brand identity.
  • ๐ŸชŸ Windows Ready: Includes specific FFmpeg flags (yuv420p, faststart) to prevent corruption errors (0x80004005) on Windows Media Player.

๐Ÿ“‚ Project Structure

Automated-YT-Shorts-AI/
โ”‚
โ”œโ”€โ”€ assets/                  # Stores all media files
โ”‚   โ”œโ”€โ”€ audio_clips/         # Generated voiceovers (.wav)
โ”‚   โ”œโ”€โ”€ video_clips/         # Downloaded stock footage (.mp4)
โ”‚   โ”œโ”€โ”€ temp/                # Intermediate processing files
โ”‚   โ”œโ”€โ”€ final/               # ๐Ÿ† The Final Output Video lives here
โ”‚   โ””โ”€โ”€ avatar/              # โš ๏ธ PUT YOUR AVATAR VIDEO HERE
โ”‚       โ””โ”€โ”€ ProfessionalGirlAnimationVideoGeneration.mp4
โ”‚
โ”œโ”€โ”€ modules/                 # Core Logic Modules
โ”‚   โ”œโ”€โ”€ brain.py             # AI Scriptwriter (Gemini)
โ”‚   โ”œโ”€โ”€ audio.py             # Voice generator (edge-tts)
โ”‚   โ”œโ”€โ”€ asset_manager.py     # Pexels Downloader (Dual-Visual logic)
โ”‚   โ””โ”€โ”€ composer.py          # FFmpeg Video Editor (Stitching & Transitions)
โ”‚
โ”œโ”€โ”€ main.py                  # Entry point (Orchestrator)
โ””โ”€โ”€ requirements.txt         # Python dependencies

๐Ÿ› ๏ธ Prerequisites

  • Python 3.10+ installed.
  • FFmpeg installed and added to your system PATH.
  • Windows: winget install ffmpeg (or download from ffmpeg.org).
  • Verify: Type ffmpeg -version in your terminal.
  • API Keys:
  • Google Gemini API Key (Free tier available).
  • Pexels API Key (Free).
  • No Ngrok token is required for the default voiceover path. The current pipeline uses edge-tts.

๐Ÿš€ Installation

1. Clone the Repository

git clone https://github.com/yourusername/AutoShorts-AI.git
cd AutoShorts-AI

2. Install Dependencies

pip install -r requirements.txt

3. Environment Setup

Create the required folders and add your avatar:

  • Create folder: assets/avatar
  • Place your avatar video inside and name it: avatars.mp4

4. Configure API Keys

Copy .env.example to .env and fill in your key:

cp .env.example .env

Required:

  • GEMINIAPIKEY for script generation
  • PEXELSAPIKEY for stock video search/download
Optional:
  • GEMINI_MODEL to override the default gemini-2.0-flash model

๐ŸŽฎ How to Run

Generate Video

Run the main script:

python main.py
  • Enter a topic (e.g., "The Mystery of the Pyramids").
  • Wait for the AI to write the script, generate audio, download stock footage, and edit the video.
  • The final video will be saved in assets/final/final_short.mp4.

๐Ÿงฉ Module Breakdown

brain.py ( The Writer)

  • Input: Topic string.
  • Logic: Prompts Gemini to create an 8-9 scene JSON script. It asks for two visual keywords per scene (visual1, visual2) to enable the A/B split effect.

audio.py (The Voice)

  • Input: Text script.
  • Logic: Generates MP3 voice clips with edge-tts.
  • Post-Processing: Reads durations with mutagen so scenes can be synced to audio length.

asset_manager.py (The Librarian)

  • Input: Visual keywords.
  • Logic: Searches Pexels for Portrait (9:16) videos. Downloads pairs of videos for every scene. Handles fallbacks (if Video B is missing, reuse Video A).

composer.py (The Editor)

  • Input: Audio files + Video files.
  • Logic:
  • Scene Processing: Cuts the scene duration in half. Plays Video A for the first half, Video B for the second half.
  • Avatar Injection: Identifies a random "middle" scene (not hook/outro) and replaces the stock footage with your Avatar loop.
  • Stitching: Merges all scenes using xfade transitions (wipes, slides).
  • Rendering: Exports as yuv420p H.264 MP4 with faststart flags for maximum compatibility.

โš ๏ธ Troubleshooting

Q: The video is black or corrupt (0x80004005 error).

  • Fix: This is usually a Windows codec issue. The updated composer.py forces pix_fmt='yuv420p'. Try opening the file with VLC Media Player.
Q: "Avatar file missing" error.
  • Fix: Ensure your folder structure is exactly assets/avatar/avatars.mp4.
Q: The audio is silent or fails.
  • Fix: Check your internet connection and that edge-tts is installed from requirements.txt.
Q: FFmpeg error "Exec format error" or "not found".
  • Fix: Ensure FFmpeg is installed and accessible from your command line.

๐Ÿ“œ License

This project is open-source. Feel free to modify and build your own automation empire!

ยฉ 2026 GitRepoTrend ยท SaarD00/AI-Youtube-Shorts-Generator ยท Updated daily from GitHub