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.

A render's timings (the JSON line on stderr after a video) print only with RAEA_RENDER_STATS=1. The fed, CPU, direct and engine paths each printed it after every render, so a person's terminal and the app's render log showed a line of numbers beside raea's own APPLIED line. The benches that read it ask for it: bench/rerender's bench.sh, bench.ps1 and the iOS app's entry, and bench/lightspeed/export.sh; nothing else read it (tools, apps, docs, tests). RAEA_TIMES' lines are unchanged. On bench/rerender/pages.tsx: without the variable stderr holds the APPLIED and summary lines only; with it, the fed path's line as before

shinyobjectz9ebedb3f6f98
diff --git a/bench/lightspeed/export.sh b/bench/lightspeed/export.sh
index 93c25999..98577b38 100644
--- a/bench/lightspeed/export.sh
+++ b/bench/lightspeed/export.sh
@@ -48,9 +48,9 @@ render() {
local edit=$1 out=$2; shift 2
local log=$out.log clock=$out.clock
if [ "${TIMES:-}" = 1 ]; then
- RAEA_EXPORT_CACHE=0 RAEA_TIMES=1 "$MOTION" ci time --to "$clock" -- "$MOTION" render "$edit" -o "$out" "$@" > "$log.out" 2> "$log.err"
+ RAEA_EXPORT_CACHE=0 RAEA_TIMES=1 RAEA_RENDER_STATS=1 "$MOTION" ci time --to "$clock" -- "$MOTION" render "$edit" -o "$out" "$@" > "$log.out" 2> "$log.err"
else
- RAEA_EXPORT_CACHE=0 "$MOTION" ci time --to "$clock" -- "$MOTION" render "$edit" -o "$out" "$@" > "$log.out" 2> "$log.err"
+ RAEA_EXPORT_CACHE=0 RAEA_RENDER_STATS=1 "$MOTION" ci time --to "$clock" -- "$MOTION" render "$edit" -o "$out" "$@" > "$log.out" 2> "$log.err"
fi
if [ $? != 0 ]; then
if [ -s "$log.err" ]; then say_tail "render $edit: " 600 "$log.err" >&2; else say_tail "render $edit: " 600 "$log.out" >&2; fi
diff --git a/bench/rerender/bench.ps1 b/bench/rerender/bench.ps1
index 83da556a..c31ea9b6 100644
--- a/bench/rerender/bench.ps1
+++ b/bench/rerender/bench.ps1
@@ -21,7 +21,7 @@ $ErrorActionPreference = "Continue"
if (-not $Film) { $Film = Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Path) "film.tsx" }
if (-not (Test-Path $Raea)) { Write-Output "bench: no raea at $Raea"; exit 2 }
New-Item -ItemType Directory -Force -Path $Out | Out-Null
-$env:RAEA_SIGN = "0"; $env:RAEA_MARK = "0"; $env:RAEA_EXPORT_CACHE = "0"; $env:RAEA_TIMES = "1"
+$env:RAEA_SIGN = "0"; $env:RAEA_MARK = "0"; $env:RAEA_EXPORT_CACHE = "0"; $env:RAEA_TIMES = "1"; $env:RAEA_RENDER_STATS = "1"
function Now { [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() / 1000.0 }
$ffmpeg = Get-Command ffmpeg -ErrorAction SilentlyContinue
diff --git a/bench/rerender/bench.sh b/bench/rerender/bench.sh
index 635783cc..dc4caba2 100755
--- a/bench/rerender/bench.sh
+++ b/bench/rerender/bench.sh
@@ -28,7 +28,7 @@ FILM=$ROOT/bench/rerender/film.tsx
command -v jq > /dev/null || { echo "bench: needs jq"; exit 2; }
mkdir -p "$OUT"
# pixels and timing only: no Content Credentials, no watermark, no export cache (a hit would time nothing)
-export RAEA_SIGN=0 RAEA_MARK=0 RAEA_EXPORT_CACHE=0 RAEA_TIMES=1
+export RAEA_SIGN=0 RAEA_MARK=0 RAEA_EXPORT_CACHE=0 RAEA_TIMES=1 RAEA_RENDER_STATS=1
export BIN FILM OUT
now() { perl -MTime::HiRes=time -e 'printf "%.3f", time'; }
diff --git a/bench/rerender/ios/src/lib.rs b/bench/rerender/ios/src/lib.rs
index e2fab046..16d64b5f 100644
--- a/bench/rerender/ios/src/lib.rs
+++ b/bench/rerender/ios/src/lib.rs
@@ -44,8 +44,10 @@ fn started_ms() -> Option<u64> {
pub unsafe extern "C" fn raea_rerender_run(bundle: *const c_char, out: *const c_char) -> i32 {
let js = unsafe { CStr::from_ptr(bundle) }.to_string_lossy().into_owned();
let out = unsafe { CStr::from_ptr(out) }.to_string_lossy().into_owned();
+ // SAFETY (both): set before any thread of raea's starts (main.m calls this first); the render's stats line is what
+ // bench.sh reads from the console
+ unsafe { std::env::set_var("RAEA_RENDER_STATS", "1") };
if let Some(t0) = started_ms() {
- // SAFETY: set before any thread of raea's starts (main.m calls this first)
unsafe { std::env::set_var("RAEA_STARTUP_TRACE", t0.to_string()) };
}
raea_runtime_react::startup_mark("main");
diff --git a/runtime/encode/src/lib.rs b/runtime/encode/src/lib.rs
index cbc32230..ac59e419 100644
--- a/runtime/encode/src/lib.rs
+++ b/runtime/encode/src/lib.rs
@@ -67,7 +67,7 @@ fn push_direct(enc: &mut Box<dyn raea_io_media::VideoEncoder>, px: &[u8], w: u32
/// Render an edit file (.sql or .rdb) to OUT: .mp4 (video and its sound), .txt (one hash per
/// frame), .raw (the frames as they came back) or a directory of PNGs. Edits without 3D take the direct path to .mp4,
-/// .mov and .txt (RAEA_DIRECT=1 forces it). Its stats go to stderr as one JSON line.
+/// .mov and .txt (RAEA_DIRECT=1 forces it). With RAEA_RENDER_STATS=1, its timings go to stderr as one JSON line.
pub fn render_file(edit: &str, out: &Path, opts: &RenderOpts) -> Result<(), String> {
engine::mem_mark("render: start");
// an HTML composition: its videos on the GPU, the page over them (html.rs)
diff --git a/runtime/encode/src/render.rs b/runtime/encode/src/render.rs
index b5d8555a..db486834 100644
--- a/runtime/encode/src/render.rs
+++ b/runtime/encode/src/render.rs
@@ -4,6 +4,14 @@
use super::*;
use raea_runtime_view::{cpuview, gpuview};
+/// A render's timings as one JSON line on stderr, with RAEA_RENDER_STATS=1 (the benches read it; a person's terminal
+/// shows only what the render made)
+fn print_stats(line: serde_json::Value) {
+ if std::env::var("RAEA_RENDER_STATS").as_deref() == Ok("1") {
+ eprintln!("{line}");
+ }
+}
+
/// Render a loaded edit (see `render_file`; `dir` is where its relative media paths start).
pub fn render(prog: &Program, rows: &[Tup], dir: &Path, out: &Path, ro: &RenderOpts) -> Result<(), String> {
render_with(prog, rows, dir, out, ro, None)
@@ -132,7 +140,7 @@ pub fn render_fed(
if hashes {
std::fs::write(out, lines.join("\n") + "\n").map_err(|e| e.to_string())?;
}
- eprintln!("{}", serde_json::json!({"direct": true, "fed": true, "frames": list.len(), "fps_incl_encode": list.len() as f64 / frames_s, "setup_s": setup_s, "finish_s": finish_s, "sound_s": sent,
+ print_stats(serde_json::json!({"direct": true, "fed": true, "frames": list.len(), "fps_incl_encode": list.len() as f64 / frames_s, "setup_s": setup_s, "finish_s": finish_s, "sound_s": sent,
"bytes": stats.as_ref().map(|s| s.bytes), "video": stats.as_ref().map(|s| s.video_codec.clone()), "times": dt.json()}));
Ok(())
}
@@ -210,7 +218,7 @@ pub fn render_with(prog: &Program, rows: &[Tup], dir: &Path, out: &Path, ro: &Re
if hashes {
std::fs::write(out, lines.join("\n") + "\n").map_err(|e| e.to_string())?;
}
- eprintln!("{}", serde_json::json!({"direct": true, "cpu": true, "frames": list.len(), "fps_incl_encode": list.len() as f64 / frames_s, "setup_s": setup_s,
+ print_stats(serde_json::json!({"direct": true, "cpu": true, "frames": list.len(), "fps_incl_encode": list.len() as f64 / frames_s, "setup_s": setup_s,
"bytes": stats.as_ref().map(|s| s.bytes), "video": stats.as_ref().map(|s| s.video_codec.clone()), "times": tm.json()}));
return Ok(());
}
@@ -294,7 +302,7 @@ pub fn render_with(prog: &Program, rows: &[Tup], dir: &Path, out: &Path, ro: &Re
if hashes {
std::fs::write(&out, lines.join("\n") + "\n").map_err(|e| e.to_string())?;
}
- eprintln!("{}", serde_json::json!({"direct": true, "frames": list.len(), "fps_incl_encode": list.len() as f64 / frames_s, "setup_s": setup_s, "finish_s": finish_s, "encoder_drain_s": drain_s,
+ print_stats(serde_json::json!({"direct": true, "frames": list.len(), "fps_incl_encode": list.len() as f64 / frames_s, "setup_s": setup_s, "finish_s": finish_s, "encoder_drain_s": drain_s,
"bytes": stats.as_ref().map(|s| s.bytes), "video": stats.as_ref().map(|s| s.video_codec.clone()), "times": dt.json(), "pool_mb": v.pool_bytes as f64 / 1e6, "upload_cpu_ms_per_upload": v.upload_cpu_ms / dt.uploads.max(1) as f64}));
return Ok(());
}
@@ -372,8 +380,7 @@ pub fn render_with(prog: &Program, rows: &[Tup], dir: &Path, out: &Path, ro: &Re
} else {
None
};
- eprintln!(
- "{}",
+ print_stats(
serde_json::json!({"frames": list.len(), "video": stats.video_codec, "audio": stats.audio_codec, "bytes": stats.bytes,
"render_fps": n / render_s, "overlay_drawn_reused": e.overlay_stats(), "stages_ms_per_frame": stages, "pool_uploads_reuses_bytes": e.pool_stats(), "gpu_stage_ms": e.gpu_stage_times().map(|(m, n)| serde_json::json!({"clip_uploads": m[0], "overlay_upload": m[1], "composite": m[2], "nv12": m[3], "frames": n})), "encode_fps": n / encode_s, "ssim": ssim, "seconds": t0.elapsed().as_secs_f64(), "audio_s": audio_s,
"lufs": mix.as_ref().map(raea_io_media::audio::lufs), "peak_db": mix.as_ref().map(raea_io_media::audio::peak_db)})