#!/usr/bin/env bash # ken-burns.sh — animate uniform scale + position on a video/image segment. # # Usage: # ken-burns.sh \ # \ # \ # \ # [easing] # # uniform scale values (1.0 = no zoom, 1.2 = 20% zoom-in) # horizontal position in half-canvas units (-1..1, 0 = center) # vertical position in half-canvas units (-1..1) # time string (e.g. 3s, 500ms) # [easing] linear | ease-in | ease-out | ease-in-out # default ease-out — the easing CapCut's own UI applies to # a ken-burns zoom ("Cubic Out") # # Writes 6 keyframes total via `capcut keyframe --batch`: uniform_scale, # position_x, position_y — each with a start keyframe at t=0 and an end # keyframe at t=duration. Keyframes for motion properties render correctly # in CapCut (unlike alpha — see pitfalls.md). set -euo pipefail if [[ $# -lt 9 || $# -gt 10 ]]; then echo "Usage: $0 [easing]" >&2 exit 2 fi project="$1" segment_id="$2" start_scale="$3" end_scale="$4" tx_start="$5" tx_end="$6" ty_start="$7" ty_end="$8" duration="$9" easing="${10:-ease-out}" script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Resolve how to launch the CLI, so this script also works when the skill is # used outside a capcut-cli checkout. A JavaScript entry runs under node; a # launcher (an npm shim, a .cmd wrapper, a shell script) runs as it is, since # node cannot execute it. Priority: # 1. $CAPCUT_CLI (explicit override: a .js entry or a launcher) # 2. /dist/index.js (this checkout) # 3. /node_modules/capcut-cli/dist/index.js, walking up from here # 4. capcut-cli / capcut on PATH (run as a launcher) cli_cmd=() resolve_cli() { local entry if [[ -n "${CAPCUT_CLI:-}" && -f "${CAPCUT_CLI}" ]]; then case "$CAPCUT_CLI" in *.js | *.mjs | *.cjs) cli_cmd=(node "$CAPCUT_CLI") ;; *) cli_cmd=("$CAPCUT_CLI") ;; esac return 0 fi entry="$script_dir/../../../dist/index.js" if [[ -f "$entry" ]]; then cli_cmd=(node "$entry") return 0 fi local dir="$script_dir" i for i in 1 2 3 4 5 6; do dir="$(dirname "$dir")" entry="$dir/node_modules/capcut-cli/dist/index.js" if [[ -f "$entry" ]]; then cli_cmd=(node "$entry") return 0 fi done for entry in capcut-cli capcut; do if command -v "$entry" >/dev/null 2>&1; then cli_cmd=("$(command -v "$entry")") return 0 fi done return 1 } if ! resolve_cli; then echo "capcut CLI not found — set \$CAPCUT_CLI to its dist/index.js or a launcher, install it (npm install -g capcut-cli), or run \`npm run build\` in capcut-cli/" >&2 exit 1 fi "${cli_cmd[@]}" keyframe "$project" "$segment_id" --batch --easing "$easing" <