Import: Interpret Footage has Start Timecode, as in After Effects (#297)
After Effects' Interpret Footage has Start Timecode: Use Source File Timecode, or Override Start, which changes the timecode the footage shows and leaves its frames alone. The Start Frame field that trimmed or padded a sequence's head isn't in After Effects, so it is replaced. Footage.start_timecode (Override Start, in frames at the footage's rate; None = Use Source, 0 as file timecode isn't read) relabels source time: the Footage panel's current time and footage.info's `timecode` count from it. file.interpretFootage takes `overrideStart` and `startTimecode` (timecode, read at the footage's rate after any frame rate change, or a frame number, 0 to 1e9). It applies to every footage with time, not only sequences, and Reload keeps it. A sequence's frames always run from its first file's number to its last. Test: start_timecode_only_relabels_source_time (project), interpret_footage_start_timecode_relabels_source_time (engine: the reply, the Footage panel's timecode, frame numbers, Use Source, the footage's rate, bad values, undo), Reload keeps it, and the Interpret Footage fields in ui_drag_drop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e12bf5ca7d
commit
a34aecd719
@@ -975,10 +975,11 @@ pub struct Footage {
|
||||
/// Effects; [`sequence`]).
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub alphabetical: bool,
|
||||
/// Image sequences: Interpret Footage ▸ Start Frame, the frame number at the footage's first
|
||||
/// frame (`None` = the first file's).
|
||||
/// Interpret Footage ▸ Start Timecode ▸ Override Start: the frame (at the footage's frame
|
||||
/// rate) its timecode shows at its first frame. `None` = Use Source File Timecode (0: file
|
||||
/// timecode isn't read). It only relabels source time, as in After Effects.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub start_frame: Option<i64>,
|
||||
pub start_timecode: Option<i64>,
|
||||
}
|
||||
|
||||
fn is_default<T: Default + PartialEq>(v: &T) -> bool {
|
||||
@@ -1012,12 +1013,18 @@ impl Default for Footage {
|
||||
layer: None,
|
||||
page: 0,
|
||||
alphabetical: false,
|
||||
start_frame: None,
|
||||
start_timecode: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Footage {
|
||||
/// Source time as the footage's timecode: its frame `frame` from Start Timecode
|
||||
/// (`0:00:41:20`), as the Footage panel shows it.
|
||||
pub fn timecode(&self, frame: i64) -> String {
|
||||
effectcraft_time::format_timecode_ae(frame.saturating_add(self.start_timecode.unwrap_or(0)), self.frame_rate, false)
|
||||
}
|
||||
|
||||
/// The data format of data footage: `json`, `csv` or `tsv` (from the file extension).
|
||||
pub fn data_format(&self) -> Option<&'static str> {
|
||||
if self.kind != FootageKind::Data {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
//! Image sequences: numbered stills (`shot_0001.png`, `shot_0002.png`, …) played as one footage
|
||||
//! item ([`FootageKind::Sequence`]).
|
||||
//!
|
||||
//! A sequence's files are kept in frame-number order ([`Footage::sequence`]). How its frames map
|
||||
//! to the files follows Interpret Footage: **Start Frame** ([`Footage::start_frame`]) is the
|
||||
//! frame number shown at the footage's first frame. A gap in the numbering shows a placeholder
|
||||
//! (colour bars), as in After Effects, except in a sequence imported with Force Alphabetical
|
||||
//! Order ([`Footage::alphabetical`]), whose files play one after another.
|
||||
//! A sequence's files are kept in frame-number order ([`Footage::sequence`]). Its frames run from
|
||||
//! the first file's number to the last's; a gap in the numbering shows a placeholder (colour
|
||||
//! bars), as in After Effects, except in a sequence imported with Force Alphabetical Order
|
||||
//! ([`Footage::alphabetical`]), whose files play one after another.
|
||||
|
||||
use crate::{Footage, FootageKind};
|
||||
|
||||
@@ -78,15 +77,8 @@ impl Footage {
|
||||
self.sequence.partition_point(|p| frame_number(p).is_some_and(|x| x < n))
|
||||
}
|
||||
|
||||
/// The frame number at the footage's first frame: Start Frame, or the first file's number
|
||||
/// (0 when unnumbered).
|
||||
pub fn first_frame_number(&self) -> i64 {
|
||||
self.start_frame.or_else(|| self.file_number(0)).unwrap_or(0)
|
||||
}
|
||||
|
||||
/// How many frames an image sequence has: the span of its numbering from Start Frame, or its
|
||||
/// files from Start Frame on (Force Alphabetical Order, or unnumbered files). At least 1; 0
|
||||
/// for other footage.
|
||||
/// How many frames an image sequence has: the span of its numbering, or its files (Force
|
||||
/// Alphabetical Order, or unnumbered files). At least 1; 0 for other footage.
|
||||
pub fn sequence_frames(&self) -> i64 {
|
||||
if !self.is_file_sequence() {
|
||||
return 0;
|
||||
@@ -94,12 +86,9 @@ impl Footage {
|
||||
let n = match self.numbered() {
|
||||
Some(first) => {
|
||||
let last = self.sequence.len().checked_sub(1).and_then(|i| self.file_number(i)).unwrap_or(first);
|
||||
last.saturating_sub(self.start_frame.unwrap_or(first)).saturating_add(1)
|
||||
}
|
||||
None => {
|
||||
let skip = self.start_frame.map_or(0, |s| self.first_file_from(s));
|
||||
self.sequence.len().saturating_sub(skip) as i64
|
||||
last.saturating_sub(first).saturating_add(1)
|
||||
}
|
||||
None => self.sequence.len() as i64,
|
||||
};
|
||||
n.clamp(1, MAX_SEQUENCE_FRAMES)
|
||||
}
|
||||
@@ -111,18 +100,15 @@ impl Footage {
|
||||
return None;
|
||||
}
|
||||
let Some(first) = self.numbered() else {
|
||||
let skip = self.start_frame.map_or(0, |s| self.first_file_from(s));
|
||||
let k = usize::try_from(i).ok()?.saturating_add(skip);
|
||||
// Past the last file (Start Frame after it): the last file.
|
||||
return self.sequence.get(k).or(self.sequence.last()).map(String::as_str);
|
||||
return self.sequence.get(usize::try_from(i).ok()?).map(String::as_str);
|
||||
};
|
||||
let n = self.start_frame.unwrap_or(first).saturating_add(i);
|
||||
let n = first.saturating_add(i);
|
||||
let k = self.first_file_from(n);
|
||||
self.sequence.get(k).filter(|p| frame_number(p) == Some(n)).map(String::as_str)
|
||||
}
|
||||
|
||||
/// Set an image sequence's duration to its frames at its frame rate (after its files,
|
||||
/// frame rate or Start Frame changed).
|
||||
/// Set an image sequence's duration to its frames at its frame rate (after its files or
|
||||
/// frame rate changed).
|
||||
pub fn sync_sequence_duration(&mut self) {
|
||||
if self.is_file_sequence() {
|
||||
self.duration = self.frame_rate.tick_of(self.sequence_frames());
|
||||
@@ -179,27 +165,20 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn start_frame_trims_or_pads_the_head() {
|
||||
fn start_timecode_only_relabels_source_time() {
|
||||
// Override Start changes the timecode shown, not the frames (After Effects).
|
||||
let at = |f: &Footage, i| f.sequence_file(i).map(|p| frame_number(p).unwrap_or(-1));
|
||||
let mut f = seq(&[1001, 1002, 1003]);
|
||||
assert_eq!(f.first_frame_number(), 1001);
|
||||
f.start_frame = Some(1002);
|
||||
assert_eq!((f.sequence_frames(), at(&f, 0), at(&f, 1)), (2, Some(1002), Some(1003)));
|
||||
f.start_frame = Some(999);
|
||||
assert_eq!((f.sequence_frames(), at(&f, 0), at(&f, 2)), (5, None, Some(1001)));
|
||||
let mut f = Footage { frame_rate: effectcraft_time::FrameRate::from_f64(24.0), ..seq(&[1001, 1002, 1003]) };
|
||||
assert_eq!(f.timecode(0), "0:00:00:00");
|
||||
f.start_timecode = Some(1001);
|
||||
assert_eq!((f.sequence_frames(), at(&f, 0), at(&f, 2)), (3, Some(1001), Some(1003)));
|
||||
assert_eq!((f.timecode(0).as_str(), f.timecode(2).as_str()), ("0:00:41:17", "0:00:41:19"));
|
||||
// Hostile values never panic.
|
||||
f.start_timecode = Some(i64::MAX);
|
||||
let _ = f.timecode(i64::MAX);
|
||||
assert_eq!((f.sequence_file(i64::MAX), f.sequence_file(-1)), (None, None));
|
||||
f.alphabetical = true;
|
||||
f.start_frame = Some(1003);
|
||||
assert_eq!((f.sequence_frames(), at(&f, 0)), (1, Some(1003)));
|
||||
// Hostile values never panic and stay bounded.
|
||||
f.alphabetical = false;
|
||||
f.start_frame = Some(i64::MIN);
|
||||
assert_eq!(f.sequence_frames(), MAX_SEQUENCE_FRAMES);
|
||||
assert_eq!(f.sequence_file(i64::MAX), None);
|
||||
f.start_frame = Some(i64::MAX);
|
||||
assert_eq!(f.sequence_frames(), 1);
|
||||
f.alphabetical = true;
|
||||
assert_eq!(f.sequence_file(-1), None);
|
||||
assert!(f.sequence_file(5).is_some());
|
||||
assert_eq!((f.sequence_frames(), f.sequence_file(-1), f.sequence_file(3)), (3, None, None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user