Skip to content

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

M11.4: AAF / OMF export settings dialogs (File ▸ Export), AAF/OMF in File ▸ Import

Brandon Thomasba3695e102f8
diff --git a/crates/ui-egui/Cargo.toml b/crates/ui-egui/Cargo.toml
index f267a24e7..e89053084 100644
--- a/crates/ui-egui/Cargo.toml
+++ b/crates/ui-egui/Cargo.toml
@@ -40,4 +40,5 @@ rustix = { version = "1", default-features = false, features = ["std", "time"] }
[dev-dependencies]
pollster = "0.4"
filmcraft-codecs = { workspace = true }
+filmcraft-interchange = { workspace = true }
egui_kittest = { workspace = true, features = ["eframe", "wgpu"] }
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 4126adaf7..d1330749c 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -665,7 +665,7 @@ impl FilmcraftApp {
.iter()
.chain(filmcraft_media::AUDIO_EXTENSIONS)
.chain(filmcraft_media::STILL_EXTENSIONS)
- .chain(&["srt", "vtt", "scc", "edl", "xml", "fcpxml", "otio"])
+ .chain(&["srt", "vtt", "scc", "edl", "xml", "fcpxml", "otio", "aaf", "omf"])
.copied()
.collect();
let paths = self.hooks.pick_files.as_mut().map(|f| f(&exts)).unwrap_or_default();
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs
index f2019b106..7daeeed9a 100644
--- a/crates/ui-egui/src/menus.rs
+++ b/crates/ui-egui/src/menus.rs
@@ -285,6 +285,11 @@ pub fn invoke(app: &mut FilmcraftApp, ctx: &egui::Context, id: &str, params: Val
crate::panels::shortcuts_dialog::open(app);
return Ok(Value::Null);
}
+ // File ▸ Export ▸ AAF… / OMF… open their settings dialogs; with a path they export directly.
+ "file.exportAaf" | "file.exportOmf" if params.get("path").is_none() => {
+ filmcraft_engine::find_command(id).map_or(Ok(()), |c| (c.enabled)(&app.session))?;
+ return crate::panels::interchange_export::open(app, ctx, id);
+ }
// Audio Gain from the menu or G opens the dialog; with params it applies directly.
"clip.audioGain" if params.as_object().is_none_or(|m| m.is_empty()) => {
filmcraft_engine::find_command("clip.audioGain").map_or(Ok(()), |c| (c.enabled)(&app.session))?;
diff --git a/crates/ui-egui/src/panels/dialogs.rs b/crates/ui-egui/src/panels/dialogs.rs
index 802a732ab..75329ad08 100644
--- a/crates/ui-egui/src/panels/dialogs.rs
+++ b/crates/ui-egui/src/panels/dialogs.rs
@@ -15,6 +15,7 @@ pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
crate::panels::monitor_view::dialogs(app, ctx);
crate::panels::voiceover::show(app, ctx);
crate::panels::remix::show(app, ctx);
+ crate::panels::interchange_export::show(app, ctx);
let Some(d) = app.dialog else { return };
if let Some(still_open) = crate::panels::file_dialogs::show(app, ctx, d) {
if !still_open && app.dialog == Some(d) {
diff --git a/crates/ui-egui/src/panels/interchange_export.rs b/crates/ui-egui/src/panels/interchange_export.rs
new file mode 100644
index 000000000..1d03a1d3d
--- /dev/null
+++ b/crates/ui-egui/src/panels/interchange_export.rs
@@ -0,0 +1,205 @@
+//! File ▸ Export ▸ AAF… and OMF…: the export settings dialogs. OK asks for the file name (the
+//! host's save panel) and runs `file.exportAaf` / `file.exportOmf` with the chosen settings; with
+//! parameters (`path` …) the menu commands run directly.
+//!
+//! Automation ids (`<p>` is `aafExport` or `omfExport`): `<p>.mixdownVideo` (AAF),
+//! `<p>.breakoutToMono`, `<p>.audio.<embedded|separate|linked>` (linked: AAF only),
+//! `<p>.audioFormat.<wav|aiff>`, `<p>.sampleRate.<rate>`, `<p>.bitDepth.<16|24>`, `<p>.trimAudio`,
+//! `<p>.handles` (frames), `<p>.renderAudioEffects`, `<p>.title` (OMF), `<p>.ok`, `<p>.cancel`.
+
+use serde_json::{Value, json};
+
+use crate::FilmcraftApp;
+
+#[derive(Clone, Debug, PartialEq)]
+struct Draft {
+ omf: bool,
+ title: String,
+ mixdown_video: bool,
+ breakout: bool,
+ audio: &'static str,
+ aiff: bool,
+ sample_rate: u32,
+ bits: u16,
+ trim: bool,
+ handles: i64,
+ render_effects: bool,
+}
+
+fn draft_id() -> egui::Id {
+ egui::Id::new("interchange-export-draft")
+}
+
+const RATES: [u32; 4] = [32_000, 44_100, 48_000, 96_000];
+
+/// Open the AAF or OMF settings dialog (`id` is the menu command).
+pub fn open(app: &mut FilmcraftApp, ctx: &egui::Context, id: &str) -> Result<Value, String> {
+ let omf = id == "file.exportOmf";
+ let seq = app.session.state.active_sequence.and_then(|s| app.session.project.item(s));
+ let title = seq.map(|i| i.name.clone()).unwrap_or_default();
+ let sr = app.session.active_sequence().map(|q| q.settings.sample_rate).filter(|r| RATES.contains(r)).unwrap_or(48_000);
+ let d = Draft {
+ omf,
+ title,
+ mixdown_video: false,
+ breakout: false,
+ audio: "embedded",
+ aiff: false,
+ sample_rate: sr,
+ bits: 16,
+ trim: omf,
+ handles: if omf { 30 } else { 0 },
+ render_effects: false,
+ };
+ ctx.data_mut(|m| m.insert_temp(draft_id(), Some(d)));
+ Ok(json!({"dialog": if omf { "omfExport" } else { "aafExport" }}))
+}
+
+/// Whether the dialog is open.
+pub fn is_open(ctx: &egui::Context) -> bool {
+ ctx.data(|m| m.get_temp::<Option<Draft>>(draft_id())).flatten().is_some()
+}
+
+pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
+ let Some(Some(mut d)) = ctx.data(|m| m.get_temp::<Option<Draft>>(draft_id())) else { return };
+ let p = if d.omf { "omfExport" } else { "aafExport" };
+ let mut close = false;
+ let mut apply = false;
+ let mut elems: Vec<(String, egui::Rect, String)> = Vec::new();
+ let title = if d.omf { "OMF Export Settings" } else { "AAF Export Settings" };
+ egui::Window::new(title).collapsible(false).resizable(false).anchor(egui::Align2::CENTER_CENTER, [0.0, 0.0]).show(ctx, |ui| {
+ ui.set_min_width(380.0);
+ egui::Grid::new("interchange-export-grid").num_columns(2).spacing([12.0, 8.0]).show(ui, |ui| {
+ if d.omf {
+ ui.label("OMF Title:");
+ let r = ui.text_edit_singleline(&mut d.title);
+ elems.push((format!("{p}.title"), r.rect, d.title.clone()));
+ ui.end_row();
+ } else {
+ ui.label("");
+ let r = ui.checkbox(&mut d.mixdown_video, "Mixdown video");
+ elems.push((format!("{p}.mixdownVideo"), r.rect, d.mixdown_video.to_string()));
+ ui.end_row();
+ }
+ ui.label("Audio:");
+ ui.horizontal(|ui| {
+ let modes: &[(&'static str, &str)] = if d.omf {
+ &[("embedded", "Encapsulate"), ("separate", "Separate Audio")]
+ } else {
+ &[("embedded", "Embed"), ("separate", "Separate Files"), ("linked", "Link to Media")]
+ };
+ for (k, label) in modes {
+ let r = ui.radio(d.audio == *k, *label);
+ if r.clicked() {
+ d.audio = k;
+ }
+ elems.push((format!("{p}.audio.{k}"), r.rect, label.to_string()));
+ }
+ });
+ ui.end_row();
+ ui.label("Audio File Format:");
+ ui.horizontal(|ui| {
+ for (aiff, label, k) in [(false, "Broadcast Wave", "wav"), (true, "AIFF", "aiff")] {
+ let r = ui.add_enabled(d.audio == "separate", egui::RadioButton::new(d.aiff == aiff, label));
+ if r.clicked() {
+ d.aiff = aiff;
+ }
+ elems.push((format!("{p}.audioFormat.{k}"), r.rect, label.to_string()));
+ }
+ });
+ ui.end_row();
+ ui.label("Sample Rate:");
+ ui.horizontal(|ui| {
+ for r in RATES {
+ let b = ui.radio(d.sample_rate == r, format!("{r}"));
+ if b.clicked() {
+ d.sample_rate = r;
+ }
+ elems.push((format!("{p}.sampleRate.{r}"), b.rect, format!("{r} Hz")));
+ }
+ });
+ ui.end_row();
+ ui.label("Bits per Sample:");
+ ui.horizontal(|ui| {
+ for b in [16u16, 24] {
+ let r = ui.radio(d.bits == b, format!("{b}"));
+ if r.clicked() {
+ d.bits = b;
+ }
+ elems.push((format!("{p}.bitDepth.{b}"), r.rect, format!("{b}-bit")));
+ }
+ });
+ ui.end_row();
+ ui.label("Rendering:");
+ let linked = d.audio == "linked";
+ let r = ui.add_enabled(!linked, egui::Checkbox::new(&mut d.trim, "Trim audio files"));
+ elems.push((format!("{p}.trimAudio"), r.rect, d.trim.to_string()));
+ ui.end_row();
+ ui.label("Handle Frames:");
+ let r = ui.add_enabled(d.trim && !linked, egui::DragValue::new(&mut d.handles).range(0..=10_000));
+ elems.push((format!("{p}.handles"), r.rect, d.handles.to_string()));
+ ui.end_row();
+ ui.label("");
+ let r = ui.add_enabled(!linked, egui::Checkbox::new(&mut d.render_effects, "Render audio clip effects"));
+ elems.push((format!("{p}.renderAudioEffects"), r.rect, d.render_effects.to_string()));
+ ui.end_row();
+ ui.label("");
+ let r = ui.checkbox(&mut d.breakout, "Breakout to mono");
+ elems.push((format!("{p}.breakoutToMono"), r.rect, d.breakout.to_string()));
+ ui.end_row();
+ });
+ ui.add_space(8.0);
+ ui.horizontal(|ui| {
+ let c = ui.button("Cancel");
+ elems.push((format!("{p}.cancel"), c.rect, "Cancel".into()));
+ if c.clicked() {
+ close = true;
+ }
+ let o = ui.add(egui::Button::new(egui::RichText::new("OK").color(egui::Color32::WHITE)).fill(app.tokens.accent));
+ elems.push((format!("{p}.ok"), o.rect, "OK".into()));
+ if o.clicked() {
+ apply = true;
+ }
+ });
+ });
+ for (id, r, l) in elems {
+ app.auto.add(&id, r, &l);
+ }
+ if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ close = true;
+ }
+ if apply {
+ close = true;
+ let (ext, filter) = if d.omf { ("omf", "OMF") } else { ("aaf", "AAF") };
+ let stem = if d.title.is_empty() { "Sequence".to_string() } else { d.title.replace(['/', '\\', ':'], "_") };
+ let suggested = format!("{stem}.{ext}");
+ match app.hooks.pick_save_as.as_mut().and_then(|f| f(filter, &[ext], &suggested)) {
+ Some(path) => {
+ let mut params = json!({
+ "path": path,
+ "breakoutToMono": d.breakout,
+ "audio": d.audio,
+ "audioFormat": if d.aiff { "aiff" } else { "wav" },
+ "sampleRate": d.sample_rate,
+ "bitDepth": d.bits,
+ "trimAudio": d.trim && d.audio != "linked",
+ "handles": d.handles,
+ "renderAudioEffects": d.render_effects && d.audio != "linked",
+ });
+ if d.omf {
+ params["title"] = json!(d.title);
+ } else {
+ params["mixdownVideo"] = json!(d.mixdown_video);
+ }
+ let cmd = if d.omf { "file.exportOmf" } else { "file.exportAaf" };
+ match app.session.execute(cmd, params) {
+ Ok(v) => app.ui.status = format!("Exported {}", v["path"].as_str().unwrap_or_default()),
+ Err(e) => app.ui.status = e.to_string(),
+ }
+ }
+ None if app.hooks.pick_save_as.is_none() => app.ui.status = "no save dialog available: run the command with a `path`".into(),
+ None => {}
+ }
+ }
+ ctx.data_mut(|m| m.insert_temp(draft_id(), if close { None } else { Some(d) }));
+}
diff --git a/crates/ui-egui/src/panels/mod.rs b/crates/ui-egui/src/panels/mod.rs
index a5c19c8aa..6827fc5f6 100644
--- a/crates/ui-egui/src/panels/mod.rs
+++ b/crates/ui-egui/src/panels/mod.rs
@@ -14,6 +14,7 @@ pub mod file_dialogs;
pub mod graphics;
pub mod graphics_templates;
pub mod import_mode;
+pub mod interchange_export;
pub mod keyboard;
pub mod lumetri;
pub mod masks;
diff --git a/crates/ui-egui/tests/interchange_export_ui.rs b/crates/ui-egui/tests/interchange_export_ui.rs
new file mode 100644
index 000000000..790035c1f
--- /dev/null
+++ b/crates/ui-egui/tests/interchange_export_ui.rs
@@ -0,0 +1,168 @@
+//! Headless UI tests of File ▸ Export ▸ AAF… / OMF…: the settings dialogs, driven by automation id
+//! through the control channel, export through the host's save panel.
+
+use std::sync::Arc;
+use std::sync::mpsc::{Sender, channel};
+
+use egui_kittest::Harness;
+use filmcraft_engine::Session;
+use filmcraft_ui_egui::FilmcraftApp;
+use filmcraft_ui_egui::control::ControlRequest;
+use serde_json::{Value, json};
+
+struct Driver {
+ harness: Harness<'static, FilmcraftApp>,
+ tx: Sender<ControlRequest>,
+}
+
+impl Driver {
+ fn new(session: Session, save_to: std::path::PathBuf) -> Self {
+ let (tx, rx) = channel();
+ let mut app = FilmcraftApp::new(session).with_control(rx);
+ app.hooks.pick_save_as = Some(Box::new(move |_, exts, suggested| {
+ assert!(suggested.ends_with(&format!(".{}", exts[0])), "{suggested}");
+ Some(save_to.join(suggested).to_string_lossy().into_owned())
+ }));
+ let harness = Harness::builder().with_size(egui::vec2(1600.0, 980.0)).with_max_steps(10_000).build_eframe(move |_cc| app);
+ let mut d = Driver { harness, tx };
+ d.frames(4);
+ d
+ }
+
+ fn frames(&mut self, n: usize) {
+ for _ in 0..n {
+ let ctx = self.harness.ctx.clone();
+ let mut raw = std::mem::take(self.harness.input_mut());
+ eframe::App::raw_input_hook(self.harness.state_mut(), &ctx, &mut raw);
+ *self.harness.input_mut() = raw;
+ self.harness.step();
+ }
+ }
+
+ fn call(&mut self, method: &str, params: Value) -> Value {
+ let (req, reply) = ControlRequest::new(method, params.clone());
+ self.tx.send(req).unwrap();
+ for _ in 0..600 {
+ self.frames(1);
+ if let Ok(v) = reply.try_recv() {
+ return v;
+ }
+ }
+ panic!("no reply to {method} {params}");
+ }
+
+ fn ok(&mut self, method: &str, params: Value) -> Value {
+ let v = self.call(method, params.clone());
+ assert_eq!(v["ok"], json!(true), "{method} {params} failed: {v}");
+ v["result"].clone()
+ }
+
+ fn ids(&mut self, prefix: &str) -> Vec<String> {
+ let v = self.ok("ui.elements", json!({"prefix": prefix}));
+ v.as_array().unwrap().iter().filter_map(|e| e["id"].as_str().map(str::to_string)).collect()
+ }
+}
+
+/// A sequence "Mix" with one second of a 440 Hz tone on A1.
+fn session() -> Session {
+ let mut s = Session::default();
+ s.execute("file.newSequence", json!({"name": "Mix", "audio": 2, "video": 1})).unwrap();
+ let inter: Vec<f32> = (0..48_000)
+ .flat_map(|i| {
+ let x = (i as f32 * 440.0 * std::f32::consts::TAU / 48_000.0).sin() * 0.5;
+ [x, x]
+ })
+ .collect();
+ let bytes: Arc<[u8]> = filmcraft_engine::previews::write_wav_f32(&inter, 48_000).into();
+ let item = filmcraft_engine::commands::import_bytes(&mut s, "/tone.wav", bytes, None).unwrap();
+ s.execute("timeline.place", json!({"item": item.0, "audioTrack": "A1", "seconds": 0.0})).unwrap();
+ s
+}
+
+fn tmp(name: &str) -> std::path::PathBuf {
+ let d = std::env::temp_dir().join(format!("fc-ix-ui-{name}-{}", std::process::id()));
+ std::fs::create_dir_all(&d).unwrap();
+ d
+}
+
+#[test]
+fn aaf_and_omf_export_dialogs() {
+ let dir = tmp("dialogs");
+ let mut d = Driver::new(session(), dir.clone());
+ let items = d.ok("ui.menu.list", json!({}));
+ let menu: Vec<(String, Vec<String>)> = items
+ .as_array()
+ .unwrap()
+ .iter()
+ .map(|i| (i["id"].as_str().unwrap().to_string(), i["path"].as_array().unwrap().iter().map(|x| x.as_str().unwrap().to_string()).collect()))
+ .collect();
+ for id in ["file.exportAaf", "file.exportOmf"] {
+ let (_, path) = menu.iter().find(|(i, _)| i == id).unwrap_or_else(|| panic!("{id} missing from the menus"));
+ assert_eq!(path, &vec!["File".to_string(), "Export".to_string()]);
+ }
+
+ // AAF: the dialog lists Premiere's options; OK asks for the file and exports
+ let r = d.ok("ui.menu.invoke", json!({"id": "file.exportAaf"}));
+ assert_eq!(r["dialog"], "aafExport");
+ d.frames(3);
+ let ids = d.ids("aafExport.");
+ for id in [
+ "mixdownVideo",
+ "breakoutToMono",
+ "audio.embedded",
+ "audio.separate",
+ "audio.linked",
+ "audioFormat.wav",
+ "sampleRate.48000",
+ "bitDepth.24",
+ "trimAudio",
+ "handles",
+ "renderAudioEffects",
+ "ok",
+ "cancel",
+ ] {
+ assert!(ids.contains(&format!("aafExport.{id}")), "aafExport.{id} missing: {ids:?}");
+ }
+ d.ok("ui.click", json!({"id": "aafExport.bitDepth.24"}));
+ d.ok("ui.click", json!({"id": "aafExport.breakoutToMono"}));
+ d.frames(2);
+ d.ok("ui.click", json!({"id": "aafExport.ok"}));
+ d.frames(4);
+ assert!(d.ids("aafExport.").is_empty(), "the dialog closes");
+ let aaf = std::fs::read(dir.join("Mix.aaf")).expect("Mix.aaf written");
+ assert!(filmcraft_interchange::aaf::sniff(&aaf));
+ let (imp, extracted, _) = filmcraft_interchange::aaf::import(&aaf, &Default::default()).unwrap();
+ assert_eq!(extracted.len(), 2, "embedded, broken out to two mono essences");
+ let (_, ch, sr, bits) = filmcraft_interchange::wav::parse_wav(&extracted[0].wav).unwrap();
+ assert_eq!((ch, sr, bits), (1, 48_000, 24));
+ assert_eq!(imp.sequences.len(), 1);
+
+ // OMF: cancel leaves nothing behind; OK with separate AIFF files
+ d.ok("ui.menu.invoke", json!({"id": "file.exportOmf"}));
+ d.frames(3);
+ let ids = d.ids("omfExport.");
+ assert!(ids.contains(&"omfExport.title".to_string()) && !ids.contains(&"omfExport.audio.linked".to_string()), "{ids:?}");
+ d.ok("ui.click", json!({"id": "omfExport.cancel"}));
+ d.frames(3);
+ assert!(!dir.join("Mix.omf").exists());
+ d.ok("ui.menu.invoke", json!({"id": "file.exportOmf"}));
+ d.frames(3);
+ d.ok("ui.click", json!({"id": "omfExport.audio.separate"}));
+ d.frames(2);
+ d.ok("ui.click", json!({"id": "omfExport.audioFormat.aiff"}));
+ d.frames(2);
+ d.ok("ui.click", json!({"id": "omfExport.ok"}));
+ d.frames(4);
+ let omf = std::fs::read(dir.join("Mix.omf")).expect("Mix.omf written");
+ assert!(filmcraft_interchange::omf::sniff(&omf));
+ let audio_dir = dir.join("Mix Audio Files");
+ let aifs: Vec<_> = std::fs::read_dir(&audio_dir).unwrap().filter_map(|e| e.ok()).filter(|e| e.path().extension().is_some_and(|x| x == "aif")).collect();
+ assert_eq!(aifs.len(), 1, "one trimmed AIFF");
+
+ // with a path the menu command exports directly (agents)
+ let p = dir.join("direct.aaf").to_string_lossy().into_owned();
+ let v = d.ok("ui.menu.invoke", json!({"id": "file.exportAaf", "params": {"path": p, "audio": "linked"}}));
+ assert!(v.get("dialog").is_none(), "{v}");
+ assert!(std::path::Path::new(&p).exists());
+ let _ = std::fs::remove_dir_all(dir);
+}