---
name: studio-character-loop
description: Build a seamless looping character animation (idle, flap, hover, bob) from phase-driven motion channels, then export clean MP4, WebM alpha, GIF or sprite sheet. Use for "make a looping animation", "animated mascot", "idle loop", "seamless loop", "character GIF".
version: "1.1.0"
category: build
platforms: [CLAUDE_CODE, CURSOR, CODEX_CLI]
---

# Character animation loops

A good loop is a function of one normalized phase `t` in `[0, 1)`. Every channel (wing angle, body bob, squash, orbit, blink) samples that phase, so the last frame flows into the first with no pop. This skill covers procedural loops (SVG, Canvas, Remotion, Three.js, Blender) and the export path.

## When to use

- A mascot, creature or object needs an idle, hover, flap, breathe or walk-in-place loop.
- A hero animation must loop forever on a landing page, in a README GIF or as a sticker.
- Not for one-shot reveals with a clear start and end (use a title sequence approach instead).

## Agree on inputs first

| Input         | Typical default                                    |
| ------------- | -------------------------------------------------- |
| Loop duration | 1 to 4 s (idle 2 to 4 s, flap 0.5 to 1 s)          |
| Frame rate    | 30 fps web, 24 fps stylized, 12 fps "on twos" look |
| Canvas        | 1080x1080, 512x512 sticker, 1080x1920 vertical     |
| Background    | Solid color, or transparent (alpha)                |
| Deliverables  | MP4 + poster PNG, WebM alpha, GIF, sprite sheet    |
| Beats         | Number of accents per loop, e.g. 2 flaps per 2 s   |

Frame count = duration x fps, and it must be an integer. 2 s at 30 fps is 60 frames, numbered 0 to 59. Frame 60 equals frame 0 and must not be rendered.

## Toolchain

- **Remotion (React)**: best for web-native, typed, reviewable code. `useCurrentFrame()` plus `durationInFrames`.
- **Canvas or SVG + headless capture**: Node script that draws each frame to PNG (node-canvas or Playwright screenshots).
- **Blender (bpy)**: for 3D characters. Use drivers or F-curve Cycles modifiers so channels repeat.
- **Three.js**: realtime web loops, `clock.getElapsedTime() % duration`.
- **FFmpeg**: encode and verify every output.

## Workflow

### 1. Rig the channels

Pick a pivot per part (wing root, hip, head base) and author local coordinates relative to it. Mirror symmetric parts by negating local x around the pivot, not by duplicating art.

```ts
const TAU = Math.PI * 2;
const t = frame / durationInFrames; // 0..1, never reaches 1
const wing = 35 * Math.sin(TAU * 2 * t); // 2 flaps per loop
const bob = -6 * Math.sin(TAU * 2 * t - 0.6); // lags wing (overlap)
const squash = 1 + 0.04 * Math.cos(TAU * 2 * t);
const drift = 10 * Math.sin(TAU * 1 * t); // slower secondary
```

Rules:

- Every channel frequency is an integer multiple of the loop (1, 2, 3 cycles). A frequency like 1.5 breaks the seam.
- Use phase offsets (the `- 0.6`) for follow-through and overlap. Secondary parts lag primary parts by 0.1 to 0.25 of a cycle.
- Preserve volume on squash: `scaleY = s`, `scaleX = 1 / s`.
- For non-sinusoidal easing, feed a periodic ramp through an ease: `ease((t * k) % 1)`, and check that the value at 0 equals the value at 1.
- Blinks: a short pulse at a fixed phase window, e.g. closed while `0.62 < t < 0.66`. Keep it identical every loop or the eye reads as a glitch.

### 2. Contact sheet before video

Render 8 to 12 evenly spaced frames into one grid and review poses statically.

```bash
ffmpeg -i frames/%04d.png -vf "select='not(mod(n\,6))',scale=320:-1,tile=5x2" -frames:v 1 contact.png
```

Check silhouette legibility at each key pose, that extremes look intentional, and that no part detaches from its pivot.

### 3. Render

Remotion:

```bash
npx remotion render src/index.ts CharacterLoop out/loop.mp4 --codec=h264 --crf=18
npx remotion render src/index.ts CharacterLoop out/loop.webm --codec=vp9 --image-format=png --pixel-format=yuva420p
npx remotion still src/index.ts CharacterLoop out/poster.png --frame=0
```

Blender (bpy), making an F-curve repeat:

```python
import bpy
scn = bpy.context.scene
scn.frame_start, scn.frame_end = 1, 60   # 60 frames; key frame 61 == frame 1 for the cycle
for fc in obj.animation_data.action.fcurves:
    fc.modifiers.new(type='CYCLES')
scn.render.film_transparent = True       # alpha output
scn.render.image_settings.file_format = 'PNG'
scn.render.image_settings.color_mode = 'RGBA'
```

Key the loop end pose on frame 61 (identical to frame 1) but render only 1 to 60.

### 4. Encode variants from a PNG sequence

```bash
# Web MP4 (no alpha), autoplay-safe
ffmpeg -framerate 30 -i frames/%04d.png -c:v libx264 -crf 18 -preset slow \
  -pix_fmt yuv420p -movflags +faststart -an loop.mp4

# Transparent WebM (Chrome, Firefox)
ffmpeg -framerate 30 -i frames/%04d.png -c:v libvpx-vp9 -pix_fmt yuva420p \
  -b:v 0 -crf 30 -row-mt 1 -auto-alt-ref 0 loop.webm

# Transparent ProRes 4444 for editors (and HEVC alpha source for Safari)
ffmpeg -framerate 30 -i frames/%04d.png -c:v prores_ks -profile:v 4444 \
  -pix_fmt yuva444p10le -alpha_bits 16 loop.mov

# High quality GIF with a generated palette
ffmpeg -framerate 30 -i frames/%04d.png -vf \
 "fps=15,scale=480:-1:flags=lanczos,split[a][b];[a]palettegen=reserve_transparent=1:stats_mode=diff[p];[b][p]paletteuse=dither=bayer:bayer_scale=3:alpha_threshold=128" \
 -loop 0 loop.gif

# Sprite sheet (10 columns)
ffmpeg -framerate 30 -i frames/%04d.png -vf "tile=10x6" -frames:v 1 sheet.png
```

Safari needs HEVC with alpha for transparent video. On macOS: `avconvert` or `ffmpeg -c:v hevc_videotoolbox -alpha_quality 0.75 -tag:v hvc1` from the ProRes 4444 master. Serve with `<video autoplay muted loop playsinline>` and two `<source>` tags (HEVC first, then WebM).

When dropping fps for GIF, choose a rate that divides the frame count evenly (60 frames at 30 fps to 15 fps gives 30 frames) or the seam will stutter.

## Common variants

- **Vertical 9:16**: 1080x1920; keep the character in the middle 1080x1350 so feed crops (4:5) still show it.
- **Sticker / emoji**: 512x512, transparent, 3 s max, WebM VP9 under 256 KB for messaging platforms.
- **On twos**: render 12 fps worth of poses but hold each for 2 frames: `Math.floor(frame / 2) * 2`.
- **Ping-pong**: only when motion is symmetric; otherwise a loop with integer frequencies reads more naturally.
- **Reduced motion**: ship the poster frame as the static fallback under `prefers-reduced-motion: reduce`.

## Quality checks

```bash
ffprobe -v error -select_streams v:0 -count_frames \
  -show_entries stream=width,height,r_frame_rate,nb_read_frames,pix_fmt -of csv=p=0 loop.mp4
```

- Frame count equals duration x fps exactly (60, not 61).
- Seam test: the difference between the last frame and frame 0 should be about the same size as between any two neighbors. Compute it:
  `ffmpeg -i frames/0059.png -i frames/0000.png -lavfi ssim -f null -` and compare to the SSIM of frames 0000 vs 0001. The seam must not be noticeably lower.
- Play the output looped for at least 3 cycles (`ffplay -loop 0 loop.mp4`) and watch only the boundary.
- Silhouette: the poster frame reads at 64 px tall.
- Alpha: `ffprobe` shows `yuva420p` for WebM or `yuva444p10le` for ProRes; check edges on both black and white backgrounds for halos.
- No flashing over 3 times per second (WCAG 2.3.1).
- File size: web MP4 loop under 1 MB, GIF under 3 MB where possible.

## Pitfalls and fixes

| Problem                        | Fix                                                                                               |
| ------------------------------ | ------------------------------------------------------------------------------------------------- |
| Visible hitch at the seam      | Duplicated endpoint frame; sample `frame / N`, not `frame / (N - 1)`                              |
| Pop at the seam on one part    | A channel uses a non-integer cycle count, or `Math.random()` without a seed                       |
| Mechanical, robotic motion     | Add phase lag to secondary parts, ease the extremes, vary amplitudes                              |
| Dark fringe around alpha edges | Premultiplied vs straight mismatch; render straight alpha PNG, or unpremultiply in the compositor |
| GIF banding or noise           | Use palettegen/paletteuse with `stats_mode=diff`; reduce colors in the art                        |
| Video won't autoplay on iOS    | Needs `muted playsinline`, and no audio track (`-an`)                                             |
| Blender loop jumps             | Interpolation overshoot at the ends; key frame N+1 identical to frame 1 and add a Cycles modifier |

## Deliverables

- [ ] Source (Remotion composition, script or .blend) with phase constants documented at the top
- [ ] Contact sheet PNG of key poses
- [ ] Poster PNG (frame 0) for static and reduced motion use
- [ ] MP4 H.264 yuv420p faststart, and alpha variants if requested (WebM VP9, ProRes 4444, HEVC alpha)
- [ ] GIF or sprite sheet if requested, with frame size, count and fps noted
- [ ] ffprobe output confirming dimensions, fps and frame count

[Moth Signal reference](https://skills-hub.ai/showcases/projects/moth-signal)
