Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

#341: CLI export message names the file written, not the requested path

JordyUSA9e8ad1d6a202
diff --git a/apps/filmcraft-cli/src/main.rs b/apps/filmcraft-cli/src/main.rs
index 13bebb85d..cd2de5439 100644
--- a/apps/filmcraft-cli/src/main.rs
+++ b/apps/filmcraft-cli/src/main.rs
@@ -344,7 +344,7 @@ async fn main() {
match r {
Ok(v) => {
print(&a, &v);
- eprintln!("exported {out} in {:.1}s", t0.elapsed().as_secs_f64());
+ eprintln!("exported {} in {:.1}s", written_paths(&v, out).join(", "), t0.elapsed().as_secs_f64());
}
Err(e) => fail(format!("export: {e}")),
}
@@ -381,6 +381,24 @@ async fn main() {
}
}
+/// The files an export wrote, from its result: `path` of a direct export, or each queued item's
+/// `path` (the format may have changed the extension: `out.mp4` exported as APV is `out.mp4.mov`).
+/// `requested` when the result names none.
+fn written_paths(result: &Value, requested: &str) -> Vec<String> {
+ let paths: Vec<String> = match result.get("path").and_then(Value::as_str) {
+ Some(p) => vec![p.to_string()],
+ None => result
+ .get("items")
+ .and_then(Value::as_array)
+ .into_iter()
+ .flatten()
+ .filter_map(|i| i.get("path").and_then(Value::as_str))
+ .map(str::to_string)
+ .collect(),
+ };
+ if paths.is_empty() { vec![requested.to_string()] } else { paths }
+}
+
#[cfg(test)]
mod format_tests {
/// The CLI (and MCP / headless runs, which share its entry point) registers the hardware
@@ -391,6 +409,17 @@ mod format_tests {
assert_eq!(filmcraft_platform::registered(), cfg!(any(target_os = "macos", target_os = "windows")), "{hardware:?}");
}
+ #[test]
+ fn export_message_names_the_written_files() {
+ use serde_json::json;
+ let direct = json!({"job": 1, "path": "out-apv.mp4.mov", "result": {"path": "out-apv.mp4.mov"}});
+ assert_eq!(super::written_paths(&direct, "out-apv.mp4"), ["out-apv.mp4.mov"]);
+ let queued = json!({"added": [1, 2], "items": [{"path": "a.mp4.mov"}, {"path": "b.wav"}]});
+ assert_eq!(super::written_paths(&queued, "a.mp4"), ["a.mp4.mov", "b.wav"]);
+ assert_eq!(super::written_paths(&json!({}), "x.mov"), ["x.mov"]);
+ assert_eq!(super::written_paths(&json!({"items": []}), "x.mov"), ["x.mov"]);
+ }
+
#[test]
fn export_format_from_extension() {
assert_eq!(super::format_for("out/clip.MXF"), Some("mxf-op1a"));
diff --git a/apps/filmcraft-cli/tests/cli.rs b/apps/filmcraft-cli/tests/cli.rs
index b7fedfc2c..e83db61fc 100644
--- a/apps/filmcraft-cli/tests/cli.rs
+++ b/apps/filmcraft-cli/tests/cli.rs
@@ -179,6 +179,36 @@ fn export_with_presets() {
let v = json_out(&cli(&["--demo", "--data-dir", data_s, "export", q.to_str().unwrap(), "--preset", "Tiny WAV", "--queue", "--range", "entire"]));
assert_eq!(v["items"][0]["status"], "done", "{v}");
assert!(q.exists());
+ // a format that changes the extension: the completion message names the file written (#341)
+ let apv = dir.join("apv.mp4");
+ let o =
+ cli(&["--demo", "--data-dir", data_s, "export", apv.to_str().unwrap(), "--preset", "APV 422-10", "--start", "0", "--end", "0.1", "--scale", "0.125"]);
+ let v = json_out(&o);
+ let written = v["path"].as_str().unwrap().to_string();
+ assert!(written.ends_with("apv.mp4.mov") && std::path::Path::new(&written).exists(), "{v}");
+ let msg = String::from_utf8_lossy(&o.stderr);
+ assert!(msg.contains(&format!("exported {written} in ")), "{msg}");
+ let qa = dir.join("queued-apv.mp4");
+ let o = cli(&[
+ "--demo",
+ "--data-dir",
+ data_s,
+ "export",
+ qa.to_str().unwrap(),
+ "--preset",
+ "APV 422-10",
+ "--queue",
+ "--start",
+ "0",
+ "--end",
+ "0.1",
+ "--scale",
+ "0.125",
+ ]);
+ let v = json_out(&o);
+ let written = v["items"][0]["path"].as_str().unwrap().to_string();
+ assert!(written.ends_with("queued-apv.mp4.mov"), "{v}");
+ assert!(String::from_utf8_lossy(&o.stderr).contains(&format!("exported {written} in ")), "{}", String::from_utf8_lossy(&o.stderr));
// unknown preset: exit status 1 and a message naming it
let bad = cli(&["--demo", "--data-dir", data_s, "export", dir.join("x.mp4").to_str().unwrap(), "--preset", "No Such Preset"]);
assert_eq!(bad.status.code(), Some(1));