Import: image sequences with a Sequence option, ranges, folders and missing frames (#297)
Image sequences were found only by the desktop media prober: one picked numbered still brought its whole run, with no way to import just that frame, picking every frame made one sequence item per frame, the browser couldn't make sequences at all, and a gap in the numbering closed up silently. The engine now groups numbered stills itself (engine/src/sequence.rs): one picked file brings its run from its folder, several picked files of one run import as that range, a picked or dropped folder imports its files with each run as a sequence, and Force Alphabetical Order takes every image of that type in the folder by name. `file.import` takes `sequence` (default on), `alphabetical` and `frameRate`; Replace Footage, Reload, proxies and render outputs probe the same way. The media layer probes one file; the browser lists its file table for the run and registers every frame with its media pool. File > Import > File... asks, like After Effects' "PNG Sequence" checkbox, whether picked numbered stills import as a sequence, with Force Alphabetical Order and the frame rate. Sequences are named `shot_[0001-0250].png`. Interpret Footage gains Missing Frames (Show Placeholder, colour bars as in After Effects, the new default; Hold Previous Frame; Skip) and Start Frame (the frame number at the footage's first frame: trims or pads the head). Saved projects keep Skip, so their sequences play as before. Form notes keep a readable width and the form fits its rows, so OK stays in view. docs/footage.md explains importing footage and sequences. Test: tests_sequence (engine: run, picked range, every frame, Sequence off, folder, alphabetical, Interpret Footage Missing Frames / Start Frame, Replace Footage and Reload), project sequence unit tests, sequence_gaps_show_placeholders_hold_or_close_up (media), import_dialog_offers_the_image_sequence_option and dropped_frames_import_as_one_sequence_with_sequence_interpretation (UI). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
4aaadd0ed3
commit
50c9549529
@@ -23,7 +23,7 @@ mod pool;
|
||||
mod probe;
|
||||
|
||||
pub use pool::{DEFAULT_BUDGET, MediaPool, PoolStats};
|
||||
pub use probe::{DEFAULT_SEQUENCE_RATE, probe, probe_bytes, probe_model, probe_single, sequence_files};
|
||||
pub use probe::{DEFAULT_SEQUENCE_RATE, probe, probe_bytes, probe_model};
|
||||
|
||||
/// Errors from probing or decoding footage.
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
||||
@@ -16,6 +16,23 @@ use crate::{MediaError, Result};
|
||||
/// Default frame-cache budget: 1 GiB of decoded frames.
|
||||
pub const DEFAULT_BUDGET: usize = 1 << 30;
|
||||
|
||||
/// The cache path of a missing image-sequence frame (no file can have this name).
|
||||
const PLACEHOLDER: &str = "\0missing frame";
|
||||
|
||||
/// What a missing image-sequence frame shows: 75 % colour bars (white, yellow, cyan, green,
|
||||
/// magenta, red, blue), the usual "no picture here" frame.
|
||||
fn colour_bars(w: u32, h: u32) -> Image {
|
||||
const BARS: [[f32; 3]; 7] = [[1.0, 1.0, 1.0], [1.0, 1.0, 0.0], [0.0, 1.0, 1.0], [0.0, 1.0, 0.0], [1.0, 0.0, 1.0], [1.0, 0.0, 0.0], [0.0, 0.0, 1.0]];
|
||||
let (w, h) = (w.clamp(1, 16_384), h.clamp(1, 16_384));
|
||||
let row: Vec<Px> = (0..w)
|
||||
.map(|x| {
|
||||
let c = BARS.get((x as usize * BARS.len()) / w as usize).copied().unwrap_or([0.0; 3]);
|
||||
[c[0] * 0.75, c[1] * 0.75, c[2] * 0.75, 1.0]
|
||||
})
|
||||
.collect();
|
||||
Image { width: w, height: h, data: row.repeat(h as usize) }
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
struct Key {
|
||||
path: Arc<str>,
|
||||
@@ -503,8 +520,12 @@ impl Inner {
|
||||
let key = |path: &str, frame| Key { path: path.into(), frame, alpha, matte };
|
||||
match footage.kind {
|
||||
FootageKind::Sequence if !footage.sequence.is_empty() => {
|
||||
let i = Self::frame_index(footage.frame_rate, t, footage.sequence.len() as i64, footage.loop_count);
|
||||
Loc { key: key(&footage.sequence[i as usize], 0), media_t: None }
|
||||
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).
|
||||
None => Loc { key: key(PLACEHOLDER, ((footage.width as i64) << 32) | footage.height as i64), media_t: None },
|
||||
}
|
||||
}
|
||||
// A layer of a layered still is keyed by its layer index and size mode (smart objects
|
||||
// by their embedded file; PDF pages by their number).
|
||||
@@ -589,6 +610,7 @@ impl Inner {
|
||||
let op = AlphaOp::new(footage.alpha, footage.premul_color);
|
||||
let path = &loc.key.path;
|
||||
match loc.media_t {
|
||||
None if &**path == PLACEHOLDER => Ok(colour_bars(footage.width, footage.height)),
|
||||
None => {
|
||||
let bytes = self.read(path)?;
|
||||
if let Some(img) = crate::layered::decode(path, &bytes, footage, op)? {
|
||||
|
||||
@@ -1,31 +1,19 @@
|
||||
//! Probing: describe a file as an [`effectcraft_project::Footage`].
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use effectcraft_project::{AlphaMode, Footage, FootageKind};
|
||||
use effectcraft_time::{FrameRate, Tick};
|
||||
|
||||
use crate::{MediaError, Result, STILL_EXTENSIONS, ext_of, rate_from_fc};
|
||||
use crate::{MediaError, Result, ext_of, rate_from_fc};
|
||||
|
||||
/// Frame rate given to image sequences on import (After Effects' default preference).
|
||||
pub const DEFAULT_SEQUENCE_RATE: FrameRate = FrameRate::FPS_30;
|
||||
|
||||
/// Probe a file. Stills whose name ends in a frame number (`shot_0001.png`) with at least one
|
||||
/// numbered sibling are imported as an image sequence; use [`probe_single`] to import one frame.
|
||||
/// Probe one file. Image sequences are made by the engine, which groups numbered stills
|
||||
/// (`effectcraft_engine::sequence`) and probes their first frame here.
|
||||
pub fn probe(path: impl AsRef<Path>) -> Result<Footage> {
|
||||
let path = path.as_ref();
|
||||
if STILL_EXTENSIONS.contains(&ext_of(path).as_str()) {
|
||||
let files = sequence_files(path);
|
||||
if files.len() >= 2 {
|
||||
return probe_sequence(&files);
|
||||
}
|
||||
}
|
||||
probe_single(path)
|
||||
}
|
||||
|
||||
/// Probe a file without image-sequence detection.
|
||||
pub fn probe_single(path: impl AsRef<Path>) -> Result<Footage> {
|
||||
let path = path.as_ref();
|
||||
let bytes = std::fs::read(path).map_err(|e| MediaError::Io(format!("{}: {e}", path.display())))?;
|
||||
if crate::MODEL_EXTENSIONS.contains(&ext_of(path).as_str()) {
|
||||
@@ -176,59 +164,3 @@ fn probe_still_bytes(path: &str, bytes: &[u8], fmt: image::ImageFormat) -> Resul
|
||||
};
|
||||
Ok(still_footage(path, w, h, fmt, has_alpha))
|
||||
}
|
||||
|
||||
fn probe_sequence(files: &[PathBuf]) -> Result<Footage> {
|
||||
let first = &files[0];
|
||||
let mut f = probe_single(first)?;
|
||||
f.kind = FootageKind::Sequence;
|
||||
f.frame_rate = DEFAULT_SEQUENCE_RATE;
|
||||
f.duration = DEFAULT_SEQUENCE_RATE.tick_of(files.len() as i64);
|
||||
f.sequence = files.iter().map(|p| p.to_string_lossy().to_string()).collect();
|
||||
Ok(f)
|
||||
}
|
||||
|
||||
/// Split a file stem into (prefix, frame number digits). `None` when it does not end in digits.
|
||||
fn split_number(stem: &str) -> Option<(&str, &str)> {
|
||||
let digits = stem.bytes().rev().take_while(u8::is_ascii_digit).count();
|
||||
(digits > 0).then(|| stem.split_at(stem.len() - digits))
|
||||
}
|
||||
|
||||
/// The numbered files of the image sequence `path` belongs to (sorted by frame number; empty when
|
||||
/// the name has no frame number). Siblings must share the prefix and extension.
|
||||
pub fn sequence_files(path: impl AsRef<Path>) -> Vec<PathBuf> {
|
||||
let path = path.as_ref();
|
||||
let ext = ext_of(path);
|
||||
let Some(stem) = path.file_stem().and_then(|s| s.to_str()) else { return Vec::new() };
|
||||
let Some((prefix, _)) = split_number(stem) else { return Vec::new() };
|
||||
let dir = path.parent().filter(|d| !d.as_os_str().is_empty()).unwrap_or(Path::new("."));
|
||||
let Ok(rd) = std::fs::read_dir(dir) else { return Vec::new() };
|
||||
let mut out: Vec<(u64, PathBuf)> = rd
|
||||
.filter_map(|e| e.ok())
|
||||
.filter_map(|e| {
|
||||
let p = e.path();
|
||||
if ext_of(&p) != ext || !p.is_file() {
|
||||
return None;
|
||||
}
|
||||
let s = p.file_stem()?.to_str()?;
|
||||
let (pre, num) = split_number(s)?;
|
||||
if pre != prefix {
|
||||
return None;
|
||||
}
|
||||
Some((num.parse().ok()?, p))
|
||||
})
|
||||
.collect();
|
||||
out.sort();
|
||||
out.into_iter().map(|(_, p)| p).collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn split_numbers() {
|
||||
assert_eq!(split_number("shot_0012"), Some(("shot_", "0012")));
|
||||
assert_eq!(split_number("shot"), None);
|
||||
assert_eq!(split_number("v2_10"), Some(("v2_", "10")));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user