FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Stop writing an empty ref for FCPXML titles and adjustment layers (#2638)
MarekSpodBiedryd1b45e960b12
diff --git a/crates/interchange/README.md b/crates/interchange/README.mdindex edaff851f..976989e14 100644--- a/crates/interchange/README.md+++ b/crates/interchange/README.md@@ -76,7 +76,7 @@ none of the exports brings one back. Each such clip is named in the export `Repo| Format | Written as | On import into FilmCraft ||---|---|---|| FCP7 XML | a clip item without media (its layers as FilmCraft filter ids) | not read back; the import report names the skipped clip item |-| FCPXML | a clip without media | not read back |+| FCPXML | a gap on V1; left out on other tracks (a gap exists only in the primary storyline) | not read back || OTIO | a clip with a `MissingReference` (effects in the `filmcraft` metadata) | offline media || EDL | an ordinary event with the reel the reel mode gives | an ordinary clip || AAF | a gap | nothing |diff --git a/crates/interchange/src/fcpxml.rs b/crates/interchange/src/fcpxml.rsindex e231fff5e..481813f4d 100644--- a/crates/interchange/src/fcpxml.rs+++ b/crates/interchange/src/fcpxml.rs@@ -871,6 +871,10 @@ impl Exp<'_, '_> {if merged_audio.contains(&it.id) {continue;}+ if let Some(what) = self.unsupported(it, rate) {+ self.report.warn(format!("{what}: it is left out and is not read back on import"));+ continue;+ }let Some(pi) = els.iter().position(|e| e.start <= it.start && it.start < e.end) else {self.report.warn("a connected clip could not be attached and was dropped");continue;@@ -938,30 +942,29 @@ impl Exp<'_, '_> {)}+ /// How the report names a clip FCPXML cannot carry (a generator, a title, an adjustment layer); `None` for any+ /// other clip. Such a clip has no asset to reference, and an empty `ref` is not a valid IDREF: Final Cut Pro+ /// rejects the whole file. A `<gap>` exists only in a spine, so a connected one is left out instead.+ fn unsupported(&self, it: &TrackItem, rate: FrameRate) -> Option<String> {+ if let Some(g) = generator_of(self.p, base_item(self.p, it.item)) {+ return Some(format!("generator \"{}\" is not supported in FCPXML", g.label()));+ }+ crate::common::uncarried_clip(self.p, it, rate).map(|clip| format!("{clip} is not supported in FCPXML"))+ }+/// A clip element at `offset` (in its parent's local time).#[allow(clippy::too_many_arguments)]fn clip_el(&mut self, it: &TrackItem, audio: Option<&TrackItem>, kind: TrackKind, offset: Tick, lane: Option<i32>, seq: &Sequence, primary: bool) -> El {let rate = seq.settings.frame_rate;let base = base_item(self.p, it.item);let is_seq = matches!(self.p.item(base).map(|i| &i.kind), Some(ItemKind::Sequence(_)));- let generator = generator_of(self.p, base).cloned();let lane_attr = lane.map(|l| format!(" lane=\"{l}\"")).unwrap_or_default();let name = crate::xml::escape(&it.name);- if let Some(g) = generator {- self.report.warn(format!("generator \"{}\" is not supported in FCPXML; written as a gap", g.label()));- return El {- start: it.start,- end: it.end(),- local: offset,- xml_open: format!(- "<gap name=\"{name}\"{lane_attr} offset=\"{}\" start=\"{}\" duration=\"{}\"",- fmt_time(offset, rate),- fmt_time(offset, rate),- fmt_time(it.duration, rate)- ),- children: vec![],- close: "gap".into(),- };+ // In the primary storyline, a clip FCPXML cannot carry becomes a gap that keeps the timing+ // (connected ones never get here: see `unsupported`).+ if let Some(what) = self.unsupported(it, rate) {+ self.report.warn(format!("{what}: it is written as a gap and is not read back on import"));+ return gap_el(it, &name, offset, rate);}// Local timeline of the element: origin + source time (retimed clips use a timeMap).let (tag, r, origin) = if is_seq {@@ -974,13 +977,7 @@ impl Exp<'_, '_> {let origin = self.p.sequence(base).map(|s| s.settings.frame_rate.tick_of(s.start_timecode)).unwrap_or(Tick::ZERO);("ref-clip", r, origin)} else {- let r = match crate::common::uncarried_clip(self.p, it, rate) {- Some(clip) => {- self.report.warn(format!("{clip} is not supported in FCPXML: it is written as a clip without media and is not read back on import"));- String::new()- }- None => self.asset(base, rate),- };+ let r = self.asset(base, rate);let m = item_media(self.p, base);let mrate = m.and_then(|m| m.info.video.as_ref().map(|v| v.frame_rate)).unwrap_or(rate);let st = m.and_then(|m| m.info.start_timecode).map(|f| mrate.tick_of(f)).unwrap_or(Tick::ZERO);@@ -1138,6 +1135,23 @@ impl Exp<'_, '_> {}}+/// A primary-storyline `<gap>` standing in for a clip FCPXML cannot carry; it keeps the clip's place and length.+fn gap_el(it: &TrackItem, name: &str, offset: Tick, rate: FrameRate) -> El {+ El {+ start: it.start,+ end: it.end(),+ local: offset,+ xml_open: format!(+ "<gap name=\"{name}\" offset=\"{}\" start=\"{}\" duration=\"{}\"",+ fmt_time(offset, rate),+ fmt_time(offset, rate),+ fmt_time(it.duration, rate)+ ),+ children: vec![],+ close: "gap".into(),+ }+}+fn wrap(tag: &str, attrs: &str, params: &[String]) -> String {if params.is_empty() { format!("<{tag}{attrs}/>") } else { format!("<{tag}{attrs}>\n{}\n</{tag}>", params.join("\n")) }}diff --git a/crates/interchange/tests/uncarried_clips.rs b/crates/interchange/tests/uncarried_clips.rsindex 2f0902e26..5355c1a9d 100644--- a/crates/interchange/tests/uncarried_clips.rs+++ b/crates/interchange/tests/uncarried_clips.rs@@ -144,3 +144,19 @@ fn fcp7_import_reports_a_clip_item_whose_file_is_not_defined() {let (_, report) = import(&bytes, Format::Fcp7Xml, None).unwrap();assert!(!report.mentions("does not define"), "{report}");}++/// An empty `ref` is not a valid IDREF: Final Cut Pro rejects the whole file. The adjustment layer+/// on V1 becomes a gap in the primary storyline; the connected title is left out (a `<gap>` can+/// only sit in a spine). The media clip still references its asset.+#[test]+fn fcpxml_has_no_empty_ref_for_a_title() {+ let (p, s) = project_with_a_title();+ let (bytes, report) = export_report(&p, s, Format::Fcpxml);+ let xml = String::from_utf8(bytes).unwrap();+ assert!(!xml.contains("ref=\"\""), "{xml}");+ assert!(!xml.contains("Opening"), "{xml}");+ assert_eq!(xml.matches("<gap name=\"Grade\" offset=").count(), 1, "{xml}");+ assert!(xml.contains("<asset-clip ref=\"r"), "{xml}");+ assert!(report.mentions(&format!("{TITLE} is not supported in FCPXML: it is left out")), "{report}");+ assert!(report.mentions(&format!("{LAYER} is not supported in FCPXML: it is written as a gap")), "{report}");+}