Why Automate YouTube Shorts?
YouTube Shorts gets 70 billion daily views in 2026. For developers, automating Shorts creation is both a profitable side project and a technical challenge that combines AI, video processing, and API integration.
The pipeline we'll build generates scripts with AI, converts them to speech, overlays text and visuals, and optionally uploads to YouTube — all from a single Python command.
Pipeline Architecture
[Topic/Niche Input] ↓
[AI Script Generation] → GPT / Gemini / OpenClaw ↓
[Text-to-Speech] → ElevenLabs / Bark / Edge TTS (free) ↓
[Video Assembly] → FFmpeg + stock footage / AI images ↓
[Subtitle Overlay] → Whisper for timing + FFmpeg burn-in ↓
[Upload to YouTube] → YouTube Data API v3 ↓
[Analytics & Iteration] → Track performance, refine topicsStep 1: AI Script Generation
Generate engaging 30-60 second scripts tailored to your niche:
import openai # or use google.generativeai for free Gemini def generate_script(topic, style="educational"): prompt = f"""Write a YouTube Shorts script about: {topic} Style: {style} Requirements: - 30-60 seconds when spoken (80-150 words) - Hook in the first 3 seconds - One key takeaway - End with a call-to-action - Use simple, conversational language Return ONLY the script text, no stage directions.""" response = openai.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": prompt}] ) return response.choices[0].message.contentFree alternative: Use Google Gemini's free API (1,500 requests/day) or OpenClaw for self-hosted script generation at zero cost.
Step 2: Text-to-Speech
Convert scripts to natural-sounding voiceovers:
# Free option: Microsoft Edge TTS (no API key needed)
import edge_tts
import asyncio async def generate_voiceover(text, output_path="voiceover.mp3"): voice = "en-US-ChristopherNeural" # Natural male voice communicate = edge_tts.Communicate(text, voice) await communicate.save(output_path) return output_path asyncio.run(generate_voiceover("Your script text here"))Paid option: ElevenLabs ($5/month) for more natural voices with emotion control. Local option: Bark (free, runs on GPU) for fully offline TTS.
Step 3: Video Assembly with FFmpeg
import subprocess def create_video(voiceover_path, background_video, output_path): """Combine voiceover with background footage in 9:16 format.""" cmd = [ "ffmpeg", "-y", "-i", background_video, "-i", voiceover_path, "-vf", "scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920", "-c:v", "libx264", "-preset", "fast", "-c:a", "aac", "-b:a", "192k", "-shortest", output_path ] subprocess.run(cmd, check=True) return output_pathFor background footage, use royalty-free sources like Pexels or Pixabay, or generate AI images with Stable Diffusion for unique visuals.
Step 4: Auto-Generated Subtitles
Subtitles dramatically increase Shorts engagement (80% of viewers watch without sound):
import whisper def generate_subtitles(audio_path): """Use Whisper to generate word-level timestamps.""" model = whisper.load_model("base") result = model.transcribe(audio_path, word_timestamps=True) # Convert to SRT format srt_content = "" for i, segment in enumerate(result["segments"]): start = format_timestamp(segment["start"]) end = format_timestamp(segment["end"]) srt_content += f"{i+1}\n{start} --> {end}\n{segment['text'].strip()}\n\n" with open("subtitles.srt", "w") as f: f.write(srt_content) return "subtitles.srt" def burn_subtitles(video_path, srt_path, output_path): """Burn subtitles into the video with styling.""" cmd = [ "ffmpeg", "-y", "-i", video_path, "-vf", f"subtitles={srt_path}:force_style='FontSize=24,Bold=1,PrimaryColour=&HFFFFFF,OutlineColour=&H000000,Outline=2,Alignment=2,MarginV=60'", "-c:a", "copy", output_path ] subprocess.run(cmd, check=True)Step 5: Automated Upload
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload def upload_short(video_path, title, description, tags): """Upload a Short to YouTube via Data API v3.""" youtube = build("youtube", "v3", credentials=get_credentials()) request = youtube.videos().insert( part="snippet,status", body={ "snippet": { "title": title + " #Shorts", "description": description, "tags": tags, "categoryId": "28" # Science & Technology }, "status": { "privacyStatus": "public", "selfDeclaredMadeForKids": False } }, media_body=MediaFileUpload(video_path, mimetype="video/mp4") ) response = request.execute() return response["id"]Batch Processing: 30+ Shorts Per Day
topics = [ "Python trick: walrus operator", "Why developers love Rust", "Git command you didn't know", "JavaScript vs TypeScript in 2026", #... add 30+ topics
] for topic in topics: script = generate_script(topic) audio = asyncio.run(generate_voiceover(script)) video = create_video(audio, "backgrounds/coding-bg.mp4", f"shorts/{topic[:20]}.mp4") srt = generate_subtitles(audio) final = burn_subtitles(video, srt, f"final/{topic[:20]}.mp4") # Optional: upload_short(final, topic,..., [...])Monetization Path
- YouTube Partner Program: 1,000 subscribers + 10M Shorts views in 90 days
- Revenue range: $0.01-0.07 per 1,000 views (lower than long-form but volume-based)
- Affiliate marketing: Promote tools and courses in descriptions
- Lead generation: Drive viewers to your products or services
- Content repurposing: Use the same scripts for TikTok, Instagram Reels, and blog posts
Complete Free Tool Stack
| Step | Free Tool | Paid Alternative |
|---|---|---|
| Scripting | Gemini Free API | GPT-4o ($20/mo) |
| TTS | Edge TTS | ElevenLabs ($5/mo) |
| Video | FFmpeg | Shotstack API |
| Subtitles | Whisper (local) | Rev.ai ($0.02/min) |
| Upload | YouTube API (free) | TubeBuddy ($9/mo) |
Start Building Today
The entire pipeline can be built and tested in a weekend. Use CoderFile.io to prototype your Python scripts collaboratively, and explore more free AI tools to enhance your automation stack. For bot-based approaches, check our OpenClaw monetization guide.