improved video edit with AI
This commit is contained in:
parent
20466a3e9f
commit
26a4c31087
2 changed files with 33 additions and 11 deletions
13
app.py
13
app.py
|
|
@ -437,8 +437,19 @@ async def edit_clip(
|
||||||
duration = frame_count / fps if fps else 0
|
duration = frame_count / fps if fps else 0
|
||||||
cap.release()
|
cap.release()
|
||||||
|
|
||||||
|
# Load transcript from metadata
|
||||||
|
transcript = None
|
||||||
|
try:
|
||||||
|
meta_files = glob.glob(os.path.join(OUTPUT_DIR, req.job_id, "*_metadata.json"))
|
||||||
|
if meta_files:
|
||||||
|
with open(meta_files[0], 'r') as f:
|
||||||
|
data = json.load(f)
|
||||||
|
transcript = data.get('transcript')
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Could not load transcript for editing context: {e}")
|
||||||
|
|
||||||
# 3. Get Plan (Filter String)
|
# 3. Get Plan (Filter String)
|
||||||
filter_data = editor.get_ffmpeg_filter(vid_file, duration, fps=fps, width=width, height=height)
|
filter_data = editor.get_ffmpeg_filter(vid_file, duration, fps=fps, width=width, height=height, transcript=transcript)
|
||||||
|
|
||||||
# 4. Apply
|
# 4. Apply
|
||||||
# Use safe output name first
|
# Use safe output name first
|
||||||
|
|
|
||||||
31
editor.py
31
editor.py
|
|
@ -37,27 +37,38 @@ class VideoEditor:
|
||||||
raise Exception("Video processing failed by Gemini.")
|
raise Exception("Video processing failed by Gemini.")
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
def get_ffmpeg_filter(self, video_file_obj, duration, fps=30, width=None, height=None):
|
def get_ffmpeg_filter(self, video_file_obj, duration, fps=30, width=None, height=None, transcript=None):
|
||||||
"""Asks Gemini for a raw FFmpeg filter string."""
|
"""Asks Gemini for a raw FFmpeg filter string."""
|
||||||
if width is None or height is None:
|
if width is None or height is None:
|
||||||
# Keep prompt usable even if caller didn't pass dimensions.
|
# Keep prompt usable even if caller didn't pass dimensions.
|
||||||
width, height = 1080, 1920
|
width, height = 1080, 1920
|
||||||
|
|
||||||
|
transcript_text = json.dumps(transcript) if transcript else "Not available."
|
||||||
|
|
||||||
prompt = f"""
|
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.
|
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 Duration: {duration} seconds.
|
||||||
Video FPS: {fps}
|
Video FPS: {fps}
|
||||||
Video Resolution (MUST KEEP EXACT): {width}x{height}
|
Video Resolution (MUST KEEP EXACT): {width}x{height}
|
||||||
|
|
||||||
Goal: Apply dynamic zooms, cuts (simulated with punch-ins), and visual effects to increase retention.
|
TRANSCRIPT (Context of what is being said):
|
||||||
|
{transcript_text}
|
||||||
|
|
||||||
|
Goal: Enhance the video with dynamic zooms, cuts (simulated with punch-ins), and visual effects to increase retention, but DO NOT overdo it. Random effects are bad. Contextual effects are good.
|
||||||
|
|
||||||
Instructions:
|
Instructions:
|
||||||
1. Analyze the video content (if possible) or apply a generic high-retention pacing.
|
1. ANALYZE THE VIDEO AND TRANSCRIPT: Understand the mood, the pacing, and the key moments.
|
||||||
2. Create a single valid FFmpeg filter complex string (for the -vf flag).
|
2. APPLY EFFECTS ONLY WHEN RELEVANT:
|
||||||
3. Use filters like `zoompan`, `eq` (contrast), `hue` (saturation/bw), `unsharp`.
|
- Use "punch-in" zooms (zoompan) to emphasize key points, jokes, or dramatic moments in the speech.
|
||||||
4. Pacing: Something interesting should happen every 3-5 seconds.
|
- slow zooms to face when the speaker is speaking
|
||||||
5. CRITICAL SYNTAX RULES:
|
- Use visual effects (contrast, saturation, sharpness) to highlight mood changes or specific segments.
|
||||||
|
- If nothing significant is happening, keep it simple. It is BETTER to have no effect than a random/distracting one.
|
||||||
|
- Avoid constant motion if the speaker is delivering a serious or steady message.
|
||||||
|
3. Create a single valid FFmpeg filter complex string (for the -vf flag).
|
||||||
|
4. Use filters like `zoompan`, `eq` (contrast), `hue` (saturation/bw), `unsharp`.
|
||||||
|
5. Pacing: Align effects with the rhythm of the speech (from transcript) or visual action.
|
||||||
|
6. CRITICAL SYNTAX RULES:
|
||||||
- DO NOT use comparison operators like `<`, `>`, `<=`, `>=` anywhere. They frequently break FFmpeg expression parsing.
|
- DO NOT use comparison operators like `<`, `>`, `<=`, `>=` anywhere. They frequently break FFmpeg expression parsing.
|
||||||
- USE FFmpeg expression FUNCTIONS instead:
|
- USE FFmpeg expression FUNCTIONS instead:
|
||||||
- `between(x,a,b)`
|
- `between(x,a,b)`
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue