# Recording to design system: the workflow

This folder is the reusable part. Point it at any screen recording (an app, a site, a motion piece) and it produces the raw material a design system is written from. The Wrapped study in this folder's parent was made with exactly these steps.

## What you need

- `ffmpeg` and `ffprobe`
- Python 3 with `numpy` and `opencv-python-headless` (set `DS_PY` to that interpreter)
- A recording at its native resolution and frame rate. Do not re-encode it first.

## The six passes

| Pass | What happens | Output |
|---|---|---|
| 1. Explode | `./run.sh <video> <work> <scale>` writes every frame twice (point size and full size), a timestamp per frame, per-frame motion numbers, and contact sheets | `work/frames`, `work/full`, `work/pts.txt`, `work/metrics.json`, `work/overview`, `work/dense` |
| 2. Survey | Read the overview sheets (one frame per second). List the scenes and cut the recording into segments of about 1,000 to 1,500 frames with a small overlap | A segment table |
| 3. Frame-by-frame | One reviewer per segment reads every dense sheet (all frames, 60 to a sheet) and measures with the tools below, following `BRIEF.md` | `work/scenes/<SEG>.md` |
| 4. Merge | Reconcile the segment reports into one list of consensus values. Where two segments disagree, re-measure | `merge-notes.md` |
| 5. Build | Write tokens, stylesheet, behaviours and one preview per component | `project/` |
| 6. Verify | Put each rebuilt piece next to the original frame at the same size. For motion, track the original per frame and fit the curve to the numbers | fixes to pass 5 |

`scale` is 3 for an @3x phone recording, 2 for @2x, 1 for a desktop capture. Everything downstream is in points.

## Tools

All take and print points. Set `DS_WORK` to the work folder and `DS_SCALE` to the scale. Run them with `python3 -I`.

| Tool | Use it for |
|---|---|
| `sheet.py` | Contact sheets of any frame range at any step |
| `zoom.py` | One or more full-resolution frames, optionally cropped: type, edges, texture |
| `strip.py` | A filmstrip of one region across consecutive frames: read an animation |
| `track.py` | Per-frame numbers for a region (position, size, colour): exact start and end frames, distance, easing |
| `colors.py` | Exact colour at a point, or a palette of a region |
| `motion.py` | Per-frame global change: find cuts, holds and the frames where something moves |
| `metrics.py` | Called by `run.sh`; the all-frame numbers `motion.py` reads |
| `tokens_to_css.py` | Compiles `tokens.json` to CSS custom properties for local previews |

## Rules that made the difference

- **Every frame, not a sample.** Entrances here last 5 to 40 frames. One frame per second misses all of them. The dense sheets exist so nothing is skipped.
- **Measure, then fit.** Track an element across its move, print the per-frame positions, and choose the cubic-bezier that reproduces those numbers. Curves picked by eye were wrong twice in this study.
- **Average over texture.** Grain and compression add a few units of noise. Sample the middle of thick strokes on full-opacity frames, two or three spots.
- **Type by metrics.** Cap height, x-height and the width of known strings identify a face and calibrate a stand-in. Do not trust the look alone.
- **Side by side or it did not happen.** A rebuilt component is done when a crop of it lines up with a crop of the frame.
- **Keep people out of it.** Recordings carry names and personal data. Reports and stills stay local; anything published uses invented content.

## Adapting BRIEF.md

`BRIEF.md` is the instruction sheet for pass 3. Its first two sections ("Goal" and "The material") describe this particular recording. For a new one, change the description, the frame size, the frame count and the list of things that are not part of the design (system status bar, recording indicators, browser chrome). Leave the tool list and the report format alone.

## Sources other than video

- **A website:** record a scroll-through and the key interactions at 60 fps, then run the same passes. Add the site's own CSS as a second source where you can read it; code beats pixels for exact values.
- **Static screens:** skip passes 1 and 3's motion work; `zoom.py` and `colors.py` still apply to screenshots placed in `work/full`.
