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
raea gen: made quotes a length-priced edit with its real video; fal puts a start frame in image_url
shinyobjectz71ee5ab5839a
diff --git a/io/gen-core/src/fal.rs b/io/gen-core/src/fal.rsindex 010c0517..0c21e049 100644--- a/io/gen-core/src/fal.rs+++ b/io/gen-core/src/fal.rs@@ -138,16 +138,26 @@ pub fn body(inputs: &serde_json::Map<String, J>, media: &[(String, String)], fie}}// a mask (image.edit's `mask`: where an inpainting model may paint) into the endpoint's mask field, not with the- // pictures (it went into image_urls beside the picture, and a fill model read no mask)- if let Some((_, u)) = media.iter().find(|(n, _)| n == "mask") {- let f = fields.iter().find(|(n, l)| !*l && n.contains("mask")).map(|(n, _)| n.clone()).unwrap_or_else(|| "mask_url".into());- b[f.as_str()] = json!(u);+ // pictures (it went into image_urls beside the picture, and a fill model read no mask); a last frame+ // (video.generate's `end_image`) into the endpoint's end-frame field+ for (name, default) in [("mask", "mask_url"), ("end_image", "end_image_url")] {+ if let Some((_, u)) = media.iter().find(|(n, _)| n == name) {+ let f = fields.iter().find(|(n, l)| !*l && if name == "mask" { n.contains(name) } else { n.starts_with(name) }).map(|(n, _)| n.clone()).unwrap_or_else(|| default.into());+ b[f.as_str()] = json!(u);+ }}- let images: Vec<&String> = media.iter().filter(|(n, _)| n != "mask").map(|(_, u)| u).collect();+ let images: Vec<&String> = media.iter().filter(|(n, _)| n != "mask" && n != "end_image").map(|(_, u)| u).collect();if images.is_empty() {return b;}- let field = |list: bool| fields.iter().find(|(n, l)| *l == list && n.contains("image_url")).map(|(n, _)| n.clone());+ // the plain field first (image_url, image_urls), then any other picture field that isn't an end frame: Seedance's+ // schema lists end_image_url before image_url, and its start frame went in as the end frame (fal answered 422)+ let field = |list: bool| {+ let plain = if list { "image_urls" } else { "image_url" };+ fields.iter().find(|(n, l)| *l == list && n == plain)+ .or_else(|| fields.iter().find(|(n, l)| *l == list && n.contains("image_url") && !n.starts_with("end_")))+ .map(|(n, _)| n.clone())+ };match (images.len(), field(false), field(true)) {(1, Some(one), _) => b[one.as_str()] = json!(images[0]),(_, _, Some(many)) => b[many.as_str()] = json!(images),@@ -163,6 +173,21 @@ pub fn body(inputs: &serde_json::Map<String, J>, media: &[(String, String)], fiemod tests {use super::*;+ #[test]+ fn a_start_frame_goes_to_image_url_not_the_end_frame() {+ // Seedance 2.5's schema order: end_image_url comes before image_url+ let fields: Vec<(String, bool)> = ["generate_audio", "resolution", "end_image_url", "image_url", "aspect_ratio", "prompt", "duration"].iter().map(|n| (n.to_string(), false)).collect();+ let mut inputs = serde_json::Map::new();+ inputs.insert("resolution".into(), json!("720p"));+ inputs.insert("aspect_ratio".into(), json!("9:16"));+ let b = body(&inputs, &[("start_image".to_string(), "https://f/start.jpg".to_string())], &fields);+ assert_eq!(b["image_url"], "https://f/start.jpg");+ assert!(b.get("end_image_url").is_none());+ assert_eq!((b["resolution"].as_str(), b["aspect_ratio"].as_str()), (Some("720p"), Some("9:16")));+ let b = body(&inputs, &[("start_image".into(), "https://f/a.jpg".into()), ("end_image".into(), "https://f/z.jpg".into())], &fields);+ assert_eq!((b["image_url"].as_str(), b["end_image_url"].as_str()), (Some("https://f/a.jpg"), Some("https://f/z.jpg")));+ }+#[test]fn a_mask_goes_to_the_mask_field() {let fields = vec![("image_url".to_string(), false), ("mask_url".to_string(), false), ("prompt".to_string(), false)];diff --git a/io/gen/src/run.rs b/io/gen/src/run.rsindex e4bd9ba3..4f30e093 100644--- a/io/gen/src/run.rs+++ b/io/gen/src/run.rs@@ -90,7 +90,12 @@ impl<'a> Run<'a> {let model = made.model(m)?;// a quote reads the media's count, not its bytes: a stand-in URL prices itlet (body, fit) = made_body(s, &model, &|_| Ok("https://www.made.app/favicon.ico".into()))?;- match made.cost(&body) {+ let by_length = model["inputSecondsPricing"]["usdPerSecondByResolution"].as_object().map(|r| {+ let res = s.inputs.get("resolution").and_then(|v| v.as_str()).or(model["defaultResolution"].as_str()).unwrap_or("");+ let per = r.get(res).and_then(|v| v.as_f64()).unwrap_or(0.0);+ format!("priced by the input's length ({res}: ${per:.4} a second); made reads it when the run uploads it, so the run quotes it exactly before sending")+ });+ match by_length.map_or_else(|| made.cost(&body), Err) {Ok((c, p)) if p < c && crate::direct::possible(&model) && crate::setting("FAL_KEY").is_some() && crate::setting("RAEA_GEN_VIA").as_deref() != Some("made") => {total += p;row["cents"] = json!(p);@@ -255,8 +260,28 @@ impl<'a> Run<'a> {fn made(&self, made: &Made, m: &str, s: &Step, key: &str, done: &BTreeMap<String, Made1>, spent: &mut u64) -> Result<(Made1, u64), String> {let model = made.model(m)?;- // priced first with a stand-in for each media (a quote reads their count, not their bytes)- let (probe, notes) = made_body(s, &model, &|_| Ok("https://www.made.app/favicon.ico".into()))?;+ // each media as made reads it (a job, a URL, or an upload), uploaded once: the quote and the job share it+ let sent = std::cell::RefCell::new(BTreeMap::<String, String>::new());+ let media = |v: &J| -> Result<String, String> {+ if let Some(m) = sent.borrow().get(&v.to_string()) {+ return Ok(m.clone());+ }+ let r = reference(v).ok_or("not a reference")?;+ let up = done.get(r).ok_or(format!("@{r} isn't made yet"))?;+ // a job or URL stands for the whole output; one picture of a batch goes up as its file+ let m = match up.job.as_ref().or(up.url.as_ref()).filter(|_| index(v).is_none()) {+ Some(j) => j.clone(),+ None => made.upload(file_of(done, v).ok_or(format!("{v} names no file of @{r}"))?)?,+ };+ sent.borrow_mut().insert(v.to_string(), m.clone());+ Ok(m)+ };+ // priced first. A quote reads most media's count, not their bytes, so a stand-in prices them; a model priced+ // by its input's length (Seedance's video edit: per second of the source) is quoted with the real input,+ // which made has to read (a stand-in answers "couldn't read the source video")+ let by_length = model["inputSecondsPricing"].is_object();+ let stand_in = |_: &J| -> Result<String, String> { Ok("https://www.made.app/favicon.ico".into()) };+ let (probe, notes) = if by_length { made_body(s, &model, &media)? } else { made_body(s, &model, &stand_in)? };for n in notes {eprintln!("raea gen: {n}");}@@ -292,15 +317,6 @@ impl<'a> Run<'a> {*spent += provider;return Ok((Made1 { files, job: Some(format!("fal:{endpoint}")), url: urls.first().cloned() }, provider));}- let media = |v: &J| -> Result<String, String> {- let r = reference(v).ok_or("not a reference")?;- let up = done.get(r).ok_or(format!("@{r} isn't made yet"))?;- // a job or URL stands for the whole output; one picture of a batch goes up as its file- if let Some(j) = up.job.as_ref().or(up.url.as_ref()).filter(|_| index(v).is_none()) {- return Ok(j.clone());- }- made.upload(file_of(done, v).ok_or(format!("{v} names no file of @{r}"))?)- };let (mut body, _) = made_body(s, &model, &media)?;body["request_id"] = json!(format!("raea-{key}"));body["max_cost_cents"] = json!(cents);