"""Retry shot-04 with a simple clean carpet scene.""" import os, sys, time, subprocess try: from google import genai from google.genai import types except ImportError: os.system(f"{sys.executable} -m pip install google-genai --quiet") from google import genai from google.genai import types API_KEY = os.environ.get("GEMINI_API_KEY", "AIzaSyB_1p8KvaT_rdNJGPs8HKk8bKsvUlcL6Kg") BASE_DIR = os.path.dirname(os.path.dirname(__file__)) VID_DIR = os.path.join(BASE_DIR, "assets", "videos", "hero", "clips") REEL_OUT = os.path.join(BASE_DIR, "assets", "videos", "hero", "hero-reel.mp4") client = genai.Client(api_key=API_KEY) PROMPTS = [ ( "Cinematic slow dolly shot moving forward through a bright residential living room. " "Clean, plush beige carpet fills the floor. Warm afternoon sunlight comes through large windows. " "Contemporary furniture, neutral walls. The carpet looks freshly cleaned — bright, fluffy, spotless. " "No people. No machines. Photorealistic." ), ( "Slow cinematic camera pan across a clean beige residential carpet in a bright living room. " "The carpet fibers are lifted and bright after professional cleaning. " "Warm natural light. Modern home interior. No people, no equipment. Photorealistic." ), ] MODEL = "veo-3.1-generate-preview" out_path = os.path.join(VID_DIR, "shot-04-extraction-carpet.mp4") def poll(op, timeout=600): elapsed = 0 while not op.done: if elapsed >= timeout: return None print(f" Waiting... ({elapsed}s)") time.sleep(15) elapsed += 15 op = client.operations.get(op) return op saved = False for i, prompt in enumerate(PROMPTS): print(f"\n[VID] shot-04 attempt {i+1}...") try: op = client.models.generate_videos( model=MODEL, prompt=prompt, config=types.GenerateVideosConfig( aspect_ratio="16:9", resolution="720p", duration_seconds=6, number_of_videos=1, ), ) op = poll(op) if op and op.response and op.response.generated_videos: vid = op.response.generated_videos[0].video video_bytes = client.files.download(file=vid) if video_bytes: with open(out_path, "wb") as f: f.write(video_bytes) print(f" Saved ({os.path.getsize(out_path)//1024}KB)") saved = True break else: print(f" No video returned, trying next prompt...") except Exception as e: print(f" Error: {e}") if not saved: print("All attempts failed.") else: ORDER = [ "shot-01-door-opens-trimmed", "shot-02-pan-to-stains", "shot-03-stain-closeup", "shot-04-extraction-carpet", "shot-05-extraction-couch", "shot-06-extraction-stairs", "shot-07-office-entryway", "shot-08-showroom", "shot-09-technician-unloading", ] concat_file = os.path.join(VID_DIR, "concat.txt") with open(concat_file, "w") as f: for name in ORDER: f.write(f"file '{os.path.join(VID_DIR, name)}.mp4'\n") result = subprocess.run( ["ffmpeg", "-y", "-f", "concat", "-safe", "0", "-i", concat_file, "-c:v", "libx264", "-crf", "22", "-preset", "fast", "-movflags", "+faststart", REEL_OUT], capture_output=True, text=True ) if result.returncode == 0: print(f" Reel saved ({os.path.getsize(REEL_OUT)//1024}KB)") else: print(f" ffmpeg error: {result.stderr[-300:]}") print("\nDone.")