Import: missing sequence frames show a placeholder, as in After Effects (#297)

After Effects shows a missing frame of an image sequence as a
placeholder (colour bars) and has no Hold Previous Frame or Skip choice
in Interpret Footage, so EffectCraft doesn't either.

Interpret Footage loses its Missing Frames field, file.interpretFootage
its missingFrames parameter, and Footage its missing_frames setting. A
gap in a numbered sequence's numbering always shows colour bars. A
sequence imported with Force Alphabetical Order still plays its files
one after another (its numbering doesn't count), as in After Effects;
that is now an internal Footage.alphabetical flag, set on import and
kept by Reload. The Interpret Footage note lists the missing frames.

Projects saved before this have no such field and open with the After
Effects behaviour: a sequence with gaps shows placeholders where it
used to close them up.

Test: project sequence unit tests (placeholders, alphabetical order,
projects saved without the flag), tests_sequence (Start Frame instead
of Hold / Skip), sequence_gaps_show_placeholders (media) and the
Interpret Footage fields in ui_drag_drop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bflatastic
2026-10-09 18:52:19 +07:00
co-authored by Claude Opus 5.5
parent 50c9549529
commit efd348335f
14 changed files with 108 additions and 169 deletions
+2 -2
View File
@@ -260,11 +260,11 @@ impl Prober {
let mut warning = None;
// Settings ▸ Import ▸ Report Missing Frames (numbered sequences).
if f.kind == FootageKind::Sequence
&& f.missing_frames != effectcraft_project::MissingFrames::Skip
&& !f.alphabetical
&& self.report_missing_frames
&& let Some(gaps) = crate::sequence::missing_report(&f.sequence)
{
warning = Some(format!("{name}: {gaps} (shown as placeholders; File ▸ Interpret Footage ▸ Missing Frames)"));
warning = Some(format!("{name}: {gaps} (shown as placeholders)"));
}
// Settings ▸ Import ▸ Interpret Unlabeled Alpha As: images only (a 3D model renders its
// own alpha, and audio and data have none).
+10 -19
View File
@@ -553,8 +553,6 @@ pub(crate) struct Interpretation {
fields: Option<effectcraft_project::FieldOrder>,
profile: Option<Option<effectcraft_project::ColorSpace>>,
linear: Option<bool>,
/// Image sequences: Missing Frames.
missing: Option<effectcraft_project::MissingFrames>,
/// Image sequences: Start Frame (`Some(None)` = the first file's number).
start: Option<Option<i64>>,
}
@@ -603,10 +601,6 @@ impl Interpretation {
None => None,
};
it.linear = super::b_p(p, "linearLight");
it.missing = match str_p(p, "missingFrames") {
Some(m) => Some(effectcraft_project::MissingFrames::parse(m).ok_or_else(|| bad(cmd, format!("missingFrames: placeholder|hold|skip, not `{m}`")))?),
None => None,
};
// Start Frame: a frame number, or "file" for the first file's.
it.start = match p.get("startFrame") {
None | Some(Value::Null) => None,
@@ -624,7 +618,7 @@ impl Interpretation {
pub(crate) fn apply(&self, f: &mut Footage, guessed: Option<(AlphaMode, [f32; 3])>) {
let before = f.frame_rate;
self.apply_settings(f, guessed);
// A sequence's length is its frames (Missing Frames and Start Frame decide how many).
// A sequence's length is its frames (Start Frame decides how many).
if f.kind == FootageKind::Sequence && !f.sequence.is_empty() {
f.sync_sequence_duration();
return;
@@ -677,15 +671,12 @@ impl Interpretation {
if let Some(v) = self.linear {
f.linear_light = v;
}
if f.kind == FootageKind::Sequence {
if let Some(m) = self.missing {
f.missing_frames = m;
}
if let Some(start) = self.start {
// The first file's own number needn't be stored (it follows the files).
let first = f.sequence.first().and_then(|p| effectcraft_project::sequence::frame_number(p));
f.start_frame = start.filter(|n| Some(*n) != first);
}
if f.kind == FootageKind::Sequence
&& let Some(start) = self.start
{
// The first file's own number needn't be stored (it follows the files).
let first = f.sequence.first().and_then(|p| effectcraft_project::sequence::frame_number(p));
f.start_frame = start.filter(|n| Some(*n) != first);
}
}
}
@@ -763,7 +754,7 @@ fn interpret(s: &mut Session, p: &Value) -> Result<Value> {
Some(ItemKind::Footage(f)) => Some(json!({
"item": i.0, "alpha": format!("{:?}", f.alpha), "matteColor": f.premul_color, "invertAlpha": f.invert_alpha,
"fields": f.fields.label(), "pixelAspect": f.pixel_aspect, "loop": f.loop_count, "frameRate": f.frame_rate.as_f64(),
"linearLight": f.linear_light, "missingFrames": f.missing_frames.id(), "startFrame": f.first_frame_number(),
"linearLight": f.linear_light, "startFrame": f.first_frame_number(),
"frames": f.sequence_frames(),
})),
_ => None,
@@ -900,7 +891,7 @@ fn reload(s: &mut Session, p: &Value) -> Result<Value> {
if nf.kind == FootageKind::Sequence && f.kind == FootageKind::Sequence {
nf.frame_rate = f.frame_rate;
nf.native_rate = f.native_rate;
nf.missing_frames = f.missing_frames;
nf.alphabetical = f.alphabetical;
nf.start_frame = f.start_frame;
nf.sync_sequence_duration();
}
@@ -1003,7 +994,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Main...",
["File", "Interpret Footage"],
Some("Cmd+Alt+G"),
"{items?, frameRate?: fps|\"file\", alpha?: straight|premultiplied|ignore|guess, guessAlpha?, matteColor?, invertAlpha?, loop?, pixelAspect?, fields?: off|upper|lower, colorProfile?: srgb|rec709|rec2020|p3|auto, linearLight?, missingFrames?: placeholder|hold|skip (image sequences: what a gap in the numbering shows), startFrame?: number|\"file\" (image sequences: the frame number at the footage's first frame)}",
"{items?, frameRate?: fps|\"file\", alpha?: straight|premultiplied|ignore|guess, guessAlpha?, matteColor?, invertAlpha?, loop?, pixelAspect?, fields?: off|upper|lower, colorProfile?: srgb|rec709|rec2020|p3|auto, linearLight?, startFrame?: number|\"file\" (image sequences: the frame number at the footage's first frame)}",
has_footage_selection,
interpret
),
+4 -4
View File
@@ -12,7 +12,7 @@
//! picking every frame of a sequence imports it there too.
use effectcraft_project::sequence::{frame_number, missing_frame_ranges, sequence_name, split_frame_number};
use effectcraft_project::{Footage, FootageKind, MissingFrames};
use effectcraft_project::{Footage, FootageKind};
use effectcraft_time::FrameRate;
use crate::{Importer, Services};
@@ -186,8 +186,8 @@ pub fn sequences(services: &dyn Services, paths: &[String], alphabetical: bool)
}
/// Probe what a [`Source`] makes. A sequence is its first file's footage with every file, at
/// `rate`, showing gaps in its numbering as placeholders (or closing them up when
/// alphabetical).
/// `rate`, showing gaps in its numbering as placeholders, as in After Effects (in Force
/// Alphabetical Order the files play one after another).
pub fn probe(importer: &dyn Importer, src: &Source, rate: FrameRate) -> Result<Footage, String> {
let Source::Sequence { files, alphabetical } = src else { return importer.probe(src.path()) };
let mut f = importer.probe(src.path())?;
@@ -196,7 +196,7 @@ pub fn probe(importer: &dyn Importer, src: &Source, rate: FrameRate) -> Result<F
}
f.kind = FootageKind::Sequence;
f.sequence = files.clone();
f.missing_frames = if *alphabetical { MissingFrames::Skip } else { MissingFrames::Placeholder };
f.alphabetical = *alphabetical;
f.start_frame = None;
f.frame_rate = rate;
f.native_rate = None;
+16 -18
View File
@@ -1,8 +1,8 @@
//! Image sequences (#297): File ▸ Import with the "<format> Sequence" option, picked ranges,
//! folders, Force Alphabetical Order, the import frame rate, Replace Footage, and Interpret
//! Footage ▸ Missing Frames / Start Frame.
//! folders, Force Alphabetical Order, the import frame rate, Replace Footage, missing frames
//! (placeholders, as in After Effects) and Interpret Footage ▸ Start Frame.
use effectcraft_project::{Footage, FootageKind, ItemId, ItemKind, MissingFrames};
use effectcraft_project::{Footage, FootageKind, ItemId, ItemKind};
use effectcraft_time::{FrameRate, Tick};
use serde_json::{Value, json};
@@ -58,7 +58,7 @@ fn one_picked_numbered_file_imports_its_run_as_one_sequence() {
assert_eq!(r["items"].as_array().unwrap().len(), 1, "{r}");
let (name, f) = footage(&s, &r["items"][0]);
assert_eq!(name, "shot_[0001-0005].png");
assert_eq!((f.kind, f.sequence.len(), f.missing_frames), (FootageKind::Sequence, 4, MissingFrames::Placeholder));
assert_eq!((f.kind, f.sequence.len(), f.alphabetical), (FootageKind::Sequence, 4, false));
assert_eq!(f.path, at(&dir, "shot_0001.png"));
// Frames 1–5 at Settings ▸ Import ▸ Sequence Footage (30 fps); frame 3 is a placeholder.
assert_eq!(f.duration, FrameRate::FPS_30.tick_of(5));
@@ -118,11 +118,13 @@ fn force_alphabetical_order_takes_every_image_of_the_type() {
let (name, f) = footage(&s, &r["items"][0]);
let files: Vec<String> = f.sequence.iter().map(|p| crate::sequence::file_name(p)).collect();
assert_eq!(files, ["other_7.png", "take_a.png", "take_b.png"]);
assert_eq!((name.as_str(), f.missing_frames), ("other_7.png", MissingFrames::Skip));
// Its numbering doesn't count: the files play one after another.
assert_eq!((name.as_str(), f.alphabetical, f.sequence_frames()), ("other_7.png", true, 3));
assert!(r["warnings"].as_array().is_none_or(Vec::is_empty), "{r}");
}
#[test]
fn interpret_footage_sets_missing_frames_and_start_frame() {
fn interpret_footage_sets_start_frame() {
let dir = folder(&RUN);
let mut s = session();
let item = s.execute("file.import", json!({"paths": [at(&dir, "shot_0001.png")]})).unwrap()["items"][0].clone();
@@ -130,15 +132,11 @@ fn interpret_footage_sets_missing_frames_and_start_frame() {
let layer = s.execute("layer.addItem", json!({"item": item})).unwrap()["layer"].as_u64().unwrap();
let out = |s: &Session| s.active_comp().unwrap().layer(effectcraft_project::LayerId(layer)).unwrap().out_point;
assert_eq!(out(&s), FrameRate::FPS_30.tick_of(5));
// Hold: the gap shows frame 2; the length stays 5 frames.
let r = s.execute("file.interpretFootage", json!({"items": [item], "missingFrames": "hold"})).unwrap();
assert_eq!((r["items"][0]["missingFrames"].as_str(), r["items"][0]["frames"].as_i64()), (Some("hold"), Some(5)));
assert_eq!(footage(&s, &item).1.sequence_file(2).map(crate::sequence::file_name).as_deref(), Some("shot_0002.png"));
// Skip: 4 frames, and the layer that ran to the end still does.
s.execute("file.interpretFootage", json!({"items": [item], "missingFrames": "skip"})).unwrap();
// Start Frame 2 trims frame 1: 4 frames, and the layer that ran to the end still does.
s.execute("file.interpretFootage", json!({"items": [item], "startFrame": 2})).unwrap();
assert_eq!((footage(&s, &item).1.duration, out(&s)), (FrameRate::FPS_30.tick_of(4), FrameRate::FPS_30.tick_of(4)));
// Start Frame 0 with placeholders: frame 0 is missing, 6 frames in all.
let r = s.execute("file.interpretFootage", json!({"items": [item], "missingFrames": "placeholder", "startFrame": 0})).unwrap();
// Start Frame 0: frame 0 is missing (a placeholder), 6 frames in all.
let r = s.execute("file.interpretFootage", json!({"items": [item], "startFrame": 0})).unwrap();
assert_eq!((r["items"][0]["startFrame"].as_i64(), r["items"][0]["frames"].as_i64()), (Some(0), Some(6)));
assert_eq!(footage(&s, &item).1.sequence_file(0), None);
// The first file's own number isn't stored; "file" goes back to it.
@@ -150,7 +148,7 @@ fn interpret_footage_sets_missing_frames_and_start_frame() {
// The frame rate re-times the frames.
s.execute("file.interpretFootage", json!({"items": [item], "frameRate": 10})).unwrap();
assert_eq!(footage(&s, &item).1.duration, Tick::from_seconds_f64(0.5));
for bad in [json!({"missingFrames": "blank"}), json!({"startFrame": "x"}), json!({"startFrame": 1e300})] {
for bad in [json!({"startFrame": "x"}), json!({"startFrame": 1e300})] {
let mut p = bad.clone();
p["items"] = json!([item]);
assert!(s.execute("file.interpretFootage", p).is_err(), "{bad}");
@@ -170,10 +168,10 @@ fn replace_footage_and_reload_keep_sequences() {
let (name, f) = footage(&s, &item);
assert_eq!((name.as_str(), f.sequence.len()), ("shot_[0001-0005].png", 4));
// Reload finds a new frame and keeps the interpretation.
s.execute("file.interpretFootage", json!({"items": [item], "frameRate": 12, "missingFrames": "hold"})).unwrap();
s.execute("file.interpretFootage", json!({"items": [item], "frameRate": 12, "startFrame": 2})).unwrap();
std::fs::write(at(&dir, "shot_0003.png"), b"").unwrap();
s.execute("file.reloadFootage", json!({"items": [item]})).unwrap();
let (_, f) = footage(&s, &item);
assert_eq!((f.sequence.len(), f.frame_rate, f.missing_frames), (5, FrameRate::from_f64(12.0), MissingFrames::Hold));
assert_eq!(f.duration, FrameRate::from_f64(12.0).tick_of(5));
assert_eq!((f.sequence.len(), f.frame_rate, f.start_frame), (5, FrameRate::from_f64(12.0), Some(2)));
assert_eq!(f.duration, FrameRate::from_f64(12.0).tick_of(4));
}
+1 -1
View File
@@ -523,7 +523,7 @@ impl Inner {
let i = Self::frame_index(footage.frame_rate, t, footage.sequence_frames(), footage.loop_count);
match footage.sequence_file(i) {
Some(path) => Loc { key: key(path, 0), media_t: None },
// A gap in the numbering (Missing Frames ▸ Show Placeholder).
// A gap in the numbering: colour bars, as in After Effects.
None => Loc { key: key(PLACEHOLDER, ((footage.width as i64) << 32) | footage.height as i64), media_t: None },
}
}
+6 -9
View File
@@ -10,7 +10,7 @@ use std::sync::Arc;
use std::time::Instant;
use effectcraft_media::{MediaPool, probe};
use effectcraft_project::{AlphaMode, Footage, FootageKind, ItemId, MissingFrames};
use effectcraft_project::{AlphaMode, Footage, FootageKind, ItemId};
use effectcraft_raster::Image;
use effectcraft_render::FootageSource;
use effectcraft_time::{FrameRate, TICKS_PER_SECOND, Tick};
@@ -379,10 +379,10 @@ fn png_sequence_import() {
assert_eq!(*img, load_png(&first.with_file_name("seq_0004.png")));
}
/// A gap in a sequence's numbering shows colour bars (Missing Frames ▸ Show Placeholder), the
/// frame before it (Hold) or nothing at all (Skip: the files play back to back) (#297).
/// A gap in a sequence's numbering shows colour bars, as in After Effects; in Force
/// Alphabetical Order the files play back to back (#297).
#[test]
fn sequence_gaps_show_placeholders_hold_or_close_up() {
fn sequence_gaps_show_placeholders() {
let dir = fixtures().join(format!("gap-seq-{}", std::process::id()));
std::fs::create_dir_all(&dir).expect("mkdir");
// Frames 1, 2 and 4: frame 3 is missing. Each frame is a flat grey of its number.
@@ -393,8 +393,7 @@ fn sequence_gaps_show_placeholders_hold_or_close_up() {
grey(n).save(&p).expect("write png");
files.push(p.to_string_lossy().to_string());
}
let mut f =
Footage { kind: FootageKind::Sequence, sequence: files, missing_frames: MissingFrames::Placeholder, ..probe(dir.join("gap_001.png")).expect("probe") };
let mut f = Footage { kind: FootageKind::Sequence, sequence: files, ..probe(dir.join("gap_001.png")).expect("probe") };
f.sync_sequence_duration();
assert_eq!(f.duration, f.frame_rate.tick_of(4), "frames 1-4");
let pool = MediaPool::new();
@@ -407,9 +406,7 @@ fn sequence_gaps_show_placeholders_hold_or_close_up() {
assert_eq!(bars.get(0, 0), [0.75, 0.75, 0.75, 1.0]);
assert_eq!(bars.get(7, 3), [0.0, 0.0, 0.75, 1.0], "blue on the right");
assert_eq!(level(&at(&f, 3)), 200);
f.missing_frames = MissingFrames::Hold;
assert_eq!(level(&at(&f, 2)), 100, "holds frame 2");
f.missing_frames = MissingFrames::Skip;
f.alphabetical = true;
f.sync_sequence_duration();
assert_eq!(f.duration, f.frame_rate.tick_of(3));
assert_eq!(level(&at(&f, 2)), 200, "frame 4 follows frame 2");
+6 -5
View File
@@ -22,7 +22,6 @@ pub use effectcraft_color::ColorSpace;
use effectcraft_color::{BlendMode, Label};
use effectcraft_time::{FrameRate, Tick};
pub use props::{Expression, FeatherFalloff, GroupKind, MaskMode, MaskMotionBlur, Node, ParamUi, PropGroup, Property, Uid, parse_path};
pub use sequence::MissingFrames;
use serde::{Deserialize, Serialize};
pub use effectcraft_keyframe as keyframe;
@@ -965,9 +964,11 @@ pub struct Footage {
/// PDF / Illustrator footage: the page shown (0-based; File ▸ Import ▸ Page).
#[serde(default, skip_serializing_if = "is_default")]
pub page: u32,
/// Image sequences: Interpret Footage ▸ Missing Frames ([`sequence`]).
#[serde(default, skip_serializing_if = "is_default")]
pub missing_frames: MissingFrames,
/// Image sequences imported with Force Alphabetical Order: the files play one after another
/// and their numbering doesn't count (otherwise a gap in it shows a placeholder, as in After
/// 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).
#[serde(default, skip_serializing_if = "Option::is_none")]
@@ -1004,7 +1005,7 @@ impl Default for Footage {
data: None,
layer: None,
page: 0,
missing_frames: MissingFrames::Skip,
alphabetical: false,
start_frame: None,
}
}
+34 -74
View File
@@ -3,10 +3,9 @@
//!
//! 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, and **Missing Frames**
//! ([`Footage::missing_frames`]) says what a gap in the numbering shows.
use serde::{Deserialize, Serialize};
//! 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.
use crate::{Footage, FootageKind};
@@ -14,45 +13,6 @@ use crate::{Footage, FootageKind};
/// naming accident, such as dates in file names, not footage).
pub const MAX_SEQUENCE_FRAMES: i64 = 10_000_000;
/// Interpret Footage ▸ Missing Frames: what an image sequence shows where its numbering skips a
/// number.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum MissingFrames {
/// The files play one after another and the gaps close up (and a sequence imported with
/// Force Alphabetical Order, whose numbering doesn't count).
#[default]
Skip,
/// A missing frame shows colour bars, as in After Effects.
Placeholder,
/// A missing frame shows the frame before it.
Hold,
}
impl MissingFrames {
pub const ALL: [MissingFrames; 3] = [MissingFrames::Placeholder, MissingFrames::Hold, MissingFrames::Skip];
/// The command parameter value.
pub fn id(self) -> &'static str {
match self {
MissingFrames::Skip => "skip",
MissingFrames::Placeholder => "placeholder",
MissingFrames::Hold => "hold",
}
}
pub fn label(self) -> &'static str {
match self {
MissingFrames::Skip => "Skip (close the gaps)",
MissingFrames::Placeholder => "Show Placeholder (color bars)",
MissingFrames::Hold => "Hold Previous Frame",
}
}
pub fn parse(s: &str) -> Option<MissingFrames> {
MissingFrames::ALL.into_iter().find(|m| m.id().eq_ignore_ascii_case(s.trim()))
}
}
/// Split a file stem into (prefix, frame number digits): `shot_0012` → (`shot_`, `0012`).
/// `None` when it doesn't end in digits.
pub fn split_frame_number(stem: &str) -> Option<(&str, &str)> {
@@ -108,9 +68,9 @@ impl Footage {
self.sequence.get(i).and_then(|p| frame_number(p))
}
/// The numbering is used: Placeholder / Hold and a numbered first file.
/// The numbering is used: a numbered first file, not in Force Alphabetical Order.
fn numbered(&self) -> Option<i64> {
(self.missing_frames != MissingFrames::Skip).then(|| self.file_number(0)).flatten()
(!self.alphabetical).then(|| self.file_number(0)).flatten()
}
/// Index of the first file numbered `n` or later.
@@ -124,9 +84,9 @@ impl Footage {
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 (with
/// Placeholder / Hold), or its files from Start Frame on (Skip). At least 1; 0 for other
/// footage.
/// 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.
pub fn sequence_frames(&self) -> i64 {
if !self.is_file_sequence() {
return 0;
@@ -158,15 +118,11 @@ impl Footage {
};
let n = self.start_frame.unwrap_or(first).saturating_add(i);
let k = self.first_file_from(n);
match self.sequence.get(k) {
Some(p) if frame_number(p) == Some(n) => Some(p),
_ if self.missing_frames == MissingFrames::Hold => self.sequence.get(k.saturating_sub(1)).map(String::as_str),
_ => None,
}
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, Missing Frames or Start Frame changed).
/// frame rate or Start Frame changed).
pub fn sync_sequence_duration(&mut self) {
if self.is_file_sequence() {
self.duration = self.frame_rate.tick_of(self.sequence_frames());
@@ -178,13 +134,8 @@ impl Footage {
mod tests {
use super::*;
fn seq(numbers: &[i64], missing: MissingFrames) -> Footage {
Footage {
kind: FootageKind::Sequence,
sequence: numbers.iter().map(|n| format!("C:\\shots\\a_{n:04}.png")).collect(),
missing_frames: missing,
..Default::default()
}
fn seq(numbers: &[i64]) -> Footage {
Footage { kind: FootageKind::Sequence, sequence: numbers.iter().map(|n| format!("C:\\shots\\a_{n:04}.png")).collect(), ..Default::default() }
}
#[test]
@@ -198,53 +149,62 @@ mod tests {
let files: Vec<String> = ["/s/fx_0998.png", "/s/fx_1002.png"].map(String::from).to_vec();
assert_eq!(sequence_name(&files).as_deref(), Some("fx_[0998-1002].png"));
assert_eq!(sequence_name(&["/s/a.png".to_string()]), None);
assert_eq!(MissingFrames::parse("Hold"), Some(MissingFrames::Hold));
}
#[test]
fn missing_frames_map_frames_to_files() {
// Files 1, 2, 5: frames 3 and 4 are missing.
let f = seq(&[1, 2, 5], MissingFrames::Placeholder);
// Files 1, 2, 5: frames 3 and 4 are missing and show placeholders.
let f = seq(&[1, 2, 5]);
assert_eq!(f.sequence_frames(), 5);
let at = |f: &Footage, i| f.sequence_file(i).map(|p| frame_number(p).unwrap_or(-1));
assert_eq!((0..5).map(|i| at(&f, i)).collect::<Vec<_>>(), [Some(1), Some(2), None, None, Some(5)]);
let h = seq(&[1, 2, 5], MissingFrames::Hold);
assert_eq!((0..5).map(|i| at(&h, i)).collect::<Vec<_>>(), [Some(1), Some(2), Some(2), Some(2), Some(5)]);
let s = seq(&[1, 2, 5], MissingFrames::Skip);
// Force Alphabetical Order: the files play one after another.
let s = Footage { alphabetical: true, ..seq(&[1, 2, 5]) };
assert_eq!(s.sequence_frames(), 3);
assert_eq!((0..3).map(|i| at(&s, i)).collect::<Vec<_>>(), [Some(1), Some(2), Some(5)]);
assert_eq!(missing_frame_ranges(&f.sequence), [(3, 4)]);
}
#[test]
fn projects_saved_without_the_flag_show_placeholders() {
// Projects saved before #297 have no `alphabetical`: their gaps show placeholders, as in
// After Effects; only Force Alphabetical Order is saved.
let f = seq(&[1, 2, 5]);
let json = serde_json::to_value(&f).unwrap();
assert!(json.get("alphabetical").is_none(), "{json}");
let back: Footage = serde_json::from_value(json).unwrap();
assert_eq!((back.alphabetical, back.sequence_frames()), (false, 5));
let alpha = serde_json::to_value(Footage { alphabetical: true, ..seq(&[1, 2, 5]) }).unwrap();
assert_eq!(serde_json::from_value::<Footage>(alpha).unwrap().sequence_frames(), 3);
}
#[test]
fn start_frame_trims_or_pads_the_head() {
let at = |f: &Footage, i| f.sequence_file(i).map(|p| frame_number(p).unwrap_or(-1));
let mut f = seq(&[1001, 1002, 1003], MissingFrames::Placeholder);
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)));
f.missing_frames = MissingFrames::Hold;
assert_eq!(at(&f, 0), Some(1001), "nothing before the first file: hold it");
f.missing_frames = MissingFrames::Skip;
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.missing_frames = MissingFrames::Placeholder;
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.missing_frames = MissingFrames::Skip;
f.alphabetical = true;
assert_eq!(f.sequence_file(-1), None);
assert!(f.sequence_file(5).is_some());
}
#[test]
fn duration_follows_frames_and_rate() {
let mut f = seq(&[1, 2, 5], MissingFrames::Placeholder);
let mut f = seq(&[1, 2, 5]);
f.frame_rate = effectcraft_time::FrameRate::from_f64(10.0);
f.sync_sequence_duration();
assert!((f.duration.seconds() - 0.5).abs() < 1e-9);
+9 -23
View File
@@ -189,7 +189,7 @@ fn sequence_fields(app: &EffectcraftApp, runs: &[Vec<String>]) -> Vec<Field> {
Field::bool("sequence", &format!("{ext} Sequence"), true),
Field::bool("alphabetical", "Force alphabetical order", false),
Field::num("frameRate", "Frame rate (fps)", app.session.prefs.import.sequence_fps),
Field::note("after", "Change the frame rate, alpha, missing frames and start frame later with File ▸ Interpret Footage."),
Field::note("after", "Change the frame rate, alpha and start frame later with File ▸ Interpret Footage."),
]
}
@@ -393,22 +393,7 @@ pub fn open_form(app: &mut EffectcraftApp, id: &str, p: &Value) -> bool {
],
),
"file.interpretFootage" | "file.interpretProxy"
if !has(
p,
&[
"frameRate",
"alpha",
"loop",
"pixelAspect",
"colorProfile",
"fields",
"invertAlpha",
"matteColor",
"linearLight",
"missingFrames",
"startFrame",
],
) =>
if !has(p, &["frameRate", "alpha", "loop", "pixelAspect", "colorProfile", "fields", "invertAlpha", "matteColor", "linearLight", "startFrame"]) =>
{
let proxy = id == "file.interpretProxy";
let f = s.state.project_selection.first().and_then(|i| s.project.item(*i)).and_then(|it| match (&it.kind, &it.proxy) {
@@ -462,18 +447,19 @@ pub fn open_form(app: &mut EffectcraftApp, id: &str, p: &Value) -> bool {
),
Field::bool("linearLight", "Interpret As Linear Light", f.linear_light),
];
// Image sequences: what a gap in the numbering shows, and the first frame's number.
// Image sequences: their frames (missing ones show colour bars, as in After Effects)
// and the first frame's number.
if f.kind == effectcraft_engine::project::FootageKind::Sequence {
use effectcraft_engine::project::MissingFrames;
let at = fields.iter().position(|x| x.key == "frameRate").map_or(fields.len(), |i| i + 1);
let gaps = effectcraft_engine::sequence::missing_report(&f.sequence).unwrap_or_else(|| "no missing frames".into());
let options: Vec<(&str, Value)> = MissingFrames::ALL.iter().map(|m| (m.label(), json!(m.id()))).collect();
let sel = MissingFrames::ALL.iter().position(|m| *m == f.missing_frames).unwrap_or(0);
let gaps = match effectcraft_engine::sequence::missing_report(&f.sequence) {
_ if f.alphabetical => "files in alphabetical order".into(),
Some(gaps) => format!("{gaps} shown as color bars"),
None => "no missing frames".into(),
};
fields.splice(
at..at,
[
Field::note("sequenceInfo", &format!("Image sequence: {} files, {} frames; {gaps}.", f.sequence.len(), f.sequence_frames())),
Field::choice("missingFrames", "Missing Frames", &options, sel),
Field::num("startFrame", "Start Frame", f.first_frame_number() as f64),
],
);
+4 -2
View File
@@ -340,7 +340,8 @@ fn import_dialog_offers_the_image_sequence_option() {
}
/// #297: every frame of a sequence dropped on the window arrives as one image sequence (it used
/// to make one item per frame), and Interpret Footage shows its Missing Frames and Start Frame.
/// to make one item per frame), and Interpret Footage shows its Start Frame (missing frames
/// always show colour bars, as in After Effects: there is no Missing Frames choice).
#[test]
fn dropped_frames_import_as_one_sequence_with_sequence_interpretation() {
let (mut h, _) = harness();
@@ -358,8 +359,9 @@ fn dropped_frames_import_as_one_sequence_with_sequence_interpretation() {
let ctx = h.ctx.clone();
effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, "file.interpretFootage", json!({})).unwrap();
h.run_steps(2);
for id in ["form.field.missingFrames", "form.field.startFrame", "form.field.frameRate", "form.field.alpha"] {
for id in ["form.field.sequenceInfo", "form.field.startFrame", "form.field.frameRate", "form.field.alpha"] {
assert!(h.state().auto.find(id).is_some(), "{id}");
}
assert!(h.state().auto.find("form.field.missingFrames").is_none());
let _ = std::fs::remove_dir_all(&dir);
}