(args)
| 208 | |
| 209 | |
| 210 | def cmd_video(args): |
| 211 | cost = args.duration * VIDEO_COST_PER_SEC |
| 212 | output = Path(args.output) |
| 213 | output.parent.mkdir(parents=True, exist_ok=True) |
| 214 | |
| 215 | image_path = Path(args.image) |
| 216 | if not image_path.exists(): |
| 217 | result_json(False, error=f"Reference image not found: {image_path}") |
| 218 | sys.exit(1) |
| 219 | |
| 220 | print(f"Generating {args.duration}s video ({args.resolution})...", file=sys.stderr) |
| 221 | image_url = _image_data_uri(image_path) |
| 222 | |
| 223 | try: |
| 224 | client = xai_sdk.Client() |
| 225 | resp = client.video.generate( |
| 226 | prompt=args.prompt, |
| 227 | model=VIDEO_MODEL, |
| 228 | image_url=image_url, |
| 229 | duration=args.duration, |
| 230 | aspect_ratio="1:1", |
| 231 | resolution=args.resolution, |
| 232 | ) |
| 233 | # Download MP4 |
| 234 | print(" Downloading video...", file=sys.stderr) |
| 235 | dl = requests.get(resp.url, timeout=120) |
| 236 | dl.raise_for_status() |
| 237 | output.write_bytes(dl.content) |
| 238 | except Exception as e: |
| 239 | result_json(False, error=str(e)) |
| 240 | sys.exit(1) |
| 241 | |
| 242 | print(f"Saved: {output}", file=sys.stderr) |
| 243 | result_json(True, path=str(output), cost_cents=cost) |
| 244 | |
| 245 | |
| 246 | def _sidecar_path(output: Path) -> Path: |
nothing calls this directly
no test coverage detected