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.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
The copies part of #28 added are folded (dupes 297 -> 295): urls.rs takes the writer of a file's URL as a parameter instead of a test-only twin of raea_io_home::src, and the fixed-quantiser tests join io/soft/tests/quality.rs, sharing its frames of rings and its MP4 encode. tools/dupes.max goes down to exact=295
shinyobjectza00a49319e71
diff --git a/io/soft/src/lib.rs b/io/soft/src/lib.rsindex b1e84b56..3d250d96 100644--- a/io/soft/src/lib.rs+++ b/io/soft/src/lib.rs@@ -259,7 +259,7 @@ pub fn quality_kbps(o: &EncodeOpts) -> u32 {}}-/// openh264 at a fixed quantiser `qp`: its Quality mode with the QP range pinned (#28, tests/qp.rs). With rate control+/// openh264 at a fixed quantiser `qp`: its Quality mode with the QP range pinned (#28, tests/quality.rs). With rate control/// off it encodes at its default QP 26 whatever the range says (the crate never sets the layer's iDLayerQp). With it/// on, it refuses a bitrate of 0 and a pinned QP below 14 (Native:3; 13 passes all-intra but not with P-frames), and/// the bitrate moves nothing once the QP is pinned. A frame too big for its buffer at that QP is Native:3 too.diff --git a/io/soft/tests/qp.rs b/io/soft/tests/qp.rsdeleted file mode 100644index f1042d06..00000000--- a/io/soft/tests/qp.rs+++ /dev/null@@ -1,58 +0,0 @@-//! #28 (2): a fixed quantiser reaches openh264: the mezz copy's all-intra QP (h264_encoder's `intra_qp`) and a GOP's-//! (GopEncoder) each change what it writes. With rate control off, as both were, openh264 wrote QP 26 whatever was-//! asked: QP 12 and QP 40 gave the same bytes.-#![cfg(feature = "h264")]--use raea_io_codec::EncodeOpts;-use raea_io_soft::{GopEncoder, h264_encoder};--const W: u32 = 320;-const H: u32 = 192;--/// soft rings moving across: detail every quantiser keeps a different amount of-fn frame(k: u32) -> Vec<u8> {- (0..W * H).flat_map(|i| {- let (x, y) = (i % W, i / W);- let (dx, dy) = (x as i64 - 160 + k as i64 * 4, y as i64 - 96);- let v = ((dx * dx + dy * dy) / 13 % 256) as u8;- [v, v.wrapping_mul(3), 255 - v, 255]- }).collect()-}--fn intra(qp: u8) -> u64 {- let out = std::env::temp_dir().join(format!("raea-soft-qp-{}-{qp}.mp4", std::process::id()));- let opts = EncodeOpts { width: W, height: H, fps: 30.0, kbps: 0, quality: None, nv12: false, realtime: false };- let mut enc = h264_encoder(&out, &opts, Some(qp)).unwrap();- for k in 0..6 {- enc.push(&frame(k)).unwrap();- }- enc.finish(None).unwrap();- let n = std::fs::metadata(&out).unwrap().len();- let _ = std::fs::remove_file(&out);- n-}--fn gop(qp: u8) -> Vec<u8> {- let mut enc = GopEncoder::new(W, H, 30.0, qp).unwrap();- (0..6).flat_map(|k| enc.push(&frame(k)).unwrap().0).collect()-}--#[test]-fn the_mezz_copys_quantiser_changes_what_openh264_writes() {- let (fine, coarse) = (intra(16), intra(40));- assert!(coarse * 2 < fine, "QP 16 {fine} bytes, QP 40 {coarse}: a finer quantiser spends more");-}--#[test]-fn a_gops_quantiser_changes_what_openh264_writes() {- let (fine, coarse) = (gop(16).len(), gop(40).len());- assert!(coarse * 2 < fine, "QP 16 {fine} bytes, QP 40 {coarse}: a finer quantiser spends more");- // and a GOP is still the same bytes each time it's made (an export stitched from GOPs made at different times)- assert!(gop(16) == gop(16));-}--#[test]-fn a_quantiser_below_openh264s_floor_is_its_floor() {- // openh264 refuses a pinned QP under 14 with rate control on (Native:3); asked for less, it gets 14- assert!(gop(4) == gop(14));-}diff --git a/io/soft/tests/quality.rs b/io/soft/tests/quality.rsindex 77f1eb61..dcbc0c90 100644--- a/io/soft/tests/quality.rs+++ b/io/soft/tests/quality.rs@@ -1,34 +1,40 @@-//! #28 (3): `--quality` reaches openh264. It ignored EncodeOpts.quality, so draft and master gave byte-identical files-//! (Windows' and Linux's encoder); now quality scales its bitrate (quality_kbps).+//! What openh264 is asked for reaches what it writes (#28; Windows' and Linux's encoder):+//! - (3) `--quality`: it ignored EncodeOpts.quality, so draft and master gave byte-identical files; now quality scales+//! its bitrate (quality_kbps).+//! - (2) a fixed quantiser: the mezz copy's all-intra QP (h264_encoder's `intra_qp`) and a GOP's (GopEncoder). With+//! rate control off, as both were, openh264 wrote QP 26 whatever was asked: QP 12 and QP 40 gave the same bytes.#![cfg(feature = "h264")]use raea_io_codec::EncodeOpts;-use raea_io_soft::h264_encoder;+use raea_io_soft::{GopEncoder, h264_encoder};-const W: u32 = 640;-const H: u32 = 360;+/// soft rings moving across, `w`x`h`, frame `k`: detailed enough that the bitrate or the quantiser decides the size,+/// not noise that every rate leaves at openh264's coarsest quantiser+fn rings(w: u32, h: u32, ring: i64, k: u32) -> Vec<u8> {+ (0..w * h).flat_map(|i| {+ let (x, y) = (i % w, i / w);+ let (dx, dy) = (x as i64 - w as i64 / 2 + k as i64 * 4, y as i64 - h as i64 / 2);+ let v = ((dx * dx + dy * dy) / ring % 256) as u8;+ [v, v.wrapping_mul(3), 255 - v, 255]+ }).collect()+}-/// 90 frames (three seconds, so the rate outweighs the first frame) of a moving pattern of soft rings: detailed enough that the bitrate decides the size, not noise that-/// every rate leaves at openh264's coarsest quantiser-fn encode(quality: Option<f32>) -> u64 {- let dir = std::env::temp_dir().join(format!("raea-soft-quality-{}", std::process::id()));- std::fs::create_dir_all(&dir).unwrap();- let out = dir.join(format!("{quality:?}.mp4"));- let opts = EncodeOpts { width: W, height: H, fps: 30.0, kbps: 2000, quality, nv12: false, realtime: false };- let mut enc = h264_encoder(&out, &opts, None).unwrap();- for k in 0..90u32 {- let px: Vec<u8> = (0..W * H).flat_map(|i| {- let (x, y) = (i % W, i / W);- let (dx, dy) = (x as i64 - 320 + k as i64 * 4, y as i64 - 180);- let v = ((dx * dx + dy * dy) / 23 % 256) as u8;- [v, v.wrapping_mul(3), 255 - v, 255]- }).collect();- enc.push(&px).unwrap();+/// The size of `n` frames of rings encoded to an MP4 by h264_encoder+fn mp4(o: &EncodeOpts, intra_qp: Option<u8>, ring: i64, n: u32) -> u64 {+ let out = std::env::temp_dir().join(format!("raea-soft-quality-{}-{:?}-{intra_qp:?}.mp4", std::process::id(), o.quality));+ let mut enc = h264_encoder(&out, o, intra_qp).unwrap();+ for k in 0..n {+ enc.push(&rings(o.width, o.height, ring, k)).unwrap();}enc.finish(None).unwrap();- let n = std::fs::metadata(&out).unwrap().len();+ let size = std::fs::metadata(&out).unwrap().len();let _ = std::fs::remove_file(&out);- n+ size+}++/// 90 frames of 640x360: three seconds, so the rate outweighs the first frame+fn encode(quality: Option<f32>) -> u64 {+ mp4(&EncodeOpts { width: 640, height: 360, fps: 30.0, kbps: 2000, quality, nv12: false, realtime: false }, None, 23, 90)}#[test]@@ -37,3 +43,35 @@ fn quality_changes_what_openh264_writes() {// before, all three were the same fileassert!(draft * 5 / 4 < rate && rate * 5 / 4 < master, "draft {draft}, high {rate} and master {master} bytes: a higher quality spends more");}++const W: u32 = 320;+const H: u32 = 192;++fn intra(qp: u8) -> u64 {+ mp4(&EncodeOpts { width: W, height: H, fps: 30.0, kbps: 0, quality: None, nv12: false, realtime: false }, Some(qp), 13, 6)+}++fn gop(qp: u8) -> Vec<u8> {+ let mut enc = GopEncoder::new(W, H, 30.0, qp).unwrap();+ (0..6).flat_map(|k| enc.push(&rings(W, H, 13, k)).unwrap().0).collect()+}++#[test]+fn the_mezz_copys_quantiser_changes_what_openh264_writes() {+ let (fine, coarse) = (intra(16), intra(40));+ assert!(coarse * 2 < fine, "QP 16 {fine} bytes, QP 40 {coarse}: a finer quantiser spends more");+}++#[test]+fn a_gops_quantiser_changes_what_openh264_writes() {+ let (fine, coarse) = (gop(16).len(), gop(40).len());+ assert!(coarse * 2 < fine, "QP 16 {fine} bytes, QP 40 {coarse}: a finer quantiser spends more");+ // and a GOP is still the same bytes each time it's made (an export stitched from GOPs made at different times)+ assert!(gop(16) == gop(16));+}++#[test]+fn a_quantiser_below_openh264s_floor_is_its_floor() {+ // openh264 refuses a pinned QP under 14 with rate control on (Native:3); asked for less, it gets 14+ assert!(gop(4) == gop(14));+}diff --git a/runtime/bundle/src/urls.rs b/runtime/bundle/src/urls.rsindex 70ed2cca..89a55160 100644--- a/runtime/bundle/src/urls.rs+++ b/runtime/bundle/src/urls.rs@@ -7,7 +7,12 @@ use std::path::Path;/// `css` with each `url(..)` naming a file (not a URL with a scheme, a data: URI or a `#fragment`) as that file, quoted:/// `/media/...` (staticFile's) found from the edit's folder `media` (media_path), anything else from `rel`, the folder/// the stylesheet's own relative URLs start from. `missing` hears of each file that isn't there.-pub fn css_file_urls(css: &str, media: &Path, rel: &Path, mut missing: impl FnMut(&Path)) -> String {+pub fn css_file_urls(css: &str, media: &Path, rel: &Path, missing: impl FnMut(&Path)) -> String {+ urls_as(css, media, rel, missing, raea_io_home::src)+}++/// css_file_urls with each file written by `src` (a test writes Windows' form on any system)+fn urls_as(css: &str, media: &Path, rel: &Path, mut missing: impl FnMut(&Path), src: impl Fn(&Path) -> String) -> String {if !css.contains("url(") {return css.to_string();}@@ -35,22 +40,16 @@ pub fn css_file_urls(css: &str, media: &Path, rel: &Path, mut missing: impl FnMuout}-#[cfg(not(test))]-fn src(p: &Path) -> String {- raea_io_home::src(p)-}--// a test asks for Windows' form by a path's look, so a Windows path is checked on any system-#[cfg(test)]-fn src(p: &Path) -> String {- raea_io_home::src_on(&p.display().to_string(), p.display().to_string().as_bytes().get(1) == Some(&b':'))-}-#[cfg(test)]mod tests {- use super::css_file_urls;use std::path::Path;+ /// css_file_urls as each path's look says it's written: Windows' form for a C:\ path, so it's checked on any system+ fn css_file_urls(css: &str, media: &Path, rel: &Path, missing: impl FnMut(&Path)) -> String {+ let src = |p: &Path| raea_io_home::src_on(&p.display().to_string(), p.display().to_string().as_bytes().get(1) == Some(&b':'));+ super::urls_as(css, media, rel, missing, src)+ }+#[test]fn a_windows_path_is_a_file_url_with_no_backslash() {let dir = Path::new(r"C:\Users\a\AppData\Local\Temp\claude\edit");diff --git a/tools/dupes.max b/tools/dupes.maxindex 8441b241..c225b4bd 100644--- a/tools/dupes.max+++ b/tools/dupes.max@@ -13,5 +13,5 @@# into raea_sys_frame::json_f32; begin_live and app_mut gone; await_models split by target); the one left is an# accessor matched by shape: Engine::world_mut and Opening::world_mut (the canvas window goes on before the engine is# finished, its camera after) with runtime/page bevy_page.rs BevyPage::app-exact=296+exact=295near=56