Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

TL7n: a composition's footage retouched. sdk/timeline's composition copies move into src/copies.ts (heard, steady and now retouch: Copied, CopyEdit, copyProps, copyEdits; read.ts extends and delegates to it, nothing new exported). A media row carries retouch (of and the amounts above 0) when its <Video> plays a retouched copy; its clip's props are its own file, the copy (retouched) and the four amounts, as a film's clip has them, and a set of those is the host's new retouch edit (raea-feed de9a67d: the host retouches the <Video>'s whole file into its media folder's retouch/ and the edit writes src={staticFile(copy)} data-retouch-of and data-retouch-<amount>, the src as it was when off). Held steady too, the retouch is made from the steadied copy and comes off to it, and the clip's steadied prop is that copy (the copy under the retouch); Stabilise is refused while Retouch is on. A real 3 s face clip retouched in 4.3 s, a face on all 90 frames, and raea's render of the edited composition is the copy's own frame (0 apart; the file's is 1.4). Copies, moves and mattes are read and made at the rate the frames' times sit on (a 30/1 clip probed 29.97 had made a copy that drew a frame behind). The manual's editor page regenerated (pbr.md's drift left out)

shinyobjectzafe2150d196b
diff --git a/docs/manual/reference/sdk/editor.md b/docs/manual/reference/sdk/editor.md
index 8f4c1905..69c50e2b 100644
--- a/docs/manual/reference/sdk/editor.md
+++ b/docs/manual/reference/sdk/editor.md
@@ -1031,8 +1031,9 @@ the lane it sits on (nested ones below their parent, overlapping ones apart), an
| `volume` | `number` | its media's level, 1 as recorded |
| `muted` | `boolean` | a <Video> whose own sound was taken out (muted): its sound is an <Audio> of its own |
| `file` | `string` | its media's file, a path in the composition's media folder (where its src is staticFile("…")) |
-| `heard` | `{ of: string; denoise?: boolean; voice?: string }` | that file is a copy of `of` with its noise reduced or its voice changed |
-| `steady` | `{ of: string; level: string }` | that file is a copy of `of` held steady at `level` |
+| `heard` | `{ of: string; denoise?: boolean; voice?: string }` | what it plays is a copy of `of` with its noise reduced or its voice changed (an <Audio>'s) |
+| `steady` | `{ of: string; level: string }` | what it plays is a copy of `of` held steady at `level` (a <Video>'s) |
+| `retouch` | `{ of: string; smooth?: number; brighten?: number; slim?: number; eyes?: number }` | what it plays is a copy of `of` with its faces retouched, each amount 0 to 1 (a <Video>'s): `of` is its file, or its steadied copy when it is held steady too (the retouch over the steadying) |
### `Showing`
diff --git a/docs/timeline.feature b/docs/timeline.feature
index 90bd2f4b..7f45f35f 100644
--- a/docs/timeline.feature
+++ b/docs/timeline.feature
@@ -60,7 +60,7 @@ Feature: The timeline SDK (0.1.5): CapCut's timeline, on the composition, in the
temperature, tint, fade, vignette, grain. Audio: volume, fades, noise reduction, voice changer. Text: font,
style, effects, bubbles, animation, and its words read aloud.
Here 11-14: Basic (TL3h, TL5) with stabilise (TL7k, a film's footage and a composition's <Video>), auto cutout
- of a person or the subject (TL7l, a film's footage, on a Mac) and a custom one brushed on the picture (TL7m), Retouch (TL7n: smooth, brighten, slim face and bigger eyes, a film's footage or a file from Media, on a Mac), Mask, chroma key and Blend (TL7f) with the key's colour picked from
+ of a person or the subject (TL7l, a film's footage, on a Mac) and a custom one brushed on the picture (TL7m), Retouch (TL7n: smooth, brighten, slim face and bigger eyes, a film's footage, a file from Media or a composition's <Video>, on a Mac), Mask, chroma key and Blend (TL7f) with the key's colour picked from
the picture (TL7h) and the mask's handles dragged there (TL7i), Animation (TL7d, TL7e), Speed (TL6), Audio's
volume and fades (TL8a) and its noise reduction and voice changer (TL8d, a film's sounds and a composition's
<Audio>), Text's words, styles and captions (TL7c) and its words read aloud (TL7j), Adjust as effect clips
@@ -231,7 +231,16 @@ Feature: The timeline SDK (0.1.5): CapCut's timeline, on the composition, in the
hides the film's picture only once the copy has the frame under the playhead (a copy loading shows
the film as shot); a clip coming on within a second has its copy loaded ahead; a file from Media plays
the copy, which carries its sound, instead of its file. On a 720 x 1280 talking-head clip 90 frames
- in 10.9 s, a face found on every one; asked again, the kept copy in 24 ms),
+ in 10.9 s, a face found on every one; asked again, the kept copy in 24 ms; in a composition, its
+ <Video>'s whole file retouched into its media folder's retouch/ (its steadied copy when it is held
+ steady: the retouch over the steadying, and Stabilise refused while Retouch is on, since what is under
+ it would change), which the <Video> plays, saying what it was made from and by how much
+ (data-retouch-of, data-retouch-smooth, -brighten, -slim and -eyes), off its src as it was; a real 3 s
+ face clip in 4.3 s, a face on all 90 frames, and raea's render of the edited composition is the copy's
+ own frame, 0 apart, where the file's is 1.4 (4.9 over the face). Copies, moves and mattes are read and
+ made at the rate the frames' times sit on (the probe's frame_rate) where it is within 1% of the
+ average: that clip's 30/1 probed 29.97 on average, and a copy made at that drew its frame 44 at the
+ composition's 45; each is named by that rate too, so a copy made at the old one isn't read again),
TL11a for easings, speed curves, transitions, effects, text styles, tools (presets put
on the picked clips) and snap grids as data (a clip let go 6 px past a plugin grid's mark lands on
it, under a browser test with the plugin installed; each e2e run now starts with no plugins
@@ -264,7 +273,8 @@ Feature: The timeline SDK (0.1.5): CapCut's timeline, on the composition, in the
split, delete written into the scene's own file, which the stage opens again (TL14c). A sound's
clips: span, place in the file, level (TL14b). An <Audio>'s sound from its copy with its noise
reduced or its voice changed: its src the copy, and data-voice-of, data-denoise and data-voice (TL8d).
- A <Video>'s footage from its steadied copy: its src the copy, and data-steady-of and data-steady (TL7k)
+ A <Video>'s footage from its steadied copy: its src the copy, and data-steady-of and data-steady (TL7k);
+ from its retouched copy, over the steadied one when both: data-retouch-of and the amounts (TL7n)
plays TL10a for a film's own frames: cuts, moves, trims, speeds, freezes and reversed footage at once, the
player's buffer on the ruler. TL10f: a timed 3D scene's frames are drawn ahead by the host a few
seconds at a time at draft quality and kept by range, each range under what it is drawn from (the
diff --git a/sdk/timeline/src/copies.ts b/sdk/timeline/src/copies.ts
new file mode 100644
index 00000000..8b41d6ea
--- /dev/null
+++ b/sdk/timeline/src/copies.ts
@@ -0,0 +1,64 @@
+// A composition's footage or sound played from a copy the host made of its file (raea docs/timeline.feature TL8d,
+// TL7k, TL7n): a sound with its noise reduced or its voice changed, footage held steady, footage with its faces
+// retouched. The element's src is the copy and its data-* props say what it was made from and how; its clip's props are
+// a film's for the same (its own file, the copy and the settings), and a set of those is the host's edit back.
+import { find, type Timeline, type Value } from "./model"
+import type { Op } from "./ops"
+
+/** What a copy was made from (`of`, a path in the composition's media folder) and how, as the host reads its element. */
+export interface Copied {
+ /** what it plays is a copy of `of` with its noise reduced or its voice changed (an <Audio>'s) */
+ heard?: { of: string; denoise?: boolean; voice?: string }
+ /** what it plays is a copy of `of` held steady at `level` (a <Video>'s) */
+ steady?: { of: string; level: string }
+ /** what it plays is a copy of `of` with its faces retouched, each amount 0 to 1 (a <Video>'s): `of` is its file, or
+ * its steadied copy when it is held steady too (the retouch over the steadying) */
+ retouch?: { of: string; smooth?: number; brighten?: number; slim?: number; eyes?: number }
+}
+
+/** The host's edits that set what an element plays: `file`, a copy of `of` made so; no `of`, `file` as it is. */
+export type CopyEdit =
+ | { op: "heard"; i: number; file: string; of?: string; denoise?: boolean; voice?: string }
+ | { op: "steady"; i: number; file: string; of?: string; level?: string }
+ | { op: "retouch"; i: number; file: string; of?: string; smooth?: number; brighten?: number; slim?: number; eyes?: number }
+
+const RETOUCH = { smooth: "retouchSmooth", brighten: "retouchBrighten", slim: "retouchSlim", eyes: "retouchEyes" } as const
+
+/** A media element's clip props: its own file, and the copy it plays with what was done to it (steadied under a
+ * retouch: the copy the retouch was made from). */
+export function copyProps(file: string, r: Copied): Record<string, Value | boolean> {
+ const own = r.heard?.of ?? r.steady?.of ?? r.retouch?.of ?? file
+ return {
+ file: own,
+ ...(r.heard && { voiced: file, denoise: !!r.heard.denoise, voice: r.heard.voice ?? "" }),
+ ...(r.steady && { stabilise: r.steady.level, steadied: r.retouch?.of ?? file }),
+ ...(r.retouch && { retouched: file, ...Object.fromEntries(Object.entries(RETOUCH).map(([k, p]) => [p, r.retouch![k as keyof typeof RETOUCH] ?? 0])) }),
+ }
+}
+
+/** The host's edits for a set of copy props on media clips `ids` (each `i` its element's place), or undefined when `op`
+ * isn't one: a sound's voice (TL8d), footage held steady (TL7k) or retouched (TL7n). */
+export function copyEdits(t: Timeline, op: Op, ids: string[], place: (id: string) => number | undefined): CopyEdit[] | undefined {
+ const p = op.op === "set" && Object.keys(op.set).join() === "props" ? op.set.props : undefined
+ if (!p) return undefined
+ const of = (id: string) => find(t, id)?.clip.props?.file
+ const has = (kind: string, keys: string[]) => Object.keys(p).every((k) => keys.includes(k)) && ids.every((id) => find(t, id)?.clip.kind === kind && typeof of(id) === "string" && place(id) !== undefined)
+ const each = (f: (i: number, own: string) => CopyEdit) => ids.map((id) => f(place(id)!, of(id) as string))
+ // a retouch is made from what plays under it: its steadied copy, when it is held steady
+ const under = (id: string) => {
+ const s = find(t, id)?.clip.props?.steadied
+ return typeof s === "string" && s ? s : (of(id) as string)
+ }
+ if (has("audio", ["denoise", "voice", "voiced"]))
+ return each((i, own) => (p.voiced ? { op: "heard", i, file: String(p.voiced), of: own, ...(p.denoise === true && { denoise: true }), ...(p.voice && { voice: String(p.voice) }) } : { op: "heard", i, file: own }))
+ if (has("video", ["stabilise", "steadied", "stabiliseZoom"]))
+ return each((i, own) => (p.steadied ? { op: "steady", i, file: String(p.steadied), of: own, level: String(p.stabilise ?? "") } : { op: "steady", i, file: own }))
+ if (has("video", [...Object.values(RETOUCH), "retouched", "retouchFrom", "retouchTo"]))
+ return ids.map((id) => {
+ const i = place(id)!, from = under(id)
+ if (!p.retouched) return { op: "retouch", i, file: from }
+ const amounts = Object.entries(RETOUCH).flatMap(([k, prop]) => (typeof p[prop] === "number" && (p[prop] as number) > 0 ? [[k, p[prop] as number]] : []))
+ return { op: "retouch", i, file: String(p.retouched), of: from, ...Object.fromEntries(amounts) }
+ })
+ return undefined
+}
diff --git a/sdk/timeline/src/read.ts b/sdk/timeline/src/read.ts
index 499f9d25..da19a46a 100644
--- a/sdk/timeline/src/read.ts
+++ b/sdk/timeline/src/read.ts
@@ -8,6 +8,7 @@ import { EFFECTS, type EffectPart, type TextStyle, textStyleError } from "./regi
import { COMBO_KINDS, TRANSITION_KINDS } from "@raea/video/edges"
import { CUTOUT_PROPS, cutoutError, cutoutOf, cutoutProps, KEY_PROPS, MASK_PROPS, type Blend, type ChromaKey, type Mask } from "./cutout"
import { ADJUST_KINDS, ADJUST_PROP_LIST, ADJUST_PROPS, adjustError, adjustOf, type Adjust } from "./adjust"
+import { type Copied, copyEdits, type CopyEdit, copyProps } from "./copies"
/** A text clip's style, kept in its props as JSON: read back when it is well formed. */
export function textStyleOf(v: unknown): TextStyle | undefined {
@@ -34,7 +35,7 @@ export function effectParts(v: unknown): EffectPart[] | undefined {
/** A <Sequence> as the host lists it: its place among the file's elements, its span in the composition's frames,
* the lane it sits on (nested ones below their parent, overlapping ones apart), and why it can't be rewritten. */
-export interface SeqRow {
+export interface SeqRow extends Copied {
/** its place among the file's <Sequence> elements, in source order: what an edit names it by */
i: number
/** its name prop, or what the host calls it when it has none */
@@ -80,10 +81,6 @@ export interface SeqRow {
muted?: boolean
/** its media's file, a path in the composition's media folder (where its src is staticFile("…")) */
file?: string
- /** that file is a copy of `of` with its noise reduced or its voice changed (TL8d) */
- heard?: { of: string; denoise?: boolean; voice?: string }
- /** that file is a copy of `of` held steady at `level` (TL7k) */
- steady?: { of: string; level: string }
}
/** A sequence's still placement: its <Nudge>'s props (sdk/video nudge.tsx). `crop` is left, top, right, bottom. */
export interface SeqLook {
@@ -140,10 +137,8 @@ export type SeqEdit =
| { op: "edge"; i: number; side: "in" | "out" | "combo"; kind: string; frames: number }
/** a <Video>'s or an <Audio>'s own level (TL8a) */
| { op: "level"; i: number; volume: number }
- /** an <Audio> played from `file`, a copy of `of` with its noise reduced or its voice changed; no `of`, `file` as it is (TL8d) */
- | { op: "heard"; i: number; file: string; of?: string; denoise?: boolean; voice?: string }
- /** a <Video> played from `file`, a copy of `of` held steady at `level`; no `of`, `file` as it is (TL7k) */
- | { op: "steady"; i: number; file: string; of?: string; level?: string }
+ /** a <Video> or an <Audio> played from a copy of its file made on the host (copies.ts: TL8d, TL7k, TL7n) */
+ | CopyEdit
/** a <Video>'s own sound taken out (TL4c): the <Video> muted, and an <Audio> of the same file, from the same place
* at the same pace and level, in a new sequence from `at` for `frames` after the composition's last */
| { op: "extract"; i: number; at: number; frames: number }
@@ -218,7 +213,7 @@ export function fromSequences(rows: SeqRow[], fps: number): Timeline {
const mediaTracks = (kind: "video" | "audio"): Track[] => {
const out: Track[] = []
for (const r of media.filter((m) => m.media === kind).sort((a, b) => a.from - b.from)) {
- const c: Clip = { id: seqId(r.i), kind, name: r.label ?? r.name, start: r.from, length: Math.max(1, r.to - r.from), in: r.startFrom ?? 0, ...(r.speed && r.speed !== 1 && { speed: r.speed }), ...(r.volume !== undefined && { volume: r.volume }), ...(r.muted && kind === "video" && { muted: true }), ...(r.locked && { locked: r.locked }), ...(r.file && { props: { file: r.heard?.of ?? r.steady?.of ?? r.file, ...(r.heard && { voiced: r.file, denoise: !!r.heard.denoise, voice: r.heard.voice ?? "" }), ...(r.steady && { stabilise: r.steady.level, steadied: r.file }) } }) }
+ const c: Clip = { id: seqId(r.i), kind, name: r.label ?? r.name, start: r.from, length: Math.max(1, r.to - r.from), in: r.startFrom ?? 0, ...(r.speed && r.speed !== 1 && { speed: r.speed }), ...(r.volume !== undefined && { volume: r.volume }), ...(r.muted && kind === "video" && { muted: true }), ...(r.locked && { locked: r.locked }), ...(r.file && { props: copyProps(r.file, r) }) }
const home = out.find((k) => k.clips.every((o) => end(o) <= c.start || o.start >= end(c)))
if (home) home.clips.push(c)
else out.push({ id: `${kind === "audio" ? "sound" : "footage"}-${out.length + 1}`, kind: kind === "audio" ? "sound" : "overlay", name: kind === "audio" ? "Sound" : "Footage", clips: [c] })
@@ -279,11 +274,9 @@ export function seqEdits(t: Timeline, op: Op): SeqEdit[] | { why: string } {
}
if (ids.some(isMedia)) {
if (op.op === "set" && Object.keys(op.set).filter((k) => op.set[k as keyof typeof op.set] !== undefined).join() === "volume") return ids.flatMap((id) => { const i = seqOf(id); return i === undefined ? [] : [{ op: "level", i, volume: Math.round(Math.max(0, op.set.volume!) * 1000) / 1000 } as SeqEdit] })
- // a copy made on the host, a sound's (TL8d) or footage held steady (TL7k): its element plays it, and says what it was made from and how
- const p = op.op === "set" && Object.keys(op.set).join() === "props" ? op.set.props : undefined, has = (kind: string, keys: string[]) => p && Object.keys(p).every((k) => keys.includes(k)) && ids.every((id) => find(t, id)?.clip.kind === kind && typeof find(t, id)?.clip.props?.file === "string")
- const each = (f: (i: number, of: string) => SeqEdit) => ids.map((id) => f(seqOf(id)!, find(t, id)!.clip.props!.file as string))
- if (p && has("audio", ["denoise", "voice", "voiced"])) return each((i, of) => (p.voiced ? { op: "heard", i, file: String(p.voiced), of, ...(p.denoise === true && { denoise: true }), ...(p.voice && { voice: String(p.voice) }) } : { op: "heard", i, file: of }))
- if (p && has("video", ["stabilise", "steadied", "stabiliseZoom"])) return each((i, of) => (p.steadied ? { op: "steady", i, file: String(p.steadied), of, level: String(p.stabilise ?? "") } : { op: "steady", i, file: of }))
+ // a copy made on the host (a sound's voice, footage held steady or retouched): its element plays it (copies.ts)
+ const copied = copyEdits(t, op, ids, seqOf)
+ if (copied) return copied
return { why: "footage and sound play where their sequence does: move, trim or speed the sequence; here only its level and a sound's voice are its own" }
}
const each = (ids: string[], f: (r: { i: number; clip: Clip }) => SeqEdit): SeqEdit[] | { why: string } => {
diff --git a/sdk/timeline/test/read.test.ts b/sdk/timeline/test/read.test.ts
index 0a4ef524..cf743a36 100644
--- a/sdk/timeline/test/read.test.ts
+++ b/sdk/timeline/test/read.test.ts
@@ -156,6 +156,26 @@ describe("TL0c: a timeline is read from a composition", () => {
expect(seqEdits(t, { op: "set", id: "seq-4", set: { props: { voice: "deep", voiced: "voice/x.wav" } } })).toHaveProperty("why")
})
+ test("footage retouched is its <Video> playing a retouched copy, made over its steadied one when it is held steady (TL7n)", () => {
+ const take = { i: 4, name: "Video", label: "take.mp4", from: 90, to: 180, lane: 0, media: "video" as const, startFrom: 30, file: "take.mp4" }
+ const t = fromSequences([...rows, take], 30)
+ const on = (path: string) => ({ op: "set" as const, id: "seq-4", set: { props: { retouchSmooth: 0.4, retouchBrighten: 0, retouchSlim: 0, retouchEyes: 0.25, retouched: path, retouchFrom: 0, retouchTo: 0 } } })
+ const off = { op: "set" as const, id: "seq-4", set: { props: { retouchSmooth: 0, retouchBrighten: 0, retouchSlim: 0, retouchEyes: 0, retouched: "", retouchFrom: 0, retouchTo: 0 } } }
+ // (amounts of 0 aren't sent)
+ expect(seqEdits(t, on("retouch/take-0123456789.mp4"))).toEqual([{ op: "retouch", i: 4, file: "retouch/take-0123456789.mp4", of: "take.mp4", smooth: 0.4, eyes: 0.25 }])
+ const back = fromSequences([...rows, { ...take, file: "retouch/take-0123456789.mp4", retouch: { of: "take.mp4", smooth: 0.4, eyes: 0.25 } }], 30)
+ expect(find(back, "seq-4")!.clip.props).toEqual({ file: "take.mp4", retouched: "retouch/take-0123456789.mp4", retouchSmooth: 0.4, retouchBrighten: 0, retouchSlim: 0, retouchEyes: 0.25 })
+ expect(seqEdits(back, off)).toEqual([{ op: "retouch", i: 4, file: "take.mp4" }])
+ // held steady too: the retouch is made from the steadied copy and comes off to it; the clip's own file is still take.mp4
+ const both = fromSequences([...rows, { ...take, file: "retouch/s-fedcba9876.mp4", steady: { of: "take.mp4", level: "most" }, retouch: { of: "steady/take-most-0123456789.mp4", smooth: 0.5 } }], 30)
+ expect(find(both, "seq-4")!.clip.props).toMatchObject({ file: "take.mp4", stabilise: "most", steadied: "steady/take-most-0123456789.mp4", retouched: "retouch/s-fedcba9876.mp4", retouchSmooth: 0.5 })
+ expect(seqEdits(both, off)).toEqual([{ op: "retouch", i: 4, file: "steady/take-most-0123456789.mp4" }])
+ const held = fromSequences([...rows, { ...take, file: "steady/take-most-0123456789.mp4", steady: { of: "take.mp4", level: "most" } }], 30)
+ expect(seqEdits(held, on("retouch/s-fedcba9876.mp4"))).toEqual([{ op: "retouch", i: 4, file: "retouch/s-fedcba9876.mp4", of: "steady/take-most-0123456789.mp4", smooth: 0.4, eyes: 0.25 }])
+ // a sound isn't retouched
+ expect(seqEdits(fromSequences([...rows, { ...take, name: "Audio", media: "audio" as const }], 30), on("retouch/x.mp4"))).toHaveProperty("why")
+ })
+
test("a file of the project's is a new sequence holding it; on the magnet's main track the clips after it move on and it goes in beside the one before it (TL3j)", () => {
const t = fromSequences(rows, 30)
const add = (kind: string, track: string, start: number, length: number, asset = "/p/media/beach.mp4") => seqEdits(t, { op: "add", kind: track, clip: { id: "m", kind, name: "beach.mp4", start, length, ...(kind !== "image" && { in: 0, source: length }), props: { asset } } })