# editor.py:40-112def get_ffmpeg_filter(self, video_file_obj, duration, fps=30, width=None, height=None, transcript=None): prompt = f""" You are an expert FFmpeg video editor. Your task is to generate a complex video filter string to make a short video viral, BUT ONLY apply effects where they make sense contextually. Video Duration: {duration} seconds Video FPS: {fps} Video Resolution (MUST KEEP EXACT): {width}x{height} TRANSCRIPT (Context of what is being said): {transcript_text} Goal: Enhance the video with dynamic zooms, cuts, and visual effects to increase retention, but DO NOT overdo it. Instructions: 1. ANALYZE THE VIDEO AND TRANSCRIPT 2. APPLY EFFECTS ONLY WHEN RELEVANT: - Use "punch-in" zooms (zoompan) to emphasize key points - slow zooms to face when speaker is speaking - Use visual effects (contrast, saturation) for mood changes - If nothing significant is happening, keep it simple 3. Use filters like zoompan, eq, hue, unsharp 4. Align effects with speech rhythm from transcript """
# editor.py:82-87# Uses frame index (on) instead of time for precisionzoompan=z='1.1*between(on,0,75)+1.3*between(on,76,150)+1.15*between(on,151,300)'# Convert seconds to frames: frame = seconds * fps# Always preserves output size:s=1080x1920:fps=30:d=1
Features:
between(on, start, end) for segmented zoom levels
Automatic output size enforcement to preserve aspect ratio
Frame-based timing to avoid drift
Timeline-based color effects:
# editor.py:89-99# Multiple filter instances with enable rangeseq=contrast=1.2:enable='between(t,0,3)',eq=saturation=1.5:enable='between(t,5,8)',hue=s=0:enable='between(t,10,12)' // Black & white effect
Important: Always preserve exact input resolution. The system enforces this automatically by injecting s=WIDTHxHEIGHT into zoompan filters and adding setsar=1 for square pixels.
# app.py:514-621@app.post("/api/subtitle")async def add_subtitles(req: SubtitleRequest): # Generates SRT from transcript # Burns subtitles into video with custom style
# subtitles.py:62-124def generate_srt(transcript, clip_start, clip_end, output_path, max_chars=20, max_duration=2.0): # Extract words within time range for segment in transcript.get('segments', []): for word_info in segment.get('words', []): if word_info['end'] > clip_start and word_info['start'] < clip_end: words.append(word_info) # Group words into short blocks current_block = [] for word in words: current_text_len = sum(len(w['word']) + 1 for w in current_block) duration = end - block_start # Close block if too long or too much time if current_text_len + len(word['word']) > max_chars or duration > max_duration: # Finalize current block text = " ".join([w['word'] for w in current_block]).strip() srt_content += format_srt_block(index, block_start, block_end, text)