Skip to content

programmatic video rendering framework that is actually fast

docs(skill): overlap timing, scene names and video frames in shaders (#186)

Dmitriy Kovalenko1d7d0ea288cf
diff --git a/skills/fframes-video/SKILL.md b/skills/fframes-video/SKILL.md
index 7aeea802..6227f809 100644
--- a/skills/fframes-video/SKILL.md
+++ b/skills/fframes-video/SKILL.md
@@ -190,7 +190,8 @@ impl Video for MyVideo<'_> {
- Measure text rather than guess: `frame.text_width`, `frame.text_fit(.., TextOverflow::Ellipsis)`,
`frame.text_break_lines` for paragraphs. `inspect` catches text leaving the canvas, not text
leaving its own box, so check boxes in a `frame` PNG.
-- GPU shaders (SkSL or Shadertoy GLSL) run on the Skia backend through `fframes::Shader`; see
+- GPU shaders (SkSL or Shadertoy GLSL) run on the Skia backend through `fframes::Shader`; they
+ take images and synced video frames as input (green-screen keying, color grading). See
`references/api.md`.
## 5. Making it look good
@@ -202,8 +203,9 @@ The short version of `references/design.md`:
- Elements enter with a spring or ease-out over 300-600 ms and leave faster, with ease-in over
200-300 ms. Related items stagger by 60-120 ms. Give the viewer 1-2 s to read after the
motion settles, and never move everything at once.
-- Cross-fade scenes (`fn overlap(&self) -> Overlap { Overlap::Previous(0.4) }`) or carry an
- element across the cut. Keep a little motion during holds so they do not look frozen.
+- Cross-fade scenes (`fn overlap(&self) -> Overlap { Overlap::Previous(0.4) }`; the overlap
+ is added to the scene's `duration()`, see `references/api.md`) or carry an element across
+ the cut. Keep a little motion during holds so they do not look frozen.
- At 1920x1080: titles 96-140 px, body 44-60 px, at most about 8 words per line and 3 lines per
card. Portrait 1080x1920 is watched on a phone: same pixel sizes or larger, content inside
the middle 80% because platform UI covers the top and bottom.
diff --git a/skills/fframes-video/references/api.md b/skills/fframes-video/references/api.md
index f3ca4e2e..dff982de 100644
--- a/skills/fframes-video/references/api.md
+++ b/skills/fframes-video/references/api.md
@@ -55,7 +55,14 @@ impl Scene for Intro<'_> {
```
- Scenes must be zero sized or fields of the video (`&self.intro`). Scene names in the CLI
- are the struct names (`Intro`, `IntroScene` both match `IntroScene`).
+ are the struct names (`Intro`, `IntroScene` both match `IntroScene`). Override
+ `fn name(&self) -> &'static str` to name scenes yourself, e.g. one `Shot { kind }` struct
+ used for every scene and still addressed as `Smooch@2s` in the CLI.
+- `Overlap` is added on top of `duration()`: with `Overlap::Previous(0.5)` the scene starts
+ 0.5 s before the previous one ends and runs `duration() + 0.5` s. To land scene `i` on a cue
+ (a lyric, a beat) after a 0.5 s transition, use `duration = cue[i + 1] - cue[i]` and
+ `Overlap::Previous(0.5)`; the scene then covers `cue[i] - 0.5 .. cue[i + 1]`. Check with
+ `timeline`.
- `ctx.render_scenes(&frame)` in the video's `render_frame` renders the active scene(s).
- `frame.index` / `frame.seconds()` are scene relative inside a scene; `frame.global_index`
is the video frame. `ctx.get_scene_info(&self.intro)` gives a scene's resolved range.
@@ -142,6 +149,25 @@ fframes::svgr!(<image href={layer.href()} x="0" y="0" width="1920" height="1080"
- Built-in uniforms when declared: `iResolution` (the `<image>` size), `iTime`, `iTimeDelta`,
`iFrame`. Pass images with `.image("iChannel0", photo)` where `photo` comes from
`ctx.get_image("photo.jpg")` (an `Option`: return `Svgr::empty()` when it is missing).
+- A synced video frame is an image too, so shaders can process footage on the GPU, e.g. a
+ green-screen key (bind the `SyncVideoFrameInput` to a variable first, the frame borrows it):
+
+```rust
+let input = SyncVideoFrameInput { start_from: 0., looping: false, editor_fallback_image: None };
+let Some(clip) = frame.get_synced_video_frame(ctx, "clip.mp4", &input) else { return Svgr::empty() };
+let layer = self.chroma.draw(&frame, ShaderUniforms::new()
+ .image("uSrc", &clip.into_image())
+ .float2("uSrcSize", clip.width() as f32, clip.height() as f32));
+```
+
+```glsl
+uniform float3 iResolution; uniform shader uSrc; uniform float2 uSrcSize;
+half4 main(float2 coord) {
+ half4 c = uSrc.eval(coord / iResolution.xy * uSrcSize); // source pixels
+ float a = 1.0 - smoothstep(0.06, 0.2, c.g - max(c.r, c.b)); // green dominance
+ return half4(c.rgb * a, a); // premultiplied
+}
+```
- SkSL follows GLSL ES 2: constant loop bounds, no `while`, no dynamic array indexing, no
preprocessor. `Shader::shadertoy` expands simple `#define`s; rewrite macros with arguments
and `texture()` calls.