FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
#340: FCP7 XML clip source span always matches its record span
txiki739d39692af6358
diff --git a/crates/interchange/src/fcp7.rs b/crates/interchange/src/fcp7.rsindex 047b013fc..0fdddd59b 100644--- a/crates/interchange/src/fcp7.rs+++ b/crates/interchange/src/fcp7.rs@@ -932,6 +932,10 @@ impl Exp<'_, '_> {let hold = c.frame_hold;let src_in = hold.unwrap_or(c.source_in);let src_out = if hold.is_some() { src_in + c.duration } else { c.source_out() };+ let (start_f, end_f, in_f) = (frames_round(rate, c.start), frames_round(rate, c.end()), frames_round(rate, src_in));+ // At normal speed (and on a freeze frame) the source span is the record span. Rounded on its own+ // it can come out a frame shorter or longer than `end - start` (#340), so derive it from them.+ let out_f = if hold.is_some() || c.speed.abs() == 1.0 { in_f.saturating_add(end_f.saturating_sub(start_f)) } else { frames_round(rate, src_out) };self.w.open(tag, &[("id", xid)]);if generator.is_none() && !is_seq {let mid = self.master_id(base);@@ -940,12 +944,12 @@ impl Exp<'_, '_> {self.w.text("name", &c.name);self.w.text("enabled", bool_str(c.enabled));let media_dur = self.p.item(base).map(|i| i.duration()).unwrap_or(Tick::ZERO).max(src_out);- self.w.text("duration", frames_round(rate, media_dur));+ self.w.text("duration", frames_round(rate, media_dur).max(out_f));write_rate(&mut self.w, rate);- self.w.text("start", frames_round(rate, c.start));- self.w.text("end", frames_round(rate, c.end()));- self.w.text("in", frames_round(rate, src_in));- self.w.text("out", frames_round(rate, src_out));+ self.w.text("start", start_f);+ self.w.text("end", end_f);+ self.w.text("in", in_f);+ self.w.text("out", out_f);self.w.text("pproTicksIn", src_in.0);self.w.text("pproTicksOut", src_out.0);if let Some(g) = &generator {diff --git a/crates/interchange/tests/fcp7.rs b/crates/interchange/tests/fcp7.rsindex 2b72d1e43..4d3677efc 100644--- a/crates/interchange/tests/fcp7.rs+++ b/crates/interchange/tests/fcp7.rs@@ -483,3 +483,47 @@ fn a_master_clip_used_by_an_earlier_sequence_still_lands_in_its_bin() {assert_ne!(bin, p.root.id, "the take was left loose at the top");assert_eq!(p.root.find_bin(bin).unwrap().name, "Comedy");}++/// `start`/`end`/`in`/`out` of every sequence clip item in an exported document.+fn clip_spans(xml: &str) -> Vec<(i64, i64, i64, i64)> {+ let tag = |block: &str, name: &str| -> i64 {+ let open = format!("<{name}>");+ let at = block.find(&open).unwrap_or_else(|| panic!("no <{name}> in {block}")) + open.len();+ block[at..].split('<').next().unwrap().trim().parse().unwrap()+ };+ xml.split("<clipitem").skip(1).filter(|b| b.contains("<start>")).map(|b| (tag(b, "start"), tag(b, "end"), tag(b, "in"), tag(b, "out"))).collect()+}++/// #340: a clip placed by seconds in a 23.976 sequence has sub-frame start, duration and source in.+/// Its record span and source span were rounded to frames independently, so `out - in` could come+/// out a frame shorter than `end - start` (Premiere then reads a different source range).+#[test]+fn sub_frame_clips_keep_equal_source_and_record_spans() {+ const SECOND: i64 = 254_016_000_000;+ let r = FrameRate::FPS_23_976;+ let mut p = Project::new("P");+ let a = media(&mut p, "/m/a.mov", true, true, r);+ let s = sequence(&mut p, "t", r, false);+ let c = clip(&mut p, s, TrackKind::Video, 0, a, 0, 24, 0);+ // the issue's case first (start 0, source in 20 s, 3 s long), then starts, ins and lengths in tenths of a second+ let mut cases = vec![(0, 200, 30)];+ for start in [0, 1, 5, 17, 33] {+ for src in [0, 3, 7, 200, 413] {+ for dur in [1, 4, 30, 71, 125] {+ cases.push((start, src, dur));+ }+ }+ }+ for (start, src, dur) in cases {+ let (_, it) = p.sequence_mut(s).unwrap().find_item_mut(c).unwrap();+ it.start = Tick(start * SECOND / 10);+ it.source_in = Tick(src * SECOND / 10);+ it.duration = Tick(dur * SECOND / 10);+ let (bytes, _) = export(&p, s, Format::Fcp7Xml, &ExportOptions::default()).expect("export");+ let xml = String::from_utf8(bytes).unwrap();+ let spans = clip_spans(&xml);+ assert_eq!(spans.len(), 1, "{xml}");+ let (start_f, end_f, in_f, out_f) = spans[0];+ assert_eq!(out_f - in_f, end_f - start_f, "start {start}, in {src}, duration {dur} (tenths of a second): {spans:?}");+ }+}