Skip to content

programmatic video rendering framework that is actually fast

test(e2e): compare key frames of every example on CPU, Skia CPU and Skia GPU (#205)

Dmitriy Kovalenko36af8f36edcd
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 2f55091b..cb7c1b96 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -327,8 +327,7 @@ jobs:
CARGO_PROFILE_DEV_DEBUG: 0
CARGO_PROFILE_TEST_DEBUG: 0
# Windows links a prebuilt FFmpeg instead of compiling it (see README). The
- # codec features of the examples request a from-source build, so only the
- # core crates are built here.
+ # examples are built by the e2e job.
FFMPEG_BUILD: ffmpeg-n9.0-latest-win64-gpl-shared-9.0
PACKAGES: -p fframes -p fframes-media -p webvtt-parser -p fframes-media-dir-macro -p svgr-macro -p e2e-tests
steps:
@@ -363,3 +362,90 @@ jobs:
- name: Render a video
run: cargo test -p e2e-tests --test render_smoke -- --nocapture
+
+ # Key frames of every example, rendered through its command line by the CPU backend and by
+ # Skia on the CPU and on the GPU (Metal on macOS, lavapipe Vulkan on Linux and Windows), all
+ # compared with the same images in e2e/snapshots.
+ e2e:
+ name: E2E frames (${{ matrix.os }})
+ strategy:
+ fail-fast: false
+ matrix:
+ os: [ubuntu-latest, macos-latest, windows-latest]
+ runs-on: ${{ matrix.os }}
+ defaults:
+ run:
+ shell: bash
+ env:
+ CARGO_INCREMENTAL: 0
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+ with:
+ persist-credentials: false
+
+ - name: Install apt-deps
+ if: runner.os == 'Linux'
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y llvm nasm yasm libx264-dev libx265-dev libvpx-dev libopus-dev \
+ libfontconfig1-dev libasound2-dev libwayland-dev mesa-vulkan-drivers libvulkan1
+
+ - name: Install brew deps
+ if: runner.os == 'macOS'
+ run: brew install pkg-config nasm x264 x265 libvpx opus
+
+ - name: Install FFmpeg 9
+ if: runner.os == 'Windows'
+ env:
+ FFMPEG_BUILD: ffmpeg-n9.0-latest-win64-gpl-shared-9.0
+ run: |
+ TMP_DIR="$(cygpath -u "$RUNNER_TEMP")"
+ curl -fsSL -o "$TMP_DIR/ffmpeg.zip" \
+ "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/$FFMPEG_BUILD.zip"
+ 7z x "$TMP_DIR/ffmpeg.zip" -o"$TMP_DIR" > /dev/null
+ FFMPEG_DIR="$(cygpath -w "$TMP_DIR/$FFMPEG_BUILD")"
+ echo "FFMPEG_DIR=$FFMPEG_DIR" >> "$GITHUB_ENV"
+ echo "$FFMPEG_DIR\bin" >> "$GITHUB_PATH"
+ echo "LIBCLANG_PATH=C:\Program Files\LLVM\bin" >> "$GITHUB_ENV"
+
+ - name: Install the Vulkan loader and lavapipe
+ if: runner.os == 'Windows'
+ uses: jakoch/[email protected]
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ install_runtime_only: true
+ install_lavapipe: true
+
+ - uses: actions-rust-lang/setup-rust-toolchain@v1
+ with:
+ cache-key: "v1-e2e"
+ cache-save-if: ${{ github.ref == 'refs/heads/main' }}
+
+ - uses: pnpm/action-setup@v4
+
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 24
+
+ - name: Install odiff
+ run: pnpm install --frozen-lockfile --filter fframes-root
+
+ - name: CPU
+ run: node scripts/e2e.mjs cpu
+
+ - name: Skia CPU
+ if: ${{ !cancelled() }}
+ run: node scripts/e2e.mjs skia-cpu
+
+ - name: Skia GPU
+ if: ${{ !cancelled() }}
+ run: node scripts/e2e.mjs gpu
+
+ - name: Upload frames and diffs
+ uses: actions/upload-artifact@v4
+ if: failure()
+ with:
+ name: e2e-${{ runner.os }}
+ if-no-files-found: ignore
+ path: target/e2e
diff --git a/AGENTS.md b/AGENTS.md
index 1bc5fee1..0c1aa400 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -206,6 +206,9 @@ let make = (~prop1: type1, ~prop2: type2) => {
- Unit tests in `#[cfg(test)] mod tests` blocks
- Integration tests in `/e2e/tests/`
- Visual regression tests compare rendered frames using `odiff`
+- `just e2e cpu|skia-cpu|gpu` renders key frames of every example through its CLI and compares
+ them with `e2e/snapshots`, the same images for every renderer; pass `--update` after an
+ intended change and commit the new PNGs
**Running specific tests:**
@@ -607,9 +610,10 @@ See `examples/teej-podcast/src/main.rs`; `cargo fframes new` generates the same
| `preview [TIME] [--paused] [--mute]` | real-time GPU window (`fframes_native_player`), blocks until closed |
Global flags: `--json` (one JSON document on stdout, JSON progress events on stderr),
-`--scale 0.5`. Times: frames `120`, `3.2s`, `1:05`, `50%`, `start`/`end`, scenes `Intro`
-(`IntroScene` also matches), `#3`, `Intro[1]`, `[email protected]`/`@50%`/`@end`; ranges `a..b`,
-`a..`, `..b`, `all` or a scene name.
+`--scale 0.5`, `--renderer cpu|skia-cpu|gpu` (another backend for this run, see below).
+Times: frames `120`, `3.2s`, `1:05`, `50%`, `start`/`end`, scenes `Intro` (`IntroScene` also
+matches), `#3`, `Intro[1]`, `[email protected]`/`@50%`/`@end`; ranges `a..b`, `a..`, `..b`, `all` or
+a scene name.
- Backends: `fframes::cpu::CpuRenderingBackend` (default, tiny-skia, multi-threaded) or the
Skia backend from `fframes_skia_renderer` with `SkiaFFramesRenderer::new_vulkan(&SkiaVulkanCtx::new(W, H)?, SkiaPipelineConfig { .. })`
@@ -632,6 +636,10 @@ Global flags: `--json` (one JSON document on stdout, JSON progress events on std
`FFramesRenderBackend::negotiate_encoder_input` (a software format or
`EncoderInput::hardware_frames`) and `encoder_frame_renderer`, which returns libav frames
(`fframes::VideoFrame`) for `SegmentWriter::submit_frame`.
+- `--renderer skia-cpu|gpu` needs `.renderers(SkiaRenderers::default())` before `.run()`
+ (`fframes_skia_renderer::cli`, feature `cli`): it builds the Skia backend that is asked for
+ (Metal on macOS, Vulkan elsewhere). `SkiaRenderers::gpu(SkiaPipelineConfig { .. })` also
+ renders on the GPU without the flag. Every example does this.
- macOS: request `hevc_videotoolbox` only with `fframes = { features = ["videotoolbox"] }`
(see `examples/teej-podcast/Cargo.toml`), otherwise the encoder silently falls back.
- In code: `fframes::Previewer::new(&video, &options)` keeps fonts, images and caches between
diff --git a/Cargo.lock b/Cargo.lock
index 7dfe8c54..dccd255a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -657,6 +657,7 @@ version = "1.2.0"
dependencies = [
"clap",
"fframes",
+ "fframes_skia_renderer",
"image",
"rayon",
"serde",
@@ -1520,6 +1521,7 @@ version = "1.2.0"
dependencies = [
"clap",
"fframes",
+ "fframes_skia_renderer",
]
[[package]]
@@ -1896,6 +1898,7 @@ name = "low-poly-art-example"
version = "1.2.0"
dependencies = [
"fframes",
+ "fframes_skia_renderer",
"fframes_test_utils",
"libm",
"rand 0.8.5",
@@ -1940,6 +1943,7 @@ name = "marketing-example"
version = "1.2.0"
dependencies = [
"fframes",
+ "fframes_skia_renderer",
"fframes_test_utils",
"futures",
]
@@ -2036,6 +2040,7 @@ version = "1.2.0"
dependencies = [
"clap",
"fframes",
+ "fframes_skia_renderer",
]
[[package]]
@@ -3780,6 +3785,7 @@ name = "tiktok-example"
version = "1.2.0"
dependencies = [
"fframes",
+ "fframes_skia_renderer",
"libm",
"tiktok-media",
]
diff --git a/Cargo.toml b/Cargo.toml
index 05783c2e..62b009e1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -115,4 +115,5 @@ fframes-media-dir-macro = { path = "media-dir-macro", version = "1.2.0" }
fframes = { path = "fframes", version = "1.2.0" }
webvtt-parser = { path = "webvtt-parser", version = "1.2.0" }
fframes_skia_renderer = { path = "fframes-skia-renderer", version = "1.2.0" }
-fframes_native_player = { path = "fframes-native-player", version = "1.2.0" }
+# Members pick metal or vulkan: both at once match no prebuilt Skia and build it from source.
+fframes_native_player = { path = "fframes-native-player", version = "1.2.0", default-features = false }
diff --git a/cargo-fframes/src/main.rs b/cargo-fframes/src/main.rs
index 1c5dd693..8df591c6 100644
--- a/cargo-fframes/src/main.rs
+++ b/cargo-fframes/src/main.rs
@@ -407,9 +407,9 @@ fn new(args: NewArgs) -> Result<(), String> {
let skia_deps = |renderer_source: &str, player_source: &str| {
skia_feature
.map(|f| {
- // Workspace dependencies can not turn default features off.
+ // The workspace dependency turns default features off already.
let player_features = if player_source == "workspace = true" {
- format!("features = [\"{f}\"]")
+ format!("features = [\"{f}\", \"audio\"]")
} else {
format!("default-features = false, features = [\"{f}\", \"audio\"]")
};
diff --git a/e2e/snapshots/audio-announce/30s.png b/e2e/snapshots/audio-announce/30s.png
new file mode 100644
index 00000000..c900d55b
Binary files /dev/null and b/e2e/snapshots/audio-announce/30s.png differ
diff --git a/e2e/snapshots/audio-announce/5s.png b/e2e/snapshots/audio-announce/5s.png
new file mode 100644
index 00000000..6531fbe0
Binary files /dev/null and b/e2e/snapshots/audio-announce/5s.png differ
diff --git a/e2e/snapshots/beta/betaexamples_50p.png b/e2e/snapshots/beta/betaexamples_50p.png
new file mode 100644
index 00000000..a2d379b9
Binary files /dev/null and b/e2e/snapshots/beta/betaexamples_50p.png differ
diff --git a/e2e/snapshots/beta/codedemoscene_50p.png b/e2e/snapshots/beta/codedemoscene_50p.png
new file mode 100644
index 00000000..fdd91b29
Binary files /dev/null and b/e2e/snapshots/beta/codedemoscene_50p.png differ
diff --git a/e2e/snapshots/beta/iphonescene_50p.png b/e2e/snapshots/beta/iphonescene_50p.png
new file mode 100644
index 00000000..a5e7fdeb
Binary files /dev/null and b/e2e/snapshots/beta/iphonescene_50p.png differ
diff --git a/e2e/snapshots/conference-splash-screen/speakerscene_50p.png b/e2e/snapshots/conference-splash-screen/speakerscene_50p.png
new file mode 100644
index 00000000..9fcb3f3e
Binary files /dev/null and b/e2e/snapshots/conference-splash-screen/speakerscene_50p.png differ
diff --git a/e2e/snapshots/conference-splash-screen/sponsorscene_50p.png b/e2e/snapshots/conference-splash-screen/sponsorscene_50p.png
new file mode 100644
index 00000000..8a1a0d36
Binary files /dev/null and b/e2e/snapshots/conference-splash-screen/sponsorscene_50p.png differ
diff --git a/e2e/snapshots/fframes-intro/benchmarkscene_12.4s.png b/e2e/snapshots/fframes-intro/benchmarkscene_12.4s.png
new file mode 100644
index 00000000..2c2fec5c
Binary files /dev/null and b/e2e/snapshots/fframes-intro/benchmarkscene_12.4s.png differ
diff --git a/e2e/snapshots/fframes-intro/codescene_50p.png b/e2e/snapshots/fframes-intro/codescene_50p.png
new file mode 100644
index 00000000..79f7fbdf
Binary files /dev/null and b/e2e/snapshots/fframes-intro/codescene_50p.png differ
diff --git a/e2e/snapshots/fframes-intro/outroscene_7s.png b/e2e/snapshots/fframes-intro/outroscene_7s.png
new file mode 100644
index 00000000..a767555e
Binary files /dev/null and b/e2e/snapshots/fframes-intro/outroscene_7s.png differ
diff --git a/e2e/snapshots/fframes-intro/shaderscene_2.6s.png b/e2e/snapshots/fframes-intro/shaderscene_2.6s.png
new file mode 100644
index 00000000..78900ed5
Binary files /dev/null and b/e2e/snapshots/fframes-intro/shaderscene_2.6s.png differ
diff --git a/e2e/snapshots/hello-world/20s.png b/e2e/snapshots/hello-world/20s.png
new file mode 100644
index 00000000..a9641f4c
Binary files /dev/null and b/e2e/snapshots/hello-world/20s.png differ
diff --git a/e2e/snapshots/hello-world/5s.png b/e2e/snapshots/hello-world/5s.png
new file mode 100644
index 00000000..8fb2cd7b
Binary files /dev/null and b/e2e/snapshots/hello-world/5s.png differ
diff --git a/e2e/snapshots/low-poly-art/owl_3s.png b/e2e/snapshots/low-poly-art/owl_3s.png
new file mode 100644
index 00000000..b07f0854
Binary files /dev/null and b/e2e/snapshots/low-poly-art/owl_3s.png differ
diff --git a/e2e/snapshots/low-poly-art/owl_8s.png b/e2e/snapshots/low-poly-art/owl_8s.png
new file mode 100644
index 00000000..331d95ec
Binary files /dev/null and b/e2e/snapshots/low-poly-art/owl_8s.png differ
diff --git a/e2e/snapshots/made-of-motion/fframes_50p.png b/e2e/snapshots/made-of-motion/fframes_50p.png
new file mode 100644
index 00000000..e03c6c4e
Binary files /dev/null and b/e2e/snapshots/made-of-motion/fframes_50p.png differ
diff --git a/e2e/snapshots/made-of-motion/orbit_50p.png b/e2e/snapshots/made-of-motion/orbit_50p.png
new file mode 100644
index 00000000..053b5c63
Binary files /dev/null and b/e2e/snapshots/made-of-motion/orbit_50p.png differ
diff --git a/e2e/snapshots/made-of-motion/portrait_50p.png b/e2e/snapshots/made-of-motion/portrait_50p.png
new file mode 100644
index 00000000..b64ab8f5
Binary files /dev/null and b/e2e/snapshots/made-of-motion/portrait_50p.png differ
diff --git a/e2e/snapshots/marketing/10s.png b/e2e/snapshots/marketing/10s.png
new file mode 100644
index 00000000..8f161901
Binary files /dev/null and b/e2e/snapshots/marketing/10s.png differ
diff --git a/e2e/snapshots/marketing/18s.png b/e2e/snapshots/marketing/18s.png
new file mode 100644
index 00000000..c7e545bb
Binary files /dev/null and b/e2e/snapshots/marketing/18s.png differ
diff --git a/e2e/snapshots/marketing/3s.png b/e2e/snapshots/marketing/3s.png
new file mode 100644
index 00000000..eeaa2e8c
Binary files /dev/null and b/e2e/snapshots/marketing/3s.png differ
diff --git a/e2e/snapshots/motion-graphics/1s.png b/e2e/snapshots/motion-graphics/1s.png
new file mode 100644
index 00000000..31f5ea66
Binary files /dev/null and b/e2e/snapshots/motion-graphics/1s.png differ
diff --git a/e2e/snapshots/motion-graphics/3s.png b/e2e/snapshots/motion-graphics/3s.png
new file mode 100644
index 00000000..934fc338
Binary files /dev/null and b/e2e/snapshots/motion-graphics/3s.png differ
diff --git a/e2e/snapshots/neon-triangle/2s.png b/e2e/snapshots/neon-triangle/2s.png
new file mode 100644
index 00000000..cd8f325f
Binary files /dev/null and b/e2e/snapshots/neon-triangle/2s.png differ
diff --git a/e2e/snapshots/neon-triangle/4s.png b/e2e/snapshots/neon-triangle/4s.png
new file mode 100644
index 00000000..390ba06a
Binary files /dev/null and b/e2e/snapshots/neon-triangle/4s.png differ
diff --git a/e2e/snapshots/pixel-memory/parallaxgridphotos_0__7s.png b/e2e/snapshots/pixel-memory/parallaxgridphotos_0__7s.png
new file mode 100644
index 00000000..1dcfb849
Binary files /dev/null and b/e2e/snapshots/pixel-memory/parallaxgridphotos_0__7s.png differ
diff --git a/e2e/snapshots/pixel-memory/singlephotofloat_0__50p.png b/e2e/snapshots/pixel-memory/singlephotofloat_0__50p.png
new file mode 100644
index 00000000..cea458c8
Binary files /dev/null and b/e2e/snapshots/pixel-memory/singlephotofloat_0__50p.png differ
diff --git a/e2e/snapshots/pixel-memory/spiralheapgallery_50p.png b/e2e/snapshots/pixel-memory/spiralheapgallery_50p.png
new file mode 100644
index 00000000..20e2ea14
Binary files /dev/null and b/e2e/snapshots/pixel-memory/spiralheapgallery_50p.png differ
diff --git a/e2e/snapshots/pixel-memory/startscene_1.2s.png b/e2e/snapshots/pixel-memory/startscene_1.2s.png
new file mode 100644
index 00000000..bf70274c
Binary files /dev/null and b/e2e/snapshots/pixel-memory/startscene_1.2s.png differ
diff --git a/e2e/snapshots/podcast/10s.png b/e2e/snapshots/podcast/10s.png
new file mode 100644
index 00000000..d8230877
Binary files /dev/null and b/e2e/snapshots/podcast/10s.png differ
diff --git a/e2e/snapshots/podcast/40s.png b/e2e/snapshots/podcast/40s.png
new file mode 100644
index 00000000..83e9f1fb
Binary files /dev/null and b/e2e/snapshots/podcast/40s.png differ
diff --git a/e2e/snapshots/shaders/2s.png b/e2e/snapshots/shaders/2s.png
new file mode 100644
index 00000000..54fb134a
Binary files /dev/null and b/e2e/snapshots/shaders/2s.png differ
diff --git a/e2e/snapshots/shaders/6s.png b/e2e/snapshots/shaders/6s.png
new file mode 100644
index 00000000..99528ba1
Binary files /dev/null and b/e2e/snapshots/shaders/6s.png differ
diff --git a/e2e/snapshots/signal-lab/datascene_3s.png b/e2e/snapshots/signal-lab/datascene_3s.png
new file mode 100644
index 00000000..e8dfdd25
Binary files /dev/null and b/e2e/snapshots/signal-lab/datascene_3s.png differ
diff --git a/e2e/snapshots/signal-lab/productscene_3s.png b/e2e/snapshots/signal-lab/productscene_3s.png
new file mode 100644
index 00000000..abce961b
Binary files /dev/null and b/e2e/snapshots/signal-lab/productscene_3s.png differ
diff --git a/e2e/snapshots/signal-lab/systemscene_3s.png b/e2e/snapshots/signal-lab/systemscene_3s.png
new file mode 100644
index 00000000..229a0119
Binary files /dev/null and b/e2e/snapshots/signal-lab/systemscene_3s.png differ
diff --git a/e2e/snapshots/teej-podcast/10s.png b/e2e/snapshots/teej-podcast/10s.png
new file mode 100644
index 00000000..f13d36c9
Binary files /dev/null and b/e2e/snapshots/teej-podcast/10s.png differ
diff --git a/e2e/snapshots/teej-podcast/2_00.png b/e2e/snapshots/teej-podcast/2_00.png
new file mode 100644
index 00000000..fa770121
Binary files /dev/null and b/e2e/snapshots/teej-podcast/2_00.png differ
diff --git a/e2e/snapshots/tiktok/10s.png b/e2e/snapshots/tiktok/10s.png
new file mode 100644
index 00000000..8358e884
Binary files /dev/null and b/e2e/snapshots/tiktok/10s.png differ
diff --git a/e2e/snapshots/tiktok/30s.png b/e2e/snapshots/tiktok/30s.png
new file mode 100644
index 00000000..7177b8f0
Binary files /dev/null and b/e2e/snapshots/tiktok/30s.png differ
diff --git a/examples/audio-announce/Cargo.toml b/examples/audio-announce/Cargo.toml
index 579685e0..e8cb64d4 100644
--- a/examples/audio-announce/Cargo.toml
+++ b/examples/audio-announce/Cargo.toml
@@ -5,19 +5,22 @@ edition = "2024"
[dependencies]
clap = { version = "4.3.4", features = ["derive"] }
-fframes = { workspace = true, features = ["h264", "libav-agree-gpl"] }
+fframes.workspace = true
-[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
-fframes_skia_renderer = { workspace = true, features = ["vulkan"] }
+# `--renderer cpu|skia-cpu|gpu`: Skia on Metal on macOS, on Vulkan everywhere else
# `preview`: real-time GPU window
-fframes_native_player.workspace = true
-
[target.'cfg(target_os = "macos")'.dependencies]
-fframes_native_player = { workspace = true, features = ["metal"] }
+fframes_skia_renderer = { workspace = true, features = ["metal", "cli"] }
+fframes_native_player = { workspace = true, features = ["metal", "audio"] }
+
+[target.'cfg(not(any(target_os = "macos", target_arch = "wasm32")))'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["vulkan", "cli"] }
+fframes_native_player = { workspace = true, features = ["vulkan", "audio"] }
-# Keep FFmpeg source fallbacks portable across CI runner CPUs (see README).
+# FFmpeg codecs, portable so cached source builds work across CI runner CPUs. Windows
+# links a prebuilt FFmpeg instead (see README).
[target.'cfg(not(any(target_arch = "wasm32", windows)))'.dependencies]
-fframes = { workspace = true, features = ["build-portable"] }
+fframes = { workspace = true, features = ["h264", "libav-agree-gpl", "build-portable"] }
[features]
default = ["renderer"]
diff --git a/examples/audio-announce/src/main.rs b/examples/audio-announce/src/main.rs
index e9d2dbfd..da20fa2c 100644
--- a/examples/audio-announce/src/main.rs
+++ b/examples/audio-announce/src/main.rs
@@ -3,8 +3,9 @@ use fframes::cli::{self, clap};
use fframes::{
CombinedMediaProvider, EncoderOptions, MediaProvider, RenderOptions, StaticMediaProvider, Video,
};
-use fframes_skia_renderer::vulkan::SkiaVulkanCtx;
-use fframes_skia_renderer::{SkiaFFramesRenderer, SkiaPipelineConfig};
+use fframes_skia_renderer::{
+ SkiaPipelineConcurrencyPolicy, SkiaPipelineConfig, cli::SkiaRenderers,
+};
use std::process::ExitCode;
#[derive(Debug, clap::Args)]
@@ -25,8 +26,6 @@ fn main() -> ExitCode {
]);
let font = args.app.font.clone();
- let vulkan_ctx = SkiaVulkanCtx::new(AudioAnnounce::WIDTH, AudioAnnounce::HEIGHT).unwrap();
-
cli::new(
&AudioAnnounce {
media: &media,
@@ -54,20 +53,13 @@ fn main() -> ExitCode {
},
)
.args(args)
- .backend(
- // Swap in `fframes::cpu::CpuRenderingBackend::default()` to compare with the CPU.
- SkiaFFramesRenderer::new_vulkan(
- &vulkan_ctx,
- SkiaPipelineConfig {
- buffer_queue_size: AudioAnnounce::FPS,
- // this works well on the author's machine, test other values on yours
- concurrency_policy:
- fframes_skia_renderer::SkiaPipelineConcurrencyPolicy::Concurrency(4),
- ..Default::default()
- },
- )
- .expect("Failed to create the skia renderer"),
- )
.preview(fframes_native_player::cli_preview)
+ // `--renderer cpu` compares with the CPU backend
+ .renderers(SkiaRenderers::gpu(SkiaPipelineConfig {
+ buffer_queue_size: AudioAnnounce::FPS,
+ // this works well on the author's machine, test other values on yours
+ concurrency_policy: SkiaPipelineConcurrencyPolicy::Concurrency(4),
+ ..Default::default()
+ }))
.run()
}
diff --git a/examples/beta/Cargo.toml b/examples/beta/Cargo.toml
index 978f2526..4f6fbcf1 100644
--- a/examples/beta/Cargo.toml
+++ b/examples/beta/Cargo.toml
@@ -12,19 +12,22 @@ hello-world-example = { path = "../hello-world", default-features = false }
marketing-example = { path = "../marketing", default-features = false }
podcast-example = { path = "../podcast", default-features = false }
tiktok-example = { path = "../tiktok", default-features = false }
-fframes = { workspace = true, features = ["h264", "libav-agree-gpl"] }
+fframes.workspace = true
-[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
-fframes_skia_renderer = { workspace = true, features = ["vulkan"] }
+# `--renderer cpu|skia-cpu|gpu`: Skia on Metal on macOS, on Vulkan everywhere else
# `preview`: real-time GPU window
-fframes_native_player.workspace = true
-
[target.'cfg(target_os = "macos")'.dependencies]
-fframes_native_player = { workspace = true, features = ["metal"] }
+fframes_skia_renderer = { workspace = true, features = ["metal", "cli"] }
+fframes_native_player = { workspace = true, features = ["metal", "audio"] }
+
+[target.'cfg(not(any(target_os = "macos", target_arch = "wasm32")))'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["vulkan", "cli"] }
+fframes_native_player = { workspace = true, features = ["vulkan", "audio"] }
-# Keep FFmpeg source fallbacks portable across CI runner CPUs (see README).
+# FFmpeg codecs, portable so cached source builds work across CI runner CPUs. Windows
+# links a prebuilt FFmpeg instead (see README).
[target.'cfg(not(any(target_arch = "wasm32", windows)))'.dependencies]
-fframes = { workspace = true, features = ["build-portable"] }
+fframes = { workspace = true, features = ["h264", "libav-agree-gpl", "build-portable"] }
[features]
default = ["renderer"]
diff --git a/examples/beta/src/end.rs b/examples/beta/src/end.rs
index 89989326..ffa4aca8 100644
--- a/examples/beta/src/end.rs
+++ b/examples/beta/src/end.rs
@@ -36,7 +36,7 @@ impl Scene for EndScene {
"rames"
</text>
- <text font-size="80" x="1220" y="605" fill="url(#text)" font-family="Chalkboard SE"
+ <text font-size="80" x="1220" y="605" fill="url(#text)" font-family="Fredoka One"
opacity={
frame.animate(
&fframes::timeline!(
diff --git a/examples/beta/src/main.rs b/examples/beta/src/main.rs
index ba749143..573f9541 100644
--- a/examples/beta/src/main.rs
+++ b/examples/beta/src/main.rs
@@ -3,6 +3,7 @@ use fframes::{
CombinedMediaProvider, EncoderOptions, MediaDirectory, MediaProvider, RenderOptions,
StaticMediaProvider, cli, cpu::CpuRenderingBackend,
};
+use fframes_skia_renderer::cli::SkiaRenderers;
use hello_world_example::{HelloWorldMedia, HelloWorldVideo};
use marketing_example::{MarketingMedia, MarketingVideo};
use podcast_example::PodcastVideo;
@@ -71,5 +72,6 @@ fn main() -> ExitCode {
..Default::default()
})
.preview(fframes_native_player::cli_preview)
+ .renderers(SkiaRenderers::default())
.run()
}
diff --git a/examples/conference-splash-screen/Cargo.toml b/examples/conference-splash-screen/Cargo.toml
index 3e240e90..5f2817b5 100644
--- a/examples/conference-splash-screen/Cargo.toml
+++ b/examples/conference-splash-screen/Cargo.toml
@@ -4,16 +4,24 @@ version = "1.2.0"
edition = "2024"
[dependencies]
-fframes = { workspace = true, features = ["h264", "h265", "libav-agree-gpl"] }
+fframes.workspace = true
clap = { version = "4.3.4", features = ["derive"] }
serde = "1.0.210"
serde_json = "1.0.132"
rayon = "1.10.0"
image = "0.25.4"
-# Keep FFmpeg source fallbacks portable across CI runner CPUs (see README).
+# `--renderer cpu|skia-cpu|gpu`: Skia on Metal on macOS, on Vulkan everywhere else
+[target.'cfg(target_os = "macos")'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["metal", "cli"] }
+
+[target.'cfg(not(any(target_os = "macos", target_arch = "wasm32")))'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["vulkan", "cli"] }
+
+# FFmpeg codecs, portable so cached source builds work across CI runner CPUs. Windows
+# links a prebuilt FFmpeg instead (see README).
[target.'cfg(not(any(target_arch = "wasm32", windows)))'.dependencies]
-fframes = { workspace = true, features = ["build-portable"] }
+fframes = { workspace = true, features = ["h264", "h265", "libav-agree-gpl", "build-portable"] }
[features]
default = ["renderer"]
diff --git a/examples/conference-splash-screen/src/main.rs b/examples/conference-splash-screen/src/main.rs
index 4fbf3160..437133db 100644
--- a/examples/conference-splash-screen/src/main.rs
+++ b/examples/conference-splash-screen/src/main.rs
@@ -2,6 +2,7 @@
use conference_splash_screen::ConferenceMedia;
use fframes::cli::{self, clap};
use fframes::{CombinedMediaProvider, MediaProvider, StaticMediaProvider};
+use fframes_skia_renderer::cli::SkiaRenderers;
use std::process::ExitCode;
mod talks;
@@ -54,5 +55,6 @@ fn main() -> ExitCode {
)
.args(args)
.backend(talks::backend())
+ .renderers(SkiaRenderers::default())
.run()
}
diff --git a/examples/fframes-intro/Cargo.toml b/examples/fframes-intro/Cargo.toml
index 28b7e646..0cdf293b 100644
--- a/examples/fframes-intro/Cargo.toml
+++ b/examples/fframes-intro/Cargo.toml
@@ -7,14 +7,15 @@ publish = false
[dependencies]
fframes = { workspace = true, features = ["compile-time-svgtree", "cli"] }
-# Metal on macOS, Vulkan everywhere else
+# `--renderer cpu|skia-cpu|gpu`: Skia on Metal on macOS, on Vulkan everywhere else
+# `preview`: real-time GPU window
[target.'cfg(target_os = "macos")'.dependencies]
-fframes_skia_renderer = { workspace = true, features = ["metal"] }
-fframes_native_player = { workspace = true, features = ["metal"] }
+fframes_skia_renderer = { workspace = true, features = ["metal", "cli"] }
+fframes_native_player = { workspace = true, features = ["metal", "audio"] }
-[target.'cfg(not(target_os = "macos"))'.dependencies]
-fframes_skia_renderer = { workspace = true, features = ["vulkan"] }
-fframes_native_player.workspace = true
+[target.'cfg(not(any(target_os = "macos", target_arch = "wasm32")))'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["vulkan", "cli"] }
+fframes_native_player = { workspace = true, features = ["vulkan", "audio"] }
[target.'cfg(not(windows))'.dependencies]
fframes = { workspace = true, features = ["h264", "libav-agree-gpl"] }
diff --git a/examples/fframes-intro/src/main.rs b/examples/fframes-intro/src/main.rs
index b378ca6b..0171888f 100644
--- a/examples/fframes-intro/src/main.rs
+++ b/examples/fframes-intro/src/main.rs
@@ -2,9 +2,9 @@ use fframes::{
AudioMixOptions, CombinedMediaProvider, EncoderOptions, LimiterOptions, MediaDirectory,
MediaProvider, RenderOptions, StaticMediaProvider, cli,
};
-use fframes_intro::{HEIGHT, IntroMedia, IntroVideo, WIDTH};
+use fframes_intro::{IntroMedia, IntroVideo};
use fframes_skia_renderer::{
- SkiaFFramesRenderer, SkiaPipelineConcurrencyPolicy, SkiaPipelineConfig,
+ SkiaPipelineConcurrencyPolicy, SkiaPipelineConfig, cli::SkiaRenderers,
};
use std::path::Path;
use std::process::ExitCode;
@@ -16,19 +16,6 @@ fn main() -> ExitCode {
let dir = MediaDirectory::read_folder(&folder).expect("dynamic media folder");
let dynamic = dir.process_media_source().expect("dynamic media");
let all = CombinedMediaProvider::from([&media as &dyn MediaProvider, &dynamic]);
- #[cfg(target_os = "macos")]
- let gpu = fframes_skia_renderer::metal::SkiaMetalCtx::new(WIDTH, HEIGHT).expect("GPU context");
- #[cfg(not(target_os = "macos"))]
- let gpu =
- fframes_skia_renderer::vulkan::SkiaVulkanCtx::new(WIDTH, HEIGHT).expect("GPU context");
- let pipeline = SkiaPipelineConfig {
- concurrency_policy: SkiaPipelineConcurrencyPolicy::MaxPerformance,
- ..Default::default()
- };
- #[cfg(target_os = "macos")]
- let backend = SkiaFFramesRenderer::new_metal(&gpu, pipeline);
- #[cfg(not(target_os = "macos"))]
- let backend = SkiaFFramesRenderer::new_vulkan(&gpu, pipeline);
cli::new(
&IntroVideo,
@@ -52,7 +39,10 @@ fn main() -> ExitCode {
..Default::default()
},
)
- .backend(backend.expect("skia renderer"))
.preview(fframes_native_player::cli_preview)
+ .renderers(SkiaRenderers::gpu(SkiaPipelineConfig {
+ concurrency_policy: SkiaPipelineConcurrencyPolicy::MaxPerformance,
+ ..Default::default()
+ }))
.run()
}
diff --git a/examples/fframes-intro/src/shaders/contour.sksl b/examples/fframes-intro/src/shaders/contour.sksl
index 9d9858a6..7a616fe7 100644
--- a/examples/fframes-intro/src/shaders/contour.sksl
+++ b/examples/fframes-intro/src/shaders/contour.sksl
@@ -9,7 +9,13 @@ uniform float uBright; // overall line brightness
uniform float4 uInk; // line color
uniform float4 uHot; // color near the well
-float hash(float2 p) { return fract(sin(dot(p, float2(127.1, 311.7))) * 43758.5453); }
+// No sin(): GPUs compute it with less precision than CPUs, so a sin() hash gives every
+// device different noise. "Hash without Sine" by Dave Hoskins.
+float hash(float2 p) {
+ float3 p3 = fract(float3(p.xyx) * 0.1031);
+ p3 += dot(p3, p3.yzx + 33.33);
+ return fract((p3.x + p3.y) * p3.z);
+}
float noise(float2 p) {
float2 i = floor(p); float2 f = fract(p);
float2 u = f * f * (3.0 - 2.0 * f);
diff --git a/examples/hello-world/Cargo.toml b/examples/hello-world/Cargo.toml
index da1d1760..4f8ea35e 100644
--- a/examples/hello-world/Cargo.toml
+++ b/examples/hello-world/Cargo.toml
@@ -4,13 +4,21 @@ version = "1.2.0"
edition = "2024"
[dependencies]
-fframes = { workspace = true, features = ["h264", "h265", "vpx", "libav-agree-gpl"] }
+fframes.workspace = true
clap = { version = "4.3.4", features = ["derive"] }
-# Keep FFmpeg source fallbacks portable across CI runner CPUs (see README).
+# `--renderer cpu|skia-cpu|gpu`: Skia on Metal on macOS, on Vulkan everywhere else
+[target.'cfg(target_os = "macos")'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["metal", "cli"] }
+
+[target.'cfg(not(any(target_os = "macos", target_arch = "wasm32")))'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["vulkan", "cli"] }
+
+# FFmpeg codecs, portable so cached source builds work across CI runner CPUs. Windows
+# links a prebuilt FFmpeg instead (see README).
[target.'cfg(not(any(target_arch = "wasm32", windows)))'.dependencies]
-fframes = { workspace = true, features = ["build-portable"] }
+fframes = { workspace = true, features = ["h264", "h265", "vpx", "libav-agree-gpl", "build-portable"] }
[features]
default = ["renderer"]
diff --git a/examples/hello-world/src/hello_world.rs b/examples/hello-world/src/hello_world.rs
index f96a1118..d092a570 100644
--- a/examples/hello-world/src/hello_world.rs
+++ b/examples/hello-world/src/hello_world.rs
@@ -32,8 +32,8 @@ impl Video for HelloWorldVideo<'_> {
height={ctx.current_video_size.height}
>
<rect
- width={ctx.current_video_size.width}
- height={ctx.current_video_size.height}
+ width="1920"
+ height="1080"
fill={frame.animate(&fframes::timeline!(
at 0., animate Color::hex("#fff") => Color::hex("#f8fafc"), Easing::Linear,
at 5., animate Color::hex("#f8fafc") => Color::hex("#fff7ed"), Easing::Linear,
diff --git a/examples/hello-world/src/main.rs b/examples/hello-world/src/main.rs
index 582b831b..924bb692 100644
--- a/examples/hello-world/src/main.rs
+++ b/examples/hello-world/src/main.rs
@@ -1,5 +1,6 @@
use clap::Args;
use fframes::{EncoderOptions, RenderOptions, StaticMediaProvider, cli};
+use fframes_skia_renderer::cli::SkiaRenderers;
use hello_world_example::{HelloWorldMedia, HelloWorldVideo};
use std::path::PathBuf;
use std::process::ExitCode;
@@ -40,5 +41,6 @@ fn main() -> ExitCode {
},
)
.args(args)
+ .renderers(SkiaRenderers::default())
.run()
}
diff --git a/examples/low-poly-art/Cargo.toml b/examples/low-poly-art/Cargo.toml
index 784e4220..b323755a 100644
--- a/examples/low-poly-art/Cargo.toml
+++ b/examples/low-poly-art/Cargo.toml
@@ -11,6 +11,13 @@ fframes = { workspace = true }
[dev-dependencies]
fframes_test_utils = { path = "../../fframes-test-utils" }
+# `--renderer cpu|skia-cpu|gpu`: Skia on Metal on macOS, on Vulkan everywhere else
+[target.'cfg(target_os = "macos")'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["metal", "cli"] }
+
+[target.'cfg(not(any(target_os = "macos", target_arch = "wasm32")))'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["vulkan", "cli"] }
+
# Keep FFmpeg source fallbacks portable across CI runner CPUs (see README).
[target.'cfg(not(any(target_arch = "wasm32", windows)))'.dependencies]
fframes = { workspace = true, features = ["build-portable"] }
diff --git a/examples/low-poly-art/src/main.rs b/examples/low-poly-art/src/main.rs
index 2c937330..5c20341a 100644
--- a/examples/low-poly-art/src/main.rs
+++ b/examples/low-poly-art/src/main.rs
@@ -1,4 +1,5 @@
use fframes::{CombinedMediaProvider, MediaProvider, RenderOptions, cli};
+use fframes_skia_renderer::cli::SkiaRenderers;
use low_poly_art_example::{LowPolyMedia, LowPolyVideo, owl};
use std::process::ExitCode;
@@ -28,5 +29,6 @@ fn main() -> ExitCode {
cache_capacity: 5,
..Default::default()
})
+ .renderers(SkiaRenderers::default())
.run()
}
diff --git a/examples/made-of-motion/Cargo.toml b/examples/made-of-motion/Cargo.toml
index 95d29631..65e68e89 100644
--- a/examples/made-of-motion/Cargo.toml
+++ b/examples/made-of-motion/Cargo.toml
@@ -8,13 +8,15 @@ publish = false
flate2 = "1"
fframes = { workspace = true, features = ["compile-time-svgtree", "cli"] }
+# `--renderer cpu|skia-cpu|gpu`: Skia on Metal on macOS, on Vulkan everywhere else
+# `preview`: real-time GPU window
[target.'cfg(target_os = "macos")'.dependencies]
-fframes_skia_renderer = { workspace = true, features = ["metal"] }
-fframes_native_player = { workspace = true, features = ["metal"] }
+fframes_skia_renderer = { workspace = true, features = ["metal", "cli"] }
+fframes_native_player = { workspace = true, features = ["metal", "audio"] }
[target.'cfg(not(target_os = "macos"))'.dependencies]
-fframes_skia_renderer = { workspace = true, features = ["vulkan"] }
-fframes_native_player.workspace = true
+fframes_skia_renderer = { workspace = true, features = ["vulkan", "cli"] }
+fframes_native_player = { workspace = true, features = ["vulkan", "audio"] }
[target.'cfg(not(windows))'.dependencies]
fframes = { workspace = true, features = ["h264", "libav-agree-gpl", "build-portable"] }
diff --git a/examples/made-of-motion/src/main.rs b/examples/made-of-motion/src/main.rs
index 917c5ba1..9acd9c3b 100644
--- a/examples/made-of-motion/src/main.rs
+++ b/examples/made-of-motion/src/main.rs
@@ -3,9 +3,9 @@ use std::process::ExitCode;
use fframes::cli::clap;
use fframes::{
AudioMixOptions, CombinedMediaProvider, EncoderOptions, MediaDirectory, MediaProvider,
- RenderOptions, StaticMediaProvider, Video, cli,
+ RenderOptions, StaticMediaProvider, cli,
};
-use fframes_skia_renderer::{SkiaFFramesRenderer, SkiaPipelineConfig};
+use fframes_skia_renderer::{SkiaPipelineConfig, cli::SkiaRenderers};
use made_of_motion::{MadeOfMotion, MotionMedia};
#[derive(Debug, cli::clap::Args)]
@@ -32,18 +32,6 @@ fn run() -> Result<ExitCode, Box<dyn std::error::Error>> {
let dynamic = directory.process_media_source()?;
let all = CombinedMediaProvider::from([&media as &dyn MediaProvider, &dynamic]);
let video = MadeOfMotion::new().with_ink_only(args.app.ink_only);
- #[cfg(target_os = "macos")]
- let gpu =
- fframes_skia_renderer::metal::SkiaMetalCtx::new(MadeOfMotion::WIDTH, MadeOfMotion::HEIGHT)?;
- #[cfg(not(target_os = "macos"))]
- let gpu = fframes_skia_renderer::vulkan::SkiaVulkanCtx::new(
- MadeOfMotion::WIDTH,
- MadeOfMotion::HEIGHT,
- )?;
- #[cfg(target_os = "macos")]
- let backend = SkiaFFramesRenderer::new_metal(&gpu, SkiaPipelineConfig::default())?;
- #[cfg(not(target_os = "macos"))]
- let backend = SkiaFFramesRenderer::new_vulkan(&gpu, SkiaPipelineConfig::default())?;
Ok(cli::new(
&video,
RenderOptions {
@@ -61,11 +49,11 @@ fn run() -> Result<ExitCode, Box<dyn std::error::Error>> {
},
)
.args(args)
- .backend(backend)
.preview(fframes_native_player::cli_preview)
.default_output(
std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("output/made-of-motion.mp4"),
)
+ .renderers(SkiaRenderers::gpu(SkiaPipelineConfig::default()))
.run())
}
diff --git a/examples/marketing/Cargo.toml b/examples/marketing/Cargo.toml
index 5ab6dd18..9fb11f2f 100644
--- a/examples/marketing/Cargo.toml
+++ b/examples/marketing/Cargo.toml
@@ -4,15 +4,23 @@ version = "1.2.0"
edition = "2024"
[dependencies]
-fframes = { workspace = true, features = ["h265", "libav-agree-gpl"] }
+fframes.workspace = true
[dev-dependencies]
fframes_test_utils = { path = "../../fframes-test-utils" }
futures = "0.3.17"
-# Keep FFmpeg source fallbacks portable across CI runner CPUs (see README).
+# `--renderer cpu|skia-cpu|gpu`: Skia on Metal on macOS, on Vulkan everywhere else
+[target.'cfg(target_os = "macos")'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["metal", "cli"] }
+
+[target.'cfg(not(any(target_os = "macos", target_arch = "wasm32")))'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["vulkan", "cli"] }
+
+# FFmpeg codecs, portable so cached source builds work across CI runner CPUs. Windows
+# links a prebuilt FFmpeg instead (see README).
[target.'cfg(not(any(target_arch = "wasm32", windows)))'.dependencies]
-fframes = { workspace = true, features = ["build-portable"] }
+fframes = { workspace = true, features = ["h265", "libav-agree-gpl", "build-portable"] }
[features]
default=["renderer"]
diff --git a/examples/marketing/media/FredokaOne-Regular.ttf b/examples/marketing/media/FredokaOne-Regular.ttf
new file mode 100644
index 00000000..bcef8af1
Binary files /dev/null and b/examples/marketing/media/FredokaOne-Regular.ttf differ
diff --git a/examples/marketing/src/main.rs b/examples/marketing/src/main.rs
index 9f87142d..242ccde0 100644
--- a/examples/marketing/src/main.rs
+++ b/examples/marketing/src/main.rs
@@ -1,4 +1,5 @@
use fframes::{EncoderOptions, RenderOptions, StaticMediaProvider, cli};
+use fframes_skia_renderer::cli::SkiaRenderers;
use marketing_example::{MarketingMedia, MarketingVideo};
use std::process::ExitCode;
@@ -25,5 +26,6 @@ fn main() -> ExitCode {
cache_capacity: 30,
..Default::default()
})
+ .renderers(SkiaRenderers::default())
.run()
}
diff --git a/examples/marketing/src/marketing.rs b/examples/marketing/src/marketing.rs
index 996e9104..c6724665 100644
--- a/examples/marketing/src/marketing.rs
+++ b/examples/marketing/src/marketing.rs
@@ -382,7 +382,7 @@ impl Video for MarketingVideo<'_> {
x="50%"
text-anchor="middle"
fill="white"
- font-family="Chalkboard SE"
+ font-family="Fredoka One"
>
{frame.get_subtitle_phrase(&self.media.subtitles_vtt).unwrap_or("")}
</text>
@@ -415,7 +415,7 @@ impl Video for MarketingVideo<'_> {
<text x="960" y="570" font-family="Bubble Bobble" font-size="154" text-anchor="middle">
<tspan fill={if frame.seconds() > 18.8 { "#7351d8" } else { "#000" }}>"ff"</tspan>"rames"
</text>
- <text x="960" y="610" font-family="Chalkboard SE" font-size="30" text-anchor="middle">
+ <text x="960" y="610" font-family="Fredoka One" font-size="30" text-anchor="middle">
"Write some code. Get video. Enjoy!"
</text>
<g y="540" transform="scale(2.7) translate(-218, 110)">
diff --git a/examples/motion-graphics/Cargo.toml b/examples/motion-graphics/Cargo.toml
index bf8fc09c..9b54bc29 100644
--- a/examples/motion-graphics/Cargo.toml
+++ b/examples/motion-graphics/Cargo.toml
@@ -4,12 +4,20 @@ version = "1.2.0"
edition = "2024"
[dependencies]
-fframes = { workspace = true, features = ["h264", "libav-agree-gpl"] }
+fframes.workspace = true
clap = { version = "4.3.4", features = ["derive"] }
-# Keep FFmpeg source fallbacks portable across CI runner CPUs (see README).
+# `--renderer cpu|skia-cpu|gpu`: Skia on Metal on macOS, on Vulkan everywhere else
+[target.'cfg(target_os = "macos")'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["metal", "cli"] }
+
+[target.'cfg(not(any(target_os = "macos", target_arch = "wasm32")))'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["vulkan", "cli"] }
+
+# FFmpeg codecs, portable so cached source builds work across CI runner CPUs. Windows
+# links a prebuilt FFmpeg instead (see README).
[target.'cfg(not(any(target_arch = "wasm32", windows)))'.dependencies]
-fframes = { workspace = true, features = ["build-portable"] }
+fframes = { workspace = true, features = ["h264", "libav-agree-gpl", "build-portable"] }
[features]
default = ["renderer"]
diff --git a/examples/motion-graphics/media/Inter_24pt-Bold.ttf b/examples/motion-graphics/media/Inter_24pt-Bold.ttf
new file mode 100644
index 00000000..46b3583c
Binary files /dev/null and b/examples/motion-graphics/media/Inter_24pt-Bold.ttf differ
diff --git a/examples/motion-graphics/media/Inter_24pt-Regular.ttf b/examples/motion-graphics/media/Inter_24pt-Regular.ttf
new file mode 100644
index 00000000..6b088a71
Binary files /dev/null and b/examples/motion-graphics/media/Inter_24pt-Regular.ttf differ
diff --git a/examples/motion-graphics/src/main.rs b/examples/motion-graphics/src/main.rs
index 89f74f77..d801bfe6 100644
--- a/examples/motion-graphics/src/main.rs
+++ b/examples/motion-graphics/src/main.rs
@@ -1,5 +1,6 @@
use fframes::StaticMediaProvider;
use fframes::cli::{self, clap};
+use fframes_skia_renderer::cli::SkiaRenderers;
use motion_graphics_example::{MotionGraphicsMedia, MotionGraphicsVideo, render_options};
use std::process::ExitCode;
@@ -24,5 +25,6 @@ fn main() -> ExitCode {
cache_capacity: 10,
..Default::default()
})
+ .renderers(SkiaRenderers::default())
.run()
}
diff --git a/examples/motion-graphics/src/motion_graphics.rs b/examples/motion-graphics/src/motion_graphics.rs
index 077cbd10..c0e6abf7 100644
--- a/examples/motion-graphics/src/motion_graphics.rs
+++ b/examples/motion-graphics/src/motion_graphics.rs
@@ -79,7 +79,7 @@ impl fframes::Video for MotionGraphicsVideo<'_> {
x="960"
y={line1_y}
opacity={line1_opacity}
- font-family="Helvetica Neue"
+ font-family="Inter 24pt"
font-size="340"
font-weight="700"
fill="white"
@@ -127,7 +127,7 @@ impl fframes::Video for MotionGraphicsVideo<'_> {
x="960"
y={line3_y}
opacity={line3_opacity}
- font-family="Helvetica Neue"
+ font-family="Inter 24pt"
font-size="60"
font-weight="300"
font-style="italic"
diff --git a/examples/neon-triangle/Cargo.toml b/examples/neon-triangle/Cargo.toml
index f1604a99..ee4a96a5 100644
--- a/examples/neon-triangle/Cargo.toml
+++ b/examples/neon-triangle/Cargo.toml
@@ -4,23 +4,28 @@ version = "1.2.0"
edition = "2024"
[dependencies]
-fframes = { workspace = true, features = ["h264", "h265", "libav-agree-gpl"] }
+fframes.workspace = true
clap = { version = "4.3.4", features = ["derive"] }
# Shaders are executed by the Skia backend; the editor bridge (wasm) only
# needs `fframes` and shows a placeholder in their place.
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
-fframes_skia_renderer = { workspace = true, features = ["vulkan"] }
image = "0.25.5"
-# `preview`: real-time GPU window
-fframes_native_player.workspace = true
+# `--renderer cpu|skia-cpu|gpu`: Skia on Metal on macOS, on Vulkan everywhere else
+# `preview`: real-time GPU window
[target.'cfg(target_os = "macos")'.dependencies]
-fframes_native_player = { workspace = true, features = ["metal"] }
+fframes_skia_renderer = { workspace = true, features = ["metal", "cli"] }
+fframes_native_player = { workspace = true, features = ["metal", "audio"] }
+
+[target.'cfg(not(any(target_os = "macos", target_arch = "wasm32")))'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["vulkan", "cli"] }
+fframes_native_player = { workspace = true, features = ["vulkan", "audio"] }
-# Keep FFmpeg source fallbacks portable across CI runner CPUs (see README).
+# FFmpeg codecs, portable so cached source builds work across CI runner CPUs. Windows
+# links a prebuilt FFmpeg instead (see README).
[target.'cfg(not(any(target_arch = "wasm32", windows)))'.dependencies]
-fframes = { workspace = true, features = ["build-portable"] }
+fframes = { workspace = true, features = ["h264", "h265", "libav-agree-gpl", "build-portable"] }
[features]
default = ["renderer"]
diff --git a/examples/neon-triangle/src/main.rs b/examples/neon-triangle/src/main.rs
index 3eac5953..fbcdf2d8 100644
--- a/examples/neon-triangle/src/main.rs
+++ b/examples/neon-triangle/src/main.rs
@@ -1,6 +1,6 @@
use fframes::cli::{self, clap};
-use fframes::{EncoderOptions, RenderOptions, StaticMediaProvider, Video};
-use fframes_skia_renderer::{SkiaFFramesRenderer, SkiaPipelineConfig, vulkan::SkiaVulkanCtx};
+use fframes::{EncoderOptions, RenderOptions, StaticMediaProvider};
+use fframes_skia_renderer::{SkiaPipelineConfig, cli::SkiaRenderers};
use neon_triangle_example::{NeonTriangleMedia, NeonTriangleVideo};
use std::process::ExitCode;
@@ -17,10 +17,7 @@ fn main() -> ExitCode {
let video_codec = args.app.video_codec.clone();
// Shaders run on the Skia backend's own GPU surface; the tiny-skia CPU
- // backend would draw nothing in their place, so previews use Skia too.
- let vulkan_ctx =
- SkiaVulkanCtx::new(NeonTriangleVideo::WIDTH, NeonTriangleVideo::HEIGHT).unwrap();
-
+ // backend (`--renderer cpu`) draws nothing in their place.
cli::new(
&video,
RenderOptions {
@@ -34,10 +31,7 @@ fn main() -> ExitCode {
},
)
.args(args)
- .backend(
- SkiaFFramesRenderer::new_vulkan(&vulkan_ctx, SkiaPipelineConfig::default())
- .expect("Failed to create renderer"),
- )
.preview(fframes_native_player::cli_preview)
+ .renderers(SkiaRenderers::gpu(SkiaPipelineConfig::default()))
.run()
}
diff --git a/examples/pixel-memory/Cargo.toml b/examples/pixel-memory/Cargo.toml
index a2e4d3e7..d47cffb4 100644
--- a/examples/pixel-memory/Cargo.toml
+++ b/examples/pixel-memory/Cargo.toml
@@ -8,22 +8,24 @@ clap = { version = "4.3.4", features = ["derive"] }
image = "0.25.5"
rand = "0.8.5"
getrandom = { version = "0.2.15", features = ["js"] }
-fframes = { workspace = true, features = ["h264", "h265", "libav-agree-gpl", "exif"] }
+fframes = { workspace = true, features = ["exif"] }
-[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
-fframes_skia_renderer = { workspace = true, features = ["vulkan", "debug"] }
+# `--renderer cpu|skia-cpu|gpu`: Skia on Metal on macOS, on Vulkan everywhere else
# `preview`: real-time GPU window
-fframes_native_player.workspace = true
-
[target.'cfg(target_os = "macos")'.dependencies]
-fframes_native_player = { workspace = true, features = ["metal"] }
+fframes_skia_renderer = { workspace = true, features = ["metal", "cli", "debug"] }
+fframes_native_player = { workspace = true, features = ["metal", "audio"] }
+
+[target.'cfg(not(any(target_os = "macos", target_arch = "wasm32")))'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["vulkan", "cli", "debug"] }
+fframes_native_player = { workspace = true, features = ["vulkan", "audio"] }
-# Keep FFmpeg source fallbacks portable across CI runner CPUs (see README).
+# FFmpeg codecs, portable so cached source builds work across CI runner CPUs. Windows
+# links a prebuilt FFmpeg instead (see README).
[target.'cfg(not(any(target_arch = "wasm32", windows)))'.dependencies]
-fframes = { workspace = true, features = ["build-portable"] }
+fframes = { workspace = true, features = ["h264", "h265", "libav-agree-gpl", "build-portable"] }
[features]
-cpu = []
default = ["renderer"]
renderer = ["fframes/compile-time-svgtree", "fframes/cli"]
diff --git a/examples/pixel-memory/src/main.rs b/examples/pixel-memory/src/main.rs
index abbf9c79..428fe0ca 100644
--- a/examples/pixel-memory/src/main.rs
+++ b/examples/pixel-memory/src/main.rs
@@ -1,12 +1,11 @@
-#[cfg(not(feature = "cpu"))]
-use fframes::Video;
use fframes::cli::{self, clap};
use fframes::{
CombinedMediaProvider, EncoderOptions, MediaDirectory, MediaProvider, RenderOptions,
StaticMediaProvider,
};
-#[cfg(not(feature = "cpu"))]
-use fframes_skia_renderer::{SkiaFFramesRenderer, SkiaPipelineConfig, vulkan::SkiaVulkanCtx};
+use fframes_skia_renderer::{
+ SkiaPipelineConcurrencyPolicy, SkiaPipelineConfig, cli::SkiaRenderers,
+};
use pixel_memory_example::{ALL_SONGS, PixelMedia, PixelVideo, RandomPhotos};
use rand::prelude::*;
use std::process::ExitCode;
@@ -71,33 +70,17 @@ fn main() -> ExitCode {
..Default::default()
};
- #[cfg(feature = "cpu")]
- return cli::new(&video, options)
+ cli::new(&video, options)
.args(args)
.backend(fframes::cpu::CpuRenderingBackend {
cache_capacity: 300,
..Default::default()
})
- .run();
-
- #[cfg(not(feature = "cpu"))]
- {
- let vulkan_ctx = SkiaVulkanCtx::new(PixelVideo::WIDTH, PixelVideo::HEIGHT).unwrap();
- cli::new(&video, options)
- .args(args)
- .backend(
- SkiaFFramesRenderer::new_vulkan(
- &vulkan_ctx,
- SkiaPipelineConfig {
- buffer_queue_size: 20,
- concurrency_policy:
- fframes_skia_renderer::SkiaPipelineConcurrencyPolicy::MaxPerformance,
- ..Default::default()
- },
- )
- .expect("Failed to create the skia renderer"),
- )
- .preview(fframes_native_player::cli_preview)
- .run()
- }
+ .preview(fframes_native_player::cli_preview)
+ .renderers(SkiaRenderers::gpu(SkiaPipelineConfig {
+ buffer_queue_size: 20,
+ concurrency_policy: SkiaPipelineConcurrencyPolicy::MaxPerformance,
+ ..Default::default()
+ }))
+ .run()
}
diff --git a/examples/pixel-memory/src/pixel_video.rs b/examples/pixel-memory/src/pixel_video.rs
index 43cb6240..b95dfe77 100644
--- a/examples/pixel-memory/src/pixel_video.rs
+++ b/examples/pixel-memory/src/pixel_video.rs
@@ -72,6 +72,7 @@ impl Video for PixelVideo<'_> {
fframes::svgr!(
<svg
xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 1920 1080"
width={ctx.current_video_size.width}
height={ctx.current_video_size.height}
>
diff --git a/examples/pixel-memory/src/scenes/pixel_parallax_grid_photos.rs b/examples/pixel-memory/src/scenes/pixel_parallax_grid_photos.rs
index 177d5429..1bf8febe 100644
--- a/examples/pixel-memory/src/scenes/pixel_parallax_grid_photos.rs
+++ b/examples/pixel-memory/src/scenes/pixel_parallax_grid_photos.rs
@@ -1,6 +1,6 @@
-use crate::{FramedImage, PhotoFrame, pixel_video_randomizer::RandomPhotos};
+use crate::{FramedImage, PhotoFrame, PixelVideo, pixel_video_randomizer::RandomPhotos};
use fframes::{
- Scene, Svgr, Transform,
+ Scene, Svgr, Transform, Video,
animation::{Easing, KeyFrame, KeyFramesAnimation},
};
use rand::Rng;
@@ -86,7 +86,7 @@ impl Scene for ParallaxGridPhotos<'_> {
Some(
image.render_framed(PhotoFrame {
- x: ctx.current_video_size.width as f32 / 2.,
+ x: PixelVideo::WIDTH as f32 / 2.,
y: 1080. * index as f32 + (1080. - PHOTO_HEIGHT) / 2.,
width: width as u32,
height: PHOTO_HEIGHT as u32,
diff --git a/examples/pixel-memory/src/scenes/polariod_development.rs b/examples/pixel-memory/src/scenes/polariod_development.rs
index adac5e78..5be7f87b 100644
--- a/examples/pixel-memory/src/scenes/polariod_development.rs
+++ b/examples/pixel-memory/src/scenes/polariod_development.rs
@@ -37,8 +37,8 @@ impl Scene for PolaroidDevelopment<'_> {
frame: fframes::Frame,
ctx: &fframes::FFramesContext<'a, '_>,
) -> fframes::Svgr<'a> {
- let video_width = ctx.current_video_size.width as f32;
- let video_height = ctx.current_video_size.height as f32;
+ let video_width = PixelVideo::WIDTH as f32;
+ let video_height = PixelVideo::HEIGHT as f32;
fframes::svgr!(
<defs>
diff --git a/examples/podcast/Cargo.toml b/examples/podcast/Cargo.toml
index 59c8c83a..8d78e7cb 100644
--- a/examples/podcast/Cargo.toml
+++ b/examples/podcast/Cargo.toml
@@ -4,14 +4,19 @@ version = "1.2.0"
edition = "2024"
[dependencies]
-fframes = { workspace = true, features = ["h264", "libav-agree-gpl"] }
+fframes.workspace = true
-[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
-fframes_skia_renderer = { workspace = true, features = ["vulkan"] }
+# `--renderer cpu|skia-cpu|gpu`: Skia on Metal on macOS, on Vulkan everywhere else
+[target.'cfg(target_os = "macos")'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["metal", "cli"] }
-# Keep FFmpeg source fallbacks portable across CI runner CPUs (see README).
+[target.'cfg(not(any(target_os = "macos", target_arch = "wasm32")))'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["vulkan", "cli"] }
+
+# FFmpeg codecs, portable so cached source builds work across CI runner CPUs. Windows
+# links a prebuilt FFmpeg instead (see README).
[target.'cfg(not(any(target_arch = "wasm32", windows)))'.dependencies]
-fframes = { workspace = true, features = ["build-portable"] }
+fframes = { workspace = true, features = ["h264", "libav-agree-gpl", "build-portable"] }
[features]
default = ["renderer"]
diff --git a/examples/podcast/src/main.rs b/examples/podcast/src/main.rs
index ba5146e9..9e67ee84 100644
--- a/examples/podcast/src/main.rs
+++ b/examples/podcast/src/main.rs
@@ -1,4 +1,5 @@
use fframes::{EncoderOptions, MediaDirectory, RenderOptions, cli};
+use fframes_skia_renderer::cli::SkiaRenderers;
use podcast_example::PodcastVideo;
use std::path::Path;
use std::process::ExitCode;
@@ -22,5 +23,6 @@ fn main() -> ExitCode {
..Default::default()
},
)
+ .renderers(SkiaRenderers::default())
.run()
}
diff --git a/examples/shader-mode/Cargo.toml b/examples/shader-mode/Cargo.toml
index 1e559d8e..ef80b6cd 100644
--- a/examples/shader-mode/Cargo.toml
+++ b/examples/shader-mode/Cargo.toml
@@ -7,13 +7,15 @@ publish = false
[dependencies]
fframes = { workspace = true, features = ["compile-time-svgtree", "cli"] }
+# `--renderer cpu|skia-cpu|gpu`: Skia on Metal on macOS, on Vulkan everywhere else
+# `preview`: real-time GPU window
[target.'cfg(target_os = "macos")'.dependencies]
-fframes_skia_renderer = { workspace = true, features = ["metal"] }
-fframes_native_player = { workspace = true, features = ["metal"] }
+fframes_skia_renderer = { workspace = true, features = ["metal", "cli"] }
+fframes_native_player = { workspace = true, features = ["metal", "audio"] }
[target.'cfg(not(target_os = "macos"))'.dependencies]
-fframes_skia_renderer = { workspace = true, features = ["vulkan"] }
-fframes_native_player.workspace = true
+fframes_skia_renderer = { workspace = true, features = ["vulkan", "cli"] }
+fframes_native_player = { workspace = true, features = ["vulkan", "audio"] }
[target.'cfg(not(windows))'.dependencies]
fframes = { workspace = true, features = ["h264", "libav-agree-gpl", "build-portable"] }
diff --git a/examples/shader-mode/src/main.rs b/examples/shader-mode/src/main.rs
index 2400f7b6..4e6c8791 100644
--- a/examples/shader-mode/src/main.rs
+++ b/examples/shader-mode/src/main.rs
@@ -2,9 +2,9 @@ use std::process::ExitCode;
use fframes::{
AudioMixOptions, CombinedMediaProvider, EncoderOptions, MediaDirectory, MediaProvider,
- RenderOptions, StaticMediaProvider, Video, cli,
+ RenderOptions, StaticMediaProvider, cli,
};
-use fframes_skia_renderer::{SkiaFFramesRenderer, SkiaPipelineConfig};
+use fframes_skia_renderer::{SkiaPipelineConfig, cli::SkiaRenderers};
use shader_mode::{ShaderMode, ShaderModeMedia};
fn run() -> Result<ExitCode, Box<dyn std::error::Error>> {
@@ -15,17 +15,6 @@ fn run() -> Result<ExitCode, Box<dyn std::error::Error>> {
let dynamic = directory.process_media_source()?;
let all = CombinedMediaProvider::from([&media as &dyn MediaProvider, &dynamic]);
let video = ShaderMode::new();
- #[cfg(target_os = "macos")]
- let gpu =
- fframes_skia_renderer::metal::SkiaMetalCtx::new(ShaderMode::WIDTH, ShaderMode::HEIGHT)?;
- #[cfg(not(target_os = "macos"))]
- let gpu =
- fframes_skia_renderer::vulkan::SkiaVulkanCtx::new(ShaderMode::WIDTH, ShaderMode::HEIGHT)?;
-
- #[cfg(target_os = "macos")]
- let backend = SkiaFFramesRenderer::new_metal(&gpu, SkiaPipelineConfig::default())?;
- #[cfg(not(target_os = "macos"))]
- let backend = SkiaFFramesRenderer::new_vulkan(&gpu, SkiaPipelineConfig::default())?;
Ok(cli::new(
&video,
@@ -44,9 +33,9 @@ fn run() -> Result<ExitCode, Box<dyn std::error::Error>> {
..Default::default()
},
)
- .backend(backend)
.preview(fframes_native_player::cli_preview)
.default_output(std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("output/shader-mode.mp4"))
+ .renderers(SkiaRenderers::gpu(SkiaPipelineConfig::default()))
.run())
}
diff --git a/examples/shaders/Cargo.toml b/examples/shaders/Cargo.toml
index 58f23a64..f02e0c58 100644
--- a/examples/shaders/Cargo.toml
+++ b/examples/shaders/Cargo.toml
@@ -4,23 +4,28 @@ version = "1.2.0"
edition = "2024"
[dependencies]
-fframes = { workspace = true, features = ["h264", "h265", "libav-agree-gpl"] }
+fframes.workspace = true
clap = { version = "4.3.4", features = ["derive"] }
# Shaders are executed by the Skia backend; the editor bridge (wasm) only
# needs `fframes` and shows a placeholder in their place.
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
-fframes_skia_renderer = { workspace = true, features = ["vulkan"] }
image = "0.25.5"
-# `preview`: real-time GPU window
-fframes_native_player.workspace = true
+# `--renderer cpu|skia-cpu|gpu`: Skia on Metal on macOS, on Vulkan everywhere else
+# `preview`: real-time GPU window
[target.'cfg(target_os = "macos")'.dependencies]
-fframes_native_player = { workspace = true, features = ["metal"] }
+fframes_skia_renderer = { workspace = true, features = ["metal", "cli"] }
+fframes_native_player = { workspace = true, features = ["metal", "audio"] }
+
+[target.'cfg(not(any(target_os = "macos", target_arch = "wasm32")))'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["vulkan", "cli"] }
+fframes_native_player = { workspace = true, features = ["vulkan", "audio"] }
-# Keep FFmpeg source fallbacks portable across CI runner CPUs (see README).
+# FFmpeg codecs, portable so cached source builds work across CI runner CPUs. Windows
+# links a prebuilt FFmpeg instead (see README).
[target.'cfg(not(any(target_arch = "wasm32", windows)))'.dependencies]
-fframes = { workspace = true, features = ["build-portable"] }
+fframes = { workspace = true, features = ["h264", "h265", "libav-agree-gpl", "build-portable"] }
[features]
default = ["renderer"]
diff --git a/examples/shaders/src/main.rs b/examples/shaders/src/main.rs
index 4b769ecb..f28a324d 100644
--- a/examples/shaders/src/main.rs
+++ b/examples/shaders/src/main.rs
@@ -1,6 +1,6 @@
use fframes::cli::{self, clap};
-use fframes::{EncoderOptions, RenderOptions, StaticMediaProvider, Video};
-use fframes_skia_renderer::{SkiaFFramesRenderer, SkiaPipelineConfig, vulkan::SkiaVulkanCtx};
+use fframes::{EncoderOptions, RenderOptions, StaticMediaProvider};
+use fframes_skia_renderer::{SkiaPipelineConfig, cli::SkiaRenderers};
use shaders_example::{ShadersMedia, ShadersVideo};
use std::process::ExitCode;
@@ -17,9 +17,7 @@ fn main() -> ExitCode {
let video_codec = args.app.video_codec.clone();
// Shaders run on the Skia backend's own GPU surface; the tiny-skia CPU
- // backend would draw nothing in their place, so previews use Skia too.
- let vulkan_ctx = SkiaVulkanCtx::new(ShadersVideo::WIDTH, ShadersVideo::HEIGHT).unwrap();
-
+ // backend (`--renderer cpu`) draws nothing in their place.
cli::new(
&video,
RenderOptions {
@@ -33,10 +31,7 @@ fn main() -> ExitCode {
},
)
.args(args)
- .backend(
- SkiaFFramesRenderer::new_vulkan(&vulkan_ctx, SkiaPipelineConfig::default())
- .expect("Failed to create renderer"),
- )
.preview(fframes_native_player::cli_preview)
+ .renderers(SkiaRenderers::gpu(SkiaPipelineConfig::default()))
.run()
}
diff --git a/examples/shaders/src/shaders/aurora.sksl b/examples/shaders/src/shaders/aurora.sksl
index 119ef344..d0b4da9e 100644
--- a/examples/shaders/src/shaders/aurora.sksl
+++ b/examples/shaders/src/shaders/aurora.sksl
@@ -5,8 +5,12 @@ uniform float4 uColorA;
uniform float4 uColorB;
uniform float uSpeed;
+// No sin(): GPUs compute it with less precision than CPUs, so a sin() hash gives every
+// device different noise. "Hash without Sine" by Dave Hoskins.
float hash(float2 p) {
- return fract(sin(dot(p, float2(127.1, 311.7))) * 43758.5453);
+ float3 p3 = fract(float3(p.xyx) * 0.1031);
+ p3 += dot(p3, p3.yzx + 33.33);
+ return fract((p3.x + p3.y) * p3.z);
}
float noise(float2 p) {
diff --git a/examples/signal-lab/Cargo.toml b/examples/signal-lab/Cargo.toml
index 99442668..2a2daf38 100644
--- a/examples/signal-lab/Cargo.toml
+++ b/examples/signal-lab/Cargo.toml
@@ -7,14 +7,15 @@ publish = false
[dependencies]
fframes = { workspace = true, features = ["compile-time-svgtree", "cli"] }
-# Metal on macOS, Vulkan everywhere else
+# `--renderer cpu|skia-cpu|gpu`: Skia on Metal on macOS, on Vulkan everywhere else
+# `preview`: real-time GPU window
[target.'cfg(target_os = "macos")'.dependencies]
-fframes_skia_renderer = { workspace = true, features = ["metal"] }
-fframes_native_player = { workspace = true, features = ["metal"] }
+fframes_skia_renderer = { workspace = true, features = ["metal", "cli"] }
+fframes_native_player = { workspace = true, features = ["metal", "audio"] }
-[target.'cfg(not(target_os = "macos"))'.dependencies]
-fframes_skia_renderer = { workspace = true, features = ["vulkan"] }
-fframes_native_player.workspace = true
+[target.'cfg(not(any(target_os = "macos", target_arch = "wasm32")))'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["vulkan", "cli"] }
+fframes_native_player = { workspace = true, features = ["vulkan", "audio"] }
[target.'cfg(not(windows))'.dependencies]
fframes = { workspace = true, features = ["h264", "libav-agree-gpl"] }
diff --git a/examples/signal-lab/src/main.rs b/examples/signal-lab/src/main.rs
index 47a4ad14..eba4808b 100644
--- a/examples/signal-lab/src/main.rs
+++ b/examples/signal-lab/src/main.rs
@@ -1,9 +1,9 @@
use fframes::cli::clap; // the derive below expands to `clap::...`
use fframes::{EncoderOptions, RenderOptions, StaticMediaProvider, cli};
use fframes_skia_renderer::{
- SkiaFFramesRenderer, SkiaPipelineConcurrencyPolicy, SkiaPipelineConfig,
+ SkiaPipelineConcurrencyPolicy, SkiaPipelineConfig, cli::SkiaRenderers,
};
-use signal_lab::{HEIGHT, SignalLabMedia, SignalLabVideo, WIDTH};
+use signal_lab::{SignalLabMedia, SignalLabVideo};
use std::process::ExitCode;
/// Flags of this video next to the standard ones of `fframes::cli` (render, frame, strip,
@@ -15,19 +15,6 @@ fn main() -> ExitCode {
let args = cli::parse::<VideoArgs>();
let media = SignalLabMedia::prepare().expect("media");
let video = SignalLabVideo;
- #[cfg(target_os = "macos")]
- let gpu = fframes_skia_renderer::metal::SkiaMetalCtx::new(WIDTH, HEIGHT).expect("GPU context");
- #[cfg(not(target_os = "macos"))]
- let gpu =
- fframes_skia_renderer::vulkan::SkiaVulkanCtx::new(WIDTH, HEIGHT).expect("GPU context");
- let pipeline = SkiaPipelineConfig {
- concurrency_policy: SkiaPipelineConcurrencyPolicy::MaxPerformance,
- ..Default::default()
- };
- #[cfg(target_os = "macos")]
- let backend = SkiaFFramesRenderer::new_metal(&gpu, pipeline);
- #[cfg(not(target_os = "macos"))]
- let backend = SkiaFFramesRenderer::new_vulkan(&gpu, pipeline);
cli::new(
&video,
@@ -42,7 +29,10 @@ fn main() -> ExitCode {
},
)
.args(args)
- .backend(backend.expect("skia renderer"))
.preview(fframes_native_player::cli_preview)
+ .renderers(SkiaRenderers::gpu(SkiaPipelineConfig {
+ concurrency_policy: SkiaPipelineConcurrencyPolicy::MaxPerformance,
+ ..Default::default()
+ }))
.run()
}
diff --git a/examples/teej-podcast/Cargo.toml b/examples/teej-podcast/Cargo.toml
index 4b560724..0e8a349c 100644
--- a/examples/teej-podcast/Cargo.toml
+++ b/examples/teej-podcast/Cargo.toml
@@ -5,23 +5,25 @@ edition = "2024"
[dependencies]
clap = { version = "4.3.4", features = ["derive"] }
-fframes = { workspace = true, features = ["h264", "h265", "libav-agree-gpl"] }
+fframes.workspace = true
-[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
-fframes_skia_renderer = { workspace = true, features = ["vulkan"] }
+# `--renderer cpu|skia-cpu|gpu`: Skia on Metal on macOS, on Vulkan everywhere else
# `preview`: real-time GPU window
-fframes_native_player.workspace = true
-
+[target.'cfg(target_os = "macos")'.dependencies]
# `main.rs` asks for `hevc_videotoolbox` on macOS, which only exists when
# ffmpeg is built with VideoToolbox.
-[target.'cfg(target_os = "macos")'.dependencies]
fframes = { workspace = true, features = ["videotoolbox"] }
-# Metal for the preview window, no MoltenVK needed
-fframes_native_player = { workspace = true, features = ["metal"] }
+fframes_skia_renderer = { workspace = true, features = ["metal", "cli"] }
+fframes_native_player = { workspace = true, features = ["metal", "audio"] }
+
+[target.'cfg(not(any(target_os = "macos", target_arch = "wasm32")))'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["vulkan", "cli"] }
+fframes_native_player = { workspace = true, features = ["vulkan", "audio"] }
-# Keep FFmpeg source fallbacks portable across CI runner CPUs (see README).
+# FFmpeg codecs, portable so cached source builds work across CI runner CPUs. Windows
+# links a prebuilt FFmpeg instead (see README).
[target.'cfg(not(any(target_arch = "wasm32", windows)))'.dependencies]
-fframes = { workspace = true, features = ["build-portable"] }
+fframes = { workspace = true, features = ["h264", "h265", "libav-agree-gpl", "build-portable"] }
[features]
default = ["renderer"]
diff --git a/examples/teej-podcast/dynamic_media/JetBrainsMono-Regular.ttf b/examples/teej-podcast/dynamic_media/JetBrainsMono-Regular.ttf
new file mode 100644
index 00000000..7d26f5a5
Binary files /dev/null and b/examples/teej-podcast/dynamic_media/JetBrainsMono-Regular.ttf differ
diff --git a/examples/teej-podcast/src/main.rs b/examples/teej-podcast/src/main.rs
index 62b553cc..0a95d1eb 100644
--- a/examples/teej-podcast/src/main.rs
+++ b/examples/teej-podcast/src/main.rs
@@ -1,5 +1,7 @@
-use fframes::{EncoderOptions, MediaDirectory, RenderOptions, Video, cli};
-use fframes_skia_renderer::{SkiaFFramesRenderer, SkiaPipelineConfig, vulkan::SkiaVulkanCtx};
+use fframes::{EncoderOptions, MediaDirectory, RenderOptions, cli};
+use fframes_skia_renderer::{
+ SkiaPipelineConcurrencyPolicy, SkiaPipelineConfig, cli::SkiaRenderers,
+};
use std::path::Path;
use std::process::ExitCode;
use teej_podcast_example::{Chapter, TeejPodcast};
@@ -7,7 +9,6 @@ use teej_podcast_example::{Chapter, TeejPodcast};
fn main() -> ExitCode {
let media_folder = MediaDirectory::read_folder(Path::new("./dynamic_media")).unwrap();
let dynamic_media = media_folder.process_media_source().unwrap();
- let vulkan_ctx = SkiaVulkanCtx::new(TeejPodcast::WIDTH, TeejPodcast::HEIGHT).unwrap();
let chapters = [
Chapter::new("Introduction to Lunch Bites Podcast", "00:00"),
@@ -51,18 +52,11 @@ fn main() -> ExitCode {
};
cli::new(&video, options)
- .backend(
- SkiaFFramesRenderer::new_vulkan(
- &vulkan_ctx,
- SkiaPipelineConfig {
- buffer_queue_size: 20,
- concurrency_policy:
- fframes_skia_renderer::SkiaPipelineConcurrencyPolicy::MaxPerformance,
- ..Default::default()
- },
- )
- .expect("Failed to create renderer"),
- )
.preview(fframes_native_player::cli_preview)
+ .renderers(SkiaRenderers::gpu(SkiaPipelineConfig {
+ buffer_queue_size: 20,
+ concurrency_policy: SkiaPipelineConcurrencyPolicy::MaxPerformance,
+ ..Default::default()
+ }))
.run()
}
diff --git a/examples/teej-podcast/src/teej_podcast.rs b/examples/teej-podcast/src/teej_podcast.rs
index 27f1171b..445d540b 100644
--- a/examples/teej-podcast/src/teej_podcast.rs
+++ b/examples/teej-podcast/src/teej_podcast.rs
@@ -198,7 +198,7 @@ impl Video for TeejPodcast<'_> {
alignment-baseline="text-before-edge"
font-size="75"
fill="#fff"
- font-family="Berkeley Mono"
+ font-family="JetBrains Mono"
>
"2D: Rust"
</text>
diff --git a/examples/tiktok/Cargo.toml b/examples/tiktok/Cargo.toml
index 68778735..929b68c7 100644
--- a/examples/tiktok/Cargo.toml
+++ b/examples/tiktok/Cargo.toml
@@ -4,13 +4,21 @@ version = "1.2.0"
edition = "2024"
[dependencies]
-fframes = { workspace = true, features = ["vpx", "opus"] }
+fframes.workspace = true
tiktok-media ={path="./media"}
libm="0.2.8"
-# Keep FFmpeg source fallbacks portable across CI runner CPUs (see README).
+# `--renderer cpu|skia-cpu|gpu`: Skia on Metal on macOS, on Vulkan everywhere else
+[target.'cfg(target_os = "macos")'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["metal", "cli"] }
+
+[target.'cfg(not(any(target_os = "macos", target_arch = "wasm32")))'.dependencies]
+fframes_skia_renderer = { workspace = true, features = ["vulkan", "cli"] }
+
+# FFmpeg codecs, portable so cached source builds work across CI runner CPUs. Windows
+# links a prebuilt FFmpeg instead (see README).
[target.'cfg(not(any(target_arch = "wasm32", windows)))'.dependencies]
-fframes = { workspace = true, features = ["build-portable"] }
+fframes = { workspace = true, features = ["vpx", "opus", "build-portable"] }
[features]
default=["renderer"]
diff --git a/examples/tiktok/src/main.rs b/examples/tiktok/src/main.rs
index 0f03d8c6..d26fc848 100644
--- a/examples/tiktok/src/main.rs
+++ b/examples/tiktok/src/main.rs
@@ -1,4 +1,5 @@
use fframes::{EncoderOptions, RenderOptions, StaticMediaProvider, cli};
+use fframes_skia_renderer::cli::SkiaRenderers;
use std::path::PathBuf;
use std::process::ExitCode;
use tiktok_example::{GooseMedia, GooseVideo};
@@ -33,5 +34,6 @@ fn main() -> ExitCode {
..Default::default()
})
.default_output("out.webm")
+ .renderers(SkiaRenderers::default())
.run()
}
diff --git a/fframes-skia-renderer/Cargo.toml b/fframes-skia-renderer/Cargo.toml
index 625fa09a..9ca5562c 100644
--- a/fframes-skia-renderer/Cargo.toml
+++ b/fframes-skia-renderer/Cargo.toml
@@ -48,6 +48,8 @@ vulkan = ["gpu", "skia-safe/vulkan", "ash"]
# Share the Vulkan device with FFmpeg, so Vulkan Video encoders (h264_vulkan, hevc_vulkan)
# read the frames on the GPU. Builds FFmpeg with Vulkan support.
vulkan-video = ["vulkan", "fframes/vulkan"]
+# `--renderer skia-cpu|gpu` for `fframes::cli`, see `cli::SkiaRenderers`
+cli = ["fframes/cli"]
d3d = ["skia-safe/d3d"]
gl = ["skia-safe/gl"]
x11 = ["skia-safe/x11"]
diff --git a/fframes-skia-renderer/src/cli.rs b/fframes-skia-renderer/src/cli.rs
new file mode 100644
index 00000000..20cfb398
--- /dev/null
+++ b/fframes-skia-renderer/src/cli.rs
@@ -0,0 +1,73 @@
+//! `--renderer skia-cpu|gpu` for [`fframes::cli`]: the same binary renders with Skia on the CPU
+//! or on the GPU (Metal on macOS, Vulkan elsewhere).
+use crate::{SkiaCpuCtx, SkiaFFramesRenderer, SkiaPipelineConfig};
+use fframes::cli::{Renderer, Renderers, Runner, clap::Args};
+use fframes::{FFramesRenderBackend, Video};
+use std::process::ExitCode;
+
+/// The Skia backends for `Runner::renderers`. GPU contexts are only created when they render.
+///
+/// ```ignore
+/// cli::new(&video, options)
+/// .renderers(SkiaRenderers::gpu(SkiaPipelineConfig::default()))
+/// .run()
+/// ```
+#[derive(Debug, Clone, Copy, Default)]
+pub struct SkiaRenderers {
+ /// What renders without `--renderer`, `None` for the runner's backend.
+ pub default: Option<Renderer>,
+ pub pipeline: SkiaPipelineConfig,
+}
+
+impl SkiaRenderers {
+ /// Skia on the GPU unless `--renderer` asks for another backend.
+ pub fn gpu(pipeline: SkiaPipelineConfig) -> Self {
+ Self {
+ default: Some(Renderer::Gpu),
+ pipeline,
+ }
+ }
+}
+
+impl Renderers for SkiaRenderers {
+ fn default_renderer(&self) -> Option<Renderer> {
+ self.default
+ }
+
+ fn run<'r, 'a, 'media: 'a, V: Video + Send + Sync, B: FFramesRenderBackend, A: Args>(
+ self,
+ renderer: Renderer,
+ runner: Runner<'r, 'a, 'media, V, B, A>,
+ ) -> ExitCode {
+ let pipeline = self.pipeline;
+ match renderer {
+ Renderer::Cpu => runner
+ .backend(fframes::cpu::CpuRenderingBackend::default())
+ .run(),
+ Renderer::SkiaCpu => {
+ let cpu = SkiaCpuCtx::new(V::WIDTH, V::HEIGHT);
+ runner
+ .backend(SkiaFFramesRenderer::new(pipeline, &cpu))
+ .run()
+ }
+ #[cfg(feature = "metal")]
+ Renderer::Gpu => match crate::metal::SkiaMetalCtx::new(V::WIDTH, V::HEIGHT) {
+ Ok(gpu) => runner
+ .backend(SkiaFFramesRenderer::new(pipeline, &gpu))
+ .run(),
+ Err(err) => runner.fail(err),
+ },
+ #[cfg(all(feature = "vulkan", not(feature = "metal")))]
+ Renderer::Gpu => match crate::vulkan::SkiaVulkanCtx::new(V::WIDTH, V::HEIGHT) {
+ Ok(gpu) => runner
+ .backend(SkiaFFramesRenderer::new(pipeline, &gpu))
+ .run(),
+ Err(err) => runner.fail(err),
+ },
+ #[cfg(not(any(feature = "metal", feature = "vulkan")))]
+ Renderer::Gpu => {
+ runner.fail("built without the metal or vulkan feature of fframes_skia_renderer")
+ }
+ }
+ }
+}
diff --git a/fframes-skia-renderer/src/lib.rs b/fframes-skia-renderer/src/lib.rs
index abffdc73..70c930a9 100644
--- a/fframes-skia-renderer/src/lib.rs
+++ b/fframes-skia-renderer/src/lib.rs
@@ -25,6 +25,9 @@ pub use frame_export::{
pub mod render;
+#[cfg(feature = "cli")]
+pub mod cli;
+
#[cfg(feature = "debug")]
mod metrics;
diff --git a/fframes/src/renderer/cli.rs b/fframes/src/renderer/cli.rs
index db96485d..ef0c1a17 100644
--- a/fframes/src/renderer/cli.rs
+++ b/fframes/src/renderer/cli.rs
@@ -60,6 +60,22 @@ pub struct Cli<A: Args = NoArgs> {
/// Output resolution factor, e.g. 0.5 for half resolution.
#[arg(long, global = true)]
pub scale: Option<f64>,
+
+ /// Render with this backend instead of the video's own. The Skia ones need
+ /// `Runner::renderers`.
+ #[arg(long, global = true, value_enum)]
+ pub renderer: Option<Renderer>,
+}
+
+/// The backends `--renderer` picks from.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
+pub enum Renderer {
+ /// The built-in CPU backend (tiny-skia).
+ Cpu,
+ /// Skia on the CPU.
+ SkiaCpu,
+ /// Skia on the GPU: Metal on macOS, Vulkan elsewhere.
+ Gpu,
}
impl<A: Args> Cli<A> {
@@ -258,13 +274,57 @@ type Player<'r, 'a, 'media, V> = Box<
>;
/// The command line of one video, created with `cli::new`.
-pub struct Runner<'r, 'a, 'media, V, B = crate::cpu::CpuRenderingBackend, A: Args = NoArgs> {
+pub struct Runner<
+ 'r,
+ 'a,
+ 'media,
+ V,
+ B = crate::cpu::CpuRenderingBackend,
+ A: Args = NoArgs,
+ R = NoRenderers,
+> {
video: &'a V,
options: RenderOptions<'a, 'media>,
backend: B,
args: Option<Cli<A>>,
player: Option<Player<'r, 'a, 'media, V>>,
default_output: PathBuf,
+ renderers: R,
+}
+
+/// The backends behind `--renderer skia-cpu|gpu`, see `Runner::renderers`.
+pub trait Renderers {
+ /// What renders without `--renderer`, `None` for the runner's backend.
+ fn default_renderer(&self) -> Option<Renderer> {
+ None
+ }
+
+ /// Runs the command with the backend `renderer` asks for.
+ fn run<'r, 'a, 'media: 'a, V: Video + Send + Sync, B: FFramesRenderBackend, A: Args>(
+ self,
+ renderer: Renderer,
+ runner: Runner<'r, 'a, 'media, V, B, A>,
+ ) -> ExitCode;
+}
+
+/// Only `--renderer cpu`: the binary has no Skia.
+#[derive(Debug, Clone, Copy, Default)]
+pub struct NoRenderers;
+
+impl Renderers for NoRenderers {
+ fn run<'r, 'a, 'media: 'a, V: Video + Send + Sync, B: FFramesRenderBackend, A: Args>(
+ self,
+ renderer: Renderer,
+ runner: Runner<'r, 'a, 'media, V, B, A>,
+ ) -> ExitCode {
+ let name = renderer
+ .to_possible_value()
+ .map(|v| v.get_name().to_owned());
+ runner.fail(format!(
+ "--renderer {} needs `.renderers(fframes_skia_renderer::cli::SkiaRenderers::default())`",
+ name.unwrap_or_default()
+ ))
+ }
}
/// The command line for `video`: render, frame, strip, inspect, audio, ... Call `.run()`.
@@ -279,18 +339,19 @@ pub fn new<'a, 'media: 'a, V: Video + Send + Sync>(
args: None,
player: None,
default_output: PathBuf::from("out.mp4"),
+ renderers: NoRenderers,
}
}
-impl<'r, 'a, 'media: 'a, V: Video + Send + Sync, B: FFramesRenderBackend, A: Args>
- Runner<'r, 'a, 'media, V, B, A>
+impl<'r, 'a, 'media: 'a, V: Video + Send + Sync, B: FFramesRenderBackend, A: Args, R: Renderers>
+ Runner<'r, 'a, 'media, V, B, A, R>
{
/// Renders with another backend, e.g. `SkiaFFramesRenderer`. Frame previews use the
/// backend's own renderer, so they look like the rendered video.
pub fn backend<B2: FFramesRenderBackend>(
self,
backend: B2,
- ) -> Runner<'r, 'a, 'media, V, B2, A> {
+ ) -> Runner<'r, 'a, 'media, V, B2, A, R> {
Runner {
video: self.video,
options: self.options,
@@ -298,11 +359,12 @@ impl<'r, 'a, 'media: 'a, V: Video + Send + Sync, B: FFramesRenderBackend, A: Arg
args: self.args,
player: self.player,
default_output: self.default_output,
+ renderers: self.renderers,
}
}
/// Uses already parsed arguments with application flags (see `cli::parse`).
- pub fn args<A2: Args>(self, args: Cli<A2>) -> Runner<'r, 'a, 'media, V, B, A2> {
+ pub fn args<A2: Args>(self, args: Cli<A2>) -> Runner<'r, 'a, 'media, V, B, A2, R> {
Runner {
video: self.video,
options: self.options,
@@ -310,6 +372,7 @@ impl<'r, 'a, 'media: 'a, V: Video + Send + Sync, B: FFramesRenderBackend, A: Arg
args: Some(args),
player: self.player,
default_output: self.default_output,
+ renderers: self.renderers,
}
}
@@ -322,7 +385,7 @@ impl<'r, 'a, 'media: 'a, V: Video + Send + Sync, B: FFramesRenderBackend, A: Arg
&super::PreviewRequest,
) -> Result<(), String>
+ 'r2,
- ) -> Runner<'r2, 'a, 'media, V, B, A> {
+ ) -> Runner<'r2, 'a, 'media, V, B, A, R> {
Runner {
video: self.video,
options: self.options,
@@ -330,6 +393,7 @@ impl<'r, 'a, 'media: 'a, V: Video + Send + Sync, B: FFramesRenderBackend, A: Arg
args: self.args,
player: Some(Box::new(play)),
default_output: self.default_output,
+ renderers: self.renderers,
}
}
@@ -339,8 +403,52 @@ impl<'r, 'a, 'media: 'a, V: Video + Send + Sync, B: FFramesRenderBackend, A: Arg
self
}
+ /// Backends for `--renderer skia-cpu|gpu`, usually
+ /// `fframes_skia_renderer::cli::SkiaRenderers`. Without them only `--renderer cpu` works.
+ pub fn renderers<R2: Renderers>(self, renderers: R2) -> Runner<'r, 'a, 'media, V, B, A, R2> {
+ Runner {
+ video: self.video,
+ options: self.options,
+ backend: self.backend,
+ args: self.args,
+ player: self.player,
+ default_output: self.default_output,
+ renderers,
+ }
+ }
+
+ /// Reports an error like a failed command does and returns its exit code.
+ pub fn fail(self, message: impl std::fmt::Display) -> ExitCode {
+ fail(self.args.is_some_and(|args| args.json), message)
+ }
+
/// Parses the command line (unless `args` was given) and runs the command.
- pub fn run(self) -> ExitCode {
+ pub fn run(mut self) -> ExitCode {
+ let renderer = self
+ .args
+ .get_or_insert_with(Cli::<A>::parse)
+ .renderer
+ .take()
+ .or(self.renderers.default_renderer());
+ let runner = Runner {
+ video: self.video,
+ options: self.options,
+ backend: self.backend,
+ args: self.args,
+ player: self.player,
+ default_output: self.default_output,
+ renderers: NoRenderers,
+ };
+ match renderer {
+ None => runner.execute(),
+ Some(Renderer::Cpu) => runner
+ .backend(crate::cpu::CpuRenderingBackend::default())
+ .execute(),
+ Some(renderer) => self.renderers.run(renderer, runner),
+ }
+ }
+
+ fn execute(self) -> ExitCode {
let Runner {
video,
mut options,
@@ -348,6 +456,7 @@ impl<'r, 'a, 'media: 'a, V: Video + Send + Sync, B: FFramesRenderBackend, A: Arg
args,
player,
default_output,
+ renderers: _,
} = self;
let cli = args.unwrap_or_else(Cli::<A>::parse);
@@ -424,18 +533,17 @@ impl<'r, 'a, 'media: 'a, V: Video + Send + Sync, B: FFramesRenderBackend, A: Arg
}
};
- match result {
- Ok(code) => code,
- Err(message) => {
- if json {
- println!("{}", serde_json::json!({ "error": message }));
- } else {
- eprintln!("error: {message}");
- }
- ExitCode::FAILURE
- }
- }
+ result.unwrap_or_else(|message| fail(json, message))
+ }
+}
+
+fn fail(json: bool, message: impl std::fmt::Display) -> ExitCode {
+ if json {
+ println!("{}", serde_json::json!({ "error": message.to_string() }));
+ } else {
+ eprintln!("error: {message}");
}
+ ExitCode::FAILURE
}
fn print<T: Serialize>(json: bool, value: &T, text: impl FnOnce() -> String) {
diff --git a/justfile b/justfile
index 7eec8546..675b1428 100644
--- a/justfile
+++ b/justfile
@@ -99,6 +99,10 @@ test *ARGS:
cargo test {{ARGS}}
cargo test -p fframes_test_utils --no-default-features {{ARGS}}
+# Key frames of every example on one renderer against e2e/snapshots; --update accepts changes
+e2e renderer *ARGS:
+ node scripts/e2e.mjs {{renderer}} {{ARGS}}
+
# Render a markdown file in the terminal (defaults to the agent guidelines)
md file="AGENTS.md":
bat {{file}}
diff --git a/scripts/e2e.mjs b/scripts/e2e.mjs
new file mode 100644
index 00000000..a67e6aec
--- /dev/null
+++ b/scripts/e2e.mjs
@@ -0,0 +1,114 @@
+// Renders key frames of every example through its command line with one renderer and compares
+// them with odiff to e2e/snapshots, which every renderer has to match. Frames and diffs of the
+// run go to target/e2e/<renderer>.
+// node scripts/e2e.mjs cpu|skia-cpu|gpu [--update]
+import { spawnSync } from "node:child_process";
+import {
+ copyFileSync,
+ existsSync,
+ mkdirSync,
+ readdirSync,
+ rmSync,
+} from "node:fs";
+import { dirname, join } from "node:path";
+import { fileURLToPath } from "node:url";
+import { compare } from "odiff-bin";
+
+const [renderer, flag] = process.argv.slice(2);
+const update = flag === "--update";
+if (!["cpu", "skia-cpu", "gpu"].includes(renderer) || (flag && !update)) {
+ console.error("usage: node scripts/e2e.mjs cpu|skia-cpu|gpu [--update]");
+ process.exit(1);
+}
+
+// Renderers resample images and round colours differently: odiff's colour threshold 0.15
+// absorbs that, and up to 0.5% of the pixels may still differ.
+const THRESHOLD = 0.15;
+const MAX_DIFF_PERCENT = 0.5;
+
+const root = join(dirname(fileURLToPath(import.meta.url)), "..");
+const target = process.env.CARGO_TARGET_DIR ?? join(root, "target");
+const exe = process.platform === "win32" ? ".exe" : "";
+const out = join(target, "e2e", renderer);
+
+// `skia`: shaders, which the CPU renderer (tiny-skia) does not run. shader-mode is not here: its
+// media is kept outside Git.
+// prettier-ignore
+const examples = [
+ { dir: "audio-announce", pkg: "audio-announce-example", bin: "audio_announce_example_bin", frames: "5s,30s" },
+ { dir: "beta", pkg: "beta-example", bin: "beta_example_bin", frames: "CodeDemoScene@50%,IphoneScene@50%,BetaExamples@50%" },
+ { dir: "conference-splash-screen", pkg: "conference-splash-screen-example", bin: "conference_splash_screen_bin", frames: "SponsorScene@50%,SpeakerScene@50%" },
+ { dir: "fframes-intro", pkg: "fframes-intro", bin: "fframes-intro", frames: "CodeScene@50%,[email protected],[email protected],OutroScene@7s", skia: true },
+ { dir: "hello-world", pkg: "hello-world-example", bin: "hello_world_example_bin", frames: "5s,20s" },
+ { dir: "low-poly-art", pkg: "low-poly-art-example", bin: "low_poly_art_example_bin", frames: "Owl@3s,Owl@8s" },
+ { dir: "made-of-motion", pkg: "made-of-motion", bin: "made-of-motion", frames: "Portrait@50%,Orbit@50%,Fframes@50%", skia: true },
+ { dir: "marketing", pkg: "marketing-example", bin: "marketing-example", frames: "3s,10s,18s" },
+ { dir: "motion-graphics", pkg: "motion-graphics-example", bin: "motion_graphics_example_bin", frames: "1s,3s" },
+ { dir: "neon-triangle", pkg: "neon-triangle-example", bin: "neon_triangle_example_bin", frames: "2s,4s", skia: true },
+ { dir: "pixel-memory", pkg: "pixel-example", bin: "pixel_memory_example_bin", frames: "[email protected],ParallaxGridPhotos[0]@7s,SinglePhotoFloat[0]@50%,SpiralHeapGallery@50%", args: ["--song", "revenge.mp3", "--seed", "48"] },
+ { dir: "podcast", pkg: "podcast-example", bin: "podcast_example_bin", frames: "10s,40s" },
+ { dir: "shaders", pkg: "shaders-example", bin: "shaders_example_bin", frames: "2s,6s", skia: true },
+ { dir: "signal-lab", pkg: "signal-lab", bin: "signal-lab", frames: "ProductScene@3s,DataScene@3s,SystemScene@3s" },
+ { dir: "teej-podcast", pkg: "teej_podcast_example", bin: "teej_podcast_example_bin", frames: "10s,2:00" },
+ { dir: "tiktok", pkg: "tiktok-example", bin: "tiktok_example_bin", frames: "10s,30s" },
+];
+
+const run = (command, args, cwd) =>
+ spawnSync(command, args, { cwd, stdio: ["ignore", "ignore", "inherit"] })
+ .status === 0;
+
+// One build: each example on its own would compile FFmpeg for its own codecs.
+const packages = examples.flatMap(({ pkg }) => ["-p", pkg]);
+const build = ["build", "--release", "--bins", ...packages];
+if (spawnSync("cargo", build, { cwd: root, stdio: "inherit" }).status !== 0)
+ process.exit(1);
+
+rmSync(out, { recursive: true, force: true });
+const failed = [];
+const created = [];
+for (const { dir, bin, frames, skia, args = [] } of examples) {
+ if (skia && renderer === "cpu") continue;
+ const frameDir = join(out, dir);
+ const argv = [...args, "--renderer", renderer, "--scale", "0.5"];
+ argv.push("frame", frames, "-o", frameDir);
+ const binary = join(target, "release", bin + exe);
+ if (!run(binary, argv, join(root, "examples", dir))) {
+ failed.push(`${dir}: ${frames}`);
+ continue;
+ }
+
+ for (const file of readdirSync(frameDir)) {
+ const name = `${dir}/${file}`;
+ const actual = join(frameDir, file);
+ const snapshot = join(root, "e2e", "snapshots", dir, file);
+ if (!existsSync(snapshot)) {
+ mkdirSync(dirname(snapshot), { recursive: true });
+ copyFileSync(actual, snapshot);
+ created.push(name);
+ continue;
+ }
+
+ const diff = actual.replace(/\.png$/, ".diff.png");
+ const result = await compare(snapshot, actual, diff, {
+ antialiasing: true,
+ threshold: THRESHOLD,
+ });
+ const percent = result.match ? 0 : (result.diffPercentage ?? 100);
+ console.log(`${name}: ${percent.toFixed(3)}% differ`);
+ if (percent <= MAX_DIFF_PERCENT) continue;
+ if (update) copyFileSync(actual, snapshot);
+ else failed.push(`${name}: see ${diff}`);
+ }
+}
+
+if (created.length) {
+ console.error(
+ `new snapshots, look at them and commit them:\n${created.join("\n")}`
+ );
+ // CI compares nothing against a snapshot it just created
+ if (process.env.CI) process.exit(1);
+}
+if (failed.length) {
+ console.error(`frames differ (${renderer}):\n${failed.join("\n")}`);
+ process.exit(1);
+}