OpenShorts uses Google Gemini 2.5 Flash to analyze video transcripts and automatically identify 3-15 viral moments optimized for TikTok, Instagram Reels, and YouTube Shorts. The AI considers word-level timestamps, silence patterns, and viral content signals to extract clips between 15-60 seconds.
The transcript is sent to Gemini with a specialized prompt engineered for viral moment detection:
main.py
GEMINI_PROMPT_TEMPLATE = """You are a senior short-form video editor. Read the ENTIRE transcript and word-level timestamps to choose the 3–15 MOST VIRAL moments for TikTok/IG Reels/YouTube Shorts. Each clip must be between 15 and 60 seconds long.⚠️ FFMPEG TIME CONTRACT — STRICT REQUIREMENTS:- Return timestamps in ABSOLUTE SECONDS from the start of the video (usable in: ffmpeg -ss <start> -to <end> -i <input> ...).- Only NUMBERS with decimal point, up to 3 decimals (examples: 0, 1.250, 17.350).- Ensure 0 ≤ start < end ≤ VIDEO_DURATION_SECONDS.- Each clip between 15 and 60 s (inclusive).- Prefer starting 0.2–0.4 s BEFORE the hook and ending 0.2–0.4 s AFTER the payoff.- Use silence moments for natural cuts; never cut in the middle of a word or phrase.VIDEO_DURATION_SECONDS: {video_duration}TRANSCRIPT_TEXT (raw):{transcript_text}WORDS_JSON (array of {{w, s, e}} where s/e are seconds):{words_json}STRICT EXCLUSIONS:- No generic intros/outros or purely sponsorship segments unless they contain the hook.- No clips < 15 s or > 60 s.OUTPUT — RETURN ONLY VALID JSON:{{ "shorts": [ {{ "start": <number in seconds, e.g., 12.340>, "end": <number in seconds, e.g., 37.900>, "video_description_for_tiktok": "<description for TikTok oriented to get views>", "video_description_for_instagram": "<description for Instagram oriented to get views>", "video_title_for_youtube_short": "<title for YouTube Short oriented to get views 100 chars max>", "viral_hook_text": "<SHORT punchy text overlay (max 10 words). MUST BE IN THE SAME LANGUAGE AS THE VIDEO TRANSCRIPT>" }} ]}}"""
Gemini returns a structured response with viral clips and platform-specific metadata:
{ "shorts": [ { "start": 12.340, "end": 37.900, "video_description_for_tiktok": "POV: You discovered the AI workflow that changed everything 🤯 #ai #automation", "video_description_for_instagram": "This AI hack will save you 10 hours/week. Comment WORKFLOW and I'll send it! 🔥", "video_title_for_youtube_short": "I Automated My Entire Workflow with AI (10 Hours Saved Per Week)", "viral_hook_text": "THIS CHANGED EVERYTHING" } ], "cost_analysis": { "input_tokens": 1523, "output_tokens": 342, "input_cost": 0.0001523, "output_cost": 0.0001368, "total_cost": 0.0002891, "model": "gemini-2.5-flash" }, "transcript": { /* full transcript data */ }}