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.

raea render -o OUT.wav renders the sound alone, and --audio OUT.wav writes a video's sound beside it from the same pass

shinyobjectz1b5521832846
diff --git a/Cargo.lock b/Cargo.lock
index 696f12e1..c14bc51a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -13697,6 +13697,16 @@ dependencies = [
"serde_json",
]
+[[package]]
+name = "raea-app-sound"
+version = "0.1.0"
+dependencies = [
+ "raea-io-media",
+ "raea-runtime-bundle",
+ "raea-runtime-export",
+ "raea-sys-mix",
+]
+
[[package]]
name = "raea-app-targets"
version = "0.1.0"
@@ -13947,6 +13957,7 @@ dependencies = [
"raea-app-media",
"raea-app-play",
"raea-app-solid",
+ "raea-app-sound",
"raea-app-targets",
"raea-app-tools",
"raea-app-workspace",
diff --git a/Cargo.toml b/Cargo.toml
index bfd7d778..6a6d3a88 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -152,6 +152,7 @@ members = [
"runtime/shared",
"apps/check",
"apps/direction",
+ "apps/sound",
"apps/workspace",
"apps/workspace/registry",
"apps/ci",
diff --git a/apps/sound/Cargo.toml b/apps/sound/Cargo.toml
new file mode 100644
index 00000000..f5aa3f4f
--- /dev/null
+++ b/apps/sound/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "raea-app-sound"
+version = "0.1.0"
+edition = "2024"
+license = "FSL-1.1-ALv2"
+publish = false
+description = "A render's sound alone (`raea render EDIT.tsx -o OUT.wav`, no frames drawn) and a video's sound written beside it from the same pass (`--audio OUT.wav`)"
+
+[dependencies]
+raea-runtime-export = { path = "../../runtime/export" }
+raea-runtime-bundle = { path = "../../runtime/bundle" }
+raea-sys-mix = { path = "../../systems/mix" }
+raea-io-media = { path = "../../io/media", default-features = false }
diff --git a/apps/sound/src/lib.rs b/apps/sound/src/lib.rs
new file mode 100644
index 00000000..b56d4f0f
--- /dev/null
+++ b/apps/sound/src/lib.rs
@@ -0,0 +1,61 @@
+//! A render's sound on its own (Shane 11-10: "we should add an audio-only render and also be able to render video and
+//! audio at the same time"):
+//! raea render EDIT.tsx -o OUT.wav the sound alone, mixed and mastered as the video's is, no frame drawn:
+//! React stepped through every frame for its sounds (sound_only, which
+//! live play also mixes from), so a 2-minute film's sound is minutes
+//! sooner than its video
+//! raea render EDIT.tsx -o OUT.mp4 --audio A.wav the video, and beside it the very bounce it carries (before AAC),
+//! from the same pass: every render path writes RAEA_AUDIO_BOUNCE
+use raea_runtime_bundle::{R, flag};
+use std::path::{Path, PathBuf};
+
+fn is_wav(p: &Path) -> bool {
+ p.extension().and_then(|e| e.to_str()).is_some_and(|e| e.eq_ignore_ascii_case("wav"))
+}
+
+/// Some(the answer) for a sound render (`-o OUT.wav`); None for every other render, which goes on as before. A video
+/// render's `--audio A.wav` is set up here (the render writes it) and also answers None.
+pub fn render(args: &[String]) -> Option<R<String>> {
+ let out = PathBuf::from(flag(args, "-o")?);
+ if is_wav(&out) {
+ return Some(sound(args, &out));
+ }
+ let a = flag(args, "--audio")?;
+ if !is_wav(Path::new(&a)) {
+ return Some(Err(format!("--audio {a}: the sound is written as a .wav (OUT.wav)")));
+ }
+ let a = match std::path::absolute(&a) {
+ Ok(a) => a,
+ Err(e) => return Some(Err(format!("{a}: {e}"))),
+ };
+ // read where each render path bounces (raea-runtime-export sound.rs and fed.rs, raea-runtime-encode sound.rs); set
+ // before the render starts, as cli.rs sets RAEA_ROOT
+ unsafe { std::env::set_var("RAEA_AUDIO_BOUNCE", a) };
+ None
+}
+
+/// The composition's sound alone: bundled as a render bundles it (its --composition and flags), stepped for its sounds,
+/// mastered by its <Mix>, written as 48 kHz WAV, with what it measures.
+fn sound(args: &[String], out: &Path) -> R<String> {
+ let edit = args.get(1).filter(|a| !a.starts_with('-')).ok_or("raea render EDIT.tsx -o OUT.wav")?;
+ let tsx = PathBuf::from(edit).canonicalize().map_err(|e| format!("{edit}: {e}"))?;
+ let dir = tsx.parent().ok_or("the edit has no folder")?.to_path_buf();
+ let js = std::env::temp_dir().join(format!("raea-sound-{}.js", std::process::id()));
+ raea_runtime_bundle::bundle_composition(&tsx, &js, &raea_runtime_bundle::comp_opts(args)?, None)?;
+ let t = std::time::Instant::now();
+ let a = raea_runtime_export::sound_only(&js, &dir);
+ let _ = std::fs::remove_file(&js);
+ let a = a?.ok_or_else(|| format!("{edit} makes no sound: no <Audio>, no <Video> with sound and no Tone in any frame"))?;
+ if let Some(d) = out.parent().filter(|d| !d.as_os_str().is_empty()) {
+ std::fs::create_dir_all(d).map_err(|e| format!("{}: {e}", d.display()))?;
+ }
+ raea_sys_mix::write_wav(&a, out)?;
+ Ok(format!(
+ "{}: {:.1} s of sound, {:.1} LUFS, true peak {:.1} dBTP, in {:.1} s (no frames drawn)",
+ out.display(),
+ a.duration(),
+ raea_io_media::audio::lufs(&a),
+ raea_io_media::audio::true_peak_db(&a),
+ t.elapsed().as_secs_f64()
+ ))
+}
diff --git a/docs/manual/reference/cli/render.md b/docs/manual/reference/cli/render.md
index e2e665d7..81d9645e 100644
--- a/docs/manual/reference/cli/render.md
+++ b/docs/manual/reference/cli/render.md
@@ -16,10 +16,17 @@ raea render piece.tsx --at 15,63,144 -o stills/ # some frames, as still
raea render piece.tsx --alpha -o frames/ # every frame as a transparent PNG
raea render piece.tsx --quality master -o final.mp4 # constant quality for type and thin lines
raea render scene.tsx --review review/ # a 3D scene from six fixed cameras, in colour and clay
+raea render piece.tsx -o piece.wav # the sound alone, no frames drawn
+raea render piece.tsx -o piece.mp4 --audio piece.wav # the video, and its sound beside it from the same pass
```
-What `-o` names decides what you get: a name ending in `.mp4` is a video, `.png` is one frame, and anything else is
-a folder of `frame-NNNNN.png`. The folder an output goes in must exist.
+What `-o` names decides what you get: a name ending in `.mp4` is a video, `.png` is one frame, `.wav` is the sound
+alone, and anything else is a folder of `frame-NNNNN.png`. The folder an output goes in must exist, except for a
+`.wav`.
+
+The sound alone is mixed and mastered as the video's is (its `<Mix>`'s loudness and ceiling), from the same cues, but
+no frame is drawn, so a long film's sound is ready long before its video; the command prints its loudness and true
+peak. `--audio` on a video render writes the very sound the video carries, before it is encoded to AAC.
A composition's size, frame rate and length come from its `<Composition>` (or an `export const config`); `--w`,
`--h`, `--fps` and `--frames` only apply to a file that states neither. A `words.json` and a `perception.json` next
@@ -33,7 +40,7 @@ and the command says so.
## Usage
```sh
-raea render EDIT.tsx -o OUT.mp4|OUT.png|DIR [--frame N | --at A,B] [--composition ID] [--w W] [--h H] [--fps FPS] [--frames N] [--words W.json] [--perception P.json] [--input I.json|inputs.rrl] [--manifest render.json] [--layers] [--stage WxH] [--10bit] [--aov] [--alpha] [--kbps N | --quality draft|high|master|0..1] [--clay] (also: --lite --comps)
+raea render EDIT.tsx -o OUT.mp4|OUT.png|OUT.wav|DIR [--audio OUT.wav] [--frame N | --at A,B] [--composition ID] [--w W] [--h H] [--fps FPS] [--frames N] [--words W.json] [--perception P.json] [--input I.json|inputs.rrl] [--manifest render.json] [--layers] [--stage WxH] [--10bit] [--aov] [--alpha] [--kbps N | --quality draft|high|master|0..1] [--clay] (also: --lite --comps)
raea render EDIT.tsx --review DIR [--frame N] (fixed cameras hero, front, right, top, iso, low in colour and clay: DIR/colour.png, clay.png, review.json)
raea render PAGE.html -o OUT.mp4|OUT.png|DIR [--at A,B] [--alpha] (an HTML composition)
raea render --bundle NAME.comp.js -o OUT.png|DIR [--dir DIR] [--frame N] (a bundle from raea bundle, as render_bundle draws it)
@@ -49,6 +56,7 @@ Headless: it needs nothing running and opens no window. Takes up to 1 argument b
| `--alpha` | – | Keep the background transparent. Writes PNGs only (`-o OUT.png` or a folder): H.264 and HEVC hold no alpha, so encode the folder to ProRes 4444 afterwards if you need a video. |
| `--aov` | – | Write each frame's motion vectors and depth beside its colour, in `DIR/motion` and `DIR/depth`, for [`raea neural`](neural.md). `-o` must name a folder. |
| `--at` | `A,B` | Render only these frame numbers, comma-separated. |
+| `--audio` | `OUT.wav` | With a video `-o`: also write its sound to `OUT.wav`, the same mastered sound the video carries (before AAC), from the same pass. |
| `--bundle` | `NAME.comp.js` | Render a bundle made by `raea bundle` instead of a TSX file, as `render_bundle` on the iPhone draws it. |
| `--clay` | – | Draw every standard 3D surface in plain grey, to judge shapes, light and contact without colour. |
| `--composition` | `ID` | Which registered `<Composition>` to render when the file holds several; the first one otherwise. |
@@ -69,7 +77,7 @@ Headless: it needs nothing running and opens no window. Takes up to 1 argument b
| `--stage` | `WxH` | Render a responsive composition, one that lays out from `useVideoConfig()`, at this size. A fixed-size composition ignores it and says so. |
| `--w` | `W` | Width in pixels for a file with no `<Composition>` or `config` (1080 by default). |
| `--words` | `W.json` | A transcript for the Clock's words (captions and cuts read them), when it isn't the `words.json` beside the composition. |
-| `-o` | `OUT.mp4\|OUT.png\|DIR` | Where it goes: an `.mp4` video, one `.png`, or a folder of frames. |
+| `-o` | `OUT.mp4\|OUT.png\|OUT.wav\|DIR` | Where it goes: an `.mp4` video, one `.png`, the sound alone as a `.wav`, or a folder of frames. |
<!-- generated:end -->
diff --git a/engine/cli/Cargo.toml b/engine/cli/Cargo.toml
index ac405cc0..7bd0bda9 100644
--- a/engine/cli/Cargo.toml
+++ b/engine/cli/Cargo.toml
@@ -51,6 +51,7 @@ regex = "1"
# the app crates' verbs: `raea check`, `raea ci`, and the local tools' (sao, tokensynth, setup-audio, sounds, splat)
raea-app-check = { path = "../../apps/check" }
raea-app-direction = { path = "../../apps/direction" }
+raea-app-sound = { path = "../../apps/sound" }
raea-app-ci = { path = "../../apps/ci" }
raea-app-tools = { path = "../../apps/tools" }
# raea solid info|view: a solid file measured and pictured
diff --git a/engine/cli/src/cli.rs b/engine/cli/src/cli.rs
index 544e1733..b705c326 100644
--- a/engine/cli/src/cli.rs
+++ b/engine/cli/src/cli.rs
@@ -347,12 +347,13 @@ pub fn run(args: &[String]) -> R<String> {
}
if args.first().map(String::as_str) != Some("render") || args.len() < 2 {
return Err(format!(
- "raea render EDIT.tsx -o OUT.mp4|OUT.png|DIR [--frame N | --at A,B] [--composition ID] [--w W] [--h H] [--fps FPS] [--frames N] [--words W.json] [--perception P.json] [--input I.json|inputs.rrl] [--manifest render.json] [--layers] [--stage WxH] [--10bit] [--aov] [--alpha] [--kbps N | --quality draft|high|master|0..1] [--clay] (also: --lite --comps)\n raea render EDIT.tsx --review DIR [--frame N] (fixed cameras hero, front, right, top, iso, low in colour and clay: DIR/colour.png, clay.png, review.json)\n raea render PAGE.html -o OUT.mp4|OUT.png|DIR [--at A,B] [--alpha] (an HTML composition)\n raea render --bundle NAME.comp.js -o OUT.png|DIR [--dir DIR] [--frame N] (a bundle from raea bundle, as render_bundle draws it)
+ "raea render EDIT.tsx -o OUT.mp4|OUT.png|OUT.wav|DIR [--audio OUT.wav] [--frame N | --at A,B] [--composition ID] [--w W] [--h H] [--fps FPS] [--frames N] [--words W.json] [--perception P.json] [--input I.json|inputs.rrl] [--manifest render.json] [--layers] [--stage WxH] [--10bit] [--aov] [--alpha] [--kbps N | --quality draft|high|master|0..1] [--clay] (also: --lite --comps)\n raea render EDIT.tsx --review DIR [--frame N] (fixed cameras hero, front, right, top, iso, low in colour and clay: DIR/colour.png, clay.png, review.json)\n raea render PAGE.html -o OUT.mp4|OUT.png|DIR [--at A,B] [--alpha] (an HTML composition)\n raea render --bundle NAME.comp.js -o OUT.png|DIR [--dir DIR] [--frame N] (a bundle from raea bundle, as render_bundle draws it)
raea media probe|still|sheet|audio|loudness|motion|cuts|freezes|proxy|lod|trim|concat FILE ... | ffmpeg ARGS | ffprobe ARGS (media work, native: media help)
raea bundle EDIT.tsx --composition-bundle -o OUT.js [--portable DIR] (a composition for render_bundle, on the Mac or the iPhone)\n raea add PKG[@RANGE]... [--dev] | remove NAME... | install [--offline] [--in DIR] (npm packages for the project: raea.lock, node_modules)\n {} (foley, local)\n {} (an instrument's notes, local)\n raea setup-audio [--check] [sao|tokensynth] (install or check the local audio models)\n {} (the song's energy map: beats, sections, builds, drops, stops, hits, cuts per bar; also: --backend NAME)\n raea sounds [WORDS] | sounds get PACK/INSTRUMENT [--notes ..|--all] [-o DIR] (open sample libraries for a Sampler)\n {} (the clip's camera solved, for <Matchmove>)",
tools::sound::SAO_USAGE, tools::sound::TOKENSYNTH_USAGE, tools::song::USAGE, motion::track::USAGE
));
}
- raea_runtime_export::render(args)
+ // the sound alone (-o OUT.wav), or a video's sound beside it (--audio OUT.wav): apps/sound
+ raea_app_sound::render(args).unwrap_or_else(|| raea_runtime_export::render(args))
}
diff --git a/tools/layers.toml b/tools/layers.toml
index 1c8bed0a..1ec8dc33 100644
--- a/tools/layers.toml
+++ b/tools/layers.toml
@@ -140,6 +140,7 @@ raea-runtime-shared = "runtime"
raea-page = "runtime"
raea-app-check = "apps"
raea-app-direction = "apps"
+raea-app-sound = "apps"
raea-app-ci = "apps"
raea-app-tools = "apps"
raea-app-judge = "apps"