Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

fix: CLI --bitrate now applies to VP9 WebM (#440)

mjohnson7cdc195e6c40bd9
diff --git a/apps/effectcraft-cli/src/main.rs b/apps/effectcraft-cli/src/main.rs
index 71ea1ea37..1f3257b07 100644
--- a/apps/effectcraft-cli/src/main.rs
+++ b/apps/effectcraft-cli/src/main.rs
@@ -624,7 +624,7 @@ fn from_cwd(path: &str) -> Result<String, Failure> {
/// `render`: queue `--comp` (or the active comp) with the given settings unless `--queue`, then
/// render the queue with a progress line on stderr. Fails if any item fails.
fn render(args: &Args, json_out: bool) -> Result<(), Failure> {
- use effectcraft_engine::project::render_queue::RenderStatus;
+ use effectcraft_engine::project::render_queue::{OutputFormat, RenderStatus};
if args.opt("--bridge").is_some() {
return usage_err("render runs headless; use `exec renderQueue.add` / `renderQueue.render` with --bridge");
}
@@ -670,6 +670,11 @@ fn render(args: &Args, json_out: bool) -> Result<(), Failure> {
}
if let Some(v) = args.num("--bitrate")? {
p["bitrate"] = json!(v);
+ // VP9 WebM encodes by quality unless told to target the bitrate (#440).
+ // The format parser decides what is WebM, so its aliases (`vp9`, `webmvp9opus`) count.
+ if p["format"].as_str().and_then(OutputFormat::from_name) == Some(OutputFormat::WebM) {
+ p["webmBitrate"] = json!(true);
+ }
}
for (flag, key) in [
("--profile", "profile"),
diff --git a/apps/effectcraft-cli/tests/cli.rs b/apps/effectcraft-cli/tests/cli.rs
index 723016a86..e5a5c4d70 100644
--- a/apps/effectcraft-cli/tests/cli.rs
+++ b/apps/effectcraft-cli/tests/cli.rs
@@ -454,3 +454,33 @@ fn mcp_autosave_is_opt_in_and_rejects_invalid_combinations() {
assert!(!String::from_utf8_lossy(&out.stderr).contains("panicked"));
std::fs::remove_dir_all(config).unwrap();
}
+
+/// `render --bitrate` (#440) targets the bitrate in VP9 WebM.
+#[test]
+fn render_bitrate_applies_to_vp9_webm() {
+ let root = tmp("webm-bitrate");
+ let _ = std::fs::remove_dir_all(&root);
+ std::fs::create_dir_all(&root).unwrap();
+ let project = root.join("x.ecproj");
+ let p = project.to_str().unwrap();
+ ok_json(&[
+ "run",
+ "comp.new",
+ r##"{"name":"T","width":320,"height":180,"duration":1}"##,
+ "layer.newSolid",
+ r##"{"width":320,"height":180}"##,
+ "effect.apply",
+ r##"{"layer":"#1","effect":"ec.noise.fractal"}"##,
+ "--empty",
+ "--save-as",
+ p,
+ ]);
+ let size = |kbps: &str| {
+ let out = root.join(format!("b{kbps}.webm"));
+ ok_json(&["render", "--project", p, "--start", "0", "--end", "0.5", "--bitrate", kbps, "--out", out.to_str().unwrap()]);
+ std::fs::metadata(&out).unwrap().len()
+ };
+ let (low, high) = (size("100"), size("8000"));
+ assert!(high > low, "100 kbps: {low} bytes, 8000 kbps: {high} bytes");
+ let _ = std::fs::remove_dir_all(&root);
+}