---
name: topaz-upscale-sync-lipsync
description: Run fal.ai serverless queue jobs for Topaz Video Upscale (fal-ai/topaz/upscale/video at $0.01-$0.08/s, half price on Gaia 2, 2x for 60fps) and Sync Lipsync 2.0 (fal-ai/sync-lipsync/v2 at $3/min or /v2/pro at $5/min), plus FFmpeg pre-trimming, 48 kHz WAV preservation, and -14 LUFS master verification. Use when upscaling 720p AI clips to 4K or swapping dialogue on talking-head videos.
---

# Topaz 4K Upscale & Sync Lipsync 2.0 fal.ai Skill

## 1. Mandatory Pre-Flight Cost Estimate (Before Any Paid Call)
Always probe clip duration with `ffprobe` and print estimated fal.ai spend before submitting:
- **Topaz Video Upscale (`fal-ai/topaz/upscale/video`):**
  - `<=720p`: `$0.01/sec` | `720p–1080p`: `$0.02/sec` | `>1080p (4K)`: `$0.08/sec`
  - Multipliers: `target_fps: 60` = `2x` rate; `model: "Gaia 2"` (animation/CGI) = `0.5x` rate.
- **Sync Lipsync 2.0:**
  - `fal-ai/sync-lipsync/v2`: `$3.00/min` (`$0.05/sec`)
  - `fal-ai/sync-lipsync/v2/pro`: `$5.00/min` (`$0.083/sec`)
- **Order of operations rule:** If running BOTH lip-sync and 4K upscaling, ALWAYS run **Sync Lipsync 2.0 first** on the 1080p source plate, then upscale once at the end.

## 2. Topaz Video Upscale Queue Pattern
1. Trim dead opening settle frames (`-ss 0.40`) and extract original 48 kHz WAV audio first.
2. Pick `model: "Proteus"` + `grain: 0.03` for photoreal cinema, or `model: "Gaia 2"` (half price, never 60fps) for 2D/stop-motion animation.
3. Submit asynchronously to `https://queue.fal.run/fal-ai/topaz/upscale/video`:
```bash
curl -sS -X POST "https://queue.fal.run/fal-ai/topaz/upscale/video" \
  -H "Authorization: Key $FAL_KEY" \
  -H "Content-Type: application/json" \
  -d '{"video_url":"'"$VIDEO_URL"'","model":"Proteus","upscale_factor":3,"grain":0.03,"H264_output":true}'
```
4. Poll the returned `status_url` with backoff (5s → 10s, bounded max 60 polls) until `status === "COMPLETED"`, then fetch `response_url` and download `video.url`.

## 3. Sync Lipsync 2.0 Queue Pattern
1. Verify audio duration is within +/-5% of source video duration using `ffprobe`. Warn the user before submitting if delta exceeds 15% (do NOT blindly use `sync_mode: "remap"` on large mismatches).
2. Default `sync_mode: "cut_off"` (or `"silence"` when audio is slightly shorter than video):
```bash
curl -sS -X POST "https://queue.fal.run/fal-ai/sync-lipsync/v2" \
  -H "Authorization: Key $FAL_KEY" \
  -H "Content-Type: application/json" \
  -d '{"video_url":"'"$VIDEO_URL"'","audio_url":"'"$AUDIO_URL"'","sync_mode":"cut_off"}'
```

## 4. Re-Mux Master Audio & Verify Delivery Specs
Re-attach untouched 48 kHz WAV audio without re-encoding video frames (`-c:v copy`):
```bash
ffmpeg -y -i upscaled_4k.mp4 -i source_audio.wav \
  -map 0:v:0 -map 1:a:0 -c:v copy \
  -af "loudnorm=I=-14:TP=-1.0:LRA=11" -c:a aac -b:a 192k -ar 48000 \
  -shortest -movflags +faststart master_final.mp4
```
Verify `width`, `height`, `pix_fmt=yuv420p`, CFR frame rate, and `sample_rate=48000` with `ffprobe`.
