EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
engine: Replace Footage keeps a still a still (#2073)
Madhav Agarwala29eda38448e
diff --git a/crates/engine/src/cmd/file_more.rs b/crates/engine/src/cmd/file_more.rsindex c9d581581..f03096657 100644--- a/crates/engine/src/cmd/file_more.rs+++ b/crates/engine/src/cmd/file_more.rs@@ -878,8 +878,16 @@ fn replace_footage(s: &mut Session, p: &Value) -> Result<Value> {let path = str_p(p, "path").ok_or_else(|| bad("file.replaceFootage", "missing `path`"))?.to_string();let item = *items_p(s, p).first().ok_or_else(|| bad("file.replaceFootage", "select footage"))?;let importer = s.importer.clone().ok_or_else(|| EngineError::Other("media import is not available in this build".into()))?;- // A numbered still brings its image sequence, as on import (`sequence: false` for one frame).- let opts = SequenceOptions::from_params(p);+ // Replacing a still keeps it a still; replacing a sequence keeps bringing the new file's run.+ // `sequence`/`alphabetical` override that (#2073).+ let previous = match s.project.item(item).map(|it| &it.kind) {+ Some(ItemKind::Footage(f)) if f.kind == FootageKind::Sequence => (true, true, f.alphabetical),+ _ => (false, false, false),+ };+ let mut opts = SequenceOptions::from_params(p);+ if p.get("sequence").is_none() && p.get("alphabetical").is_none() {+ (opts.sequence, opts.folders, opts.alphabetical) = previous;+ }let src = crate::sequence::source_of(s.services.as_ref(), &path, opts);let f = crate::sequence::probe(importer.as_ref(), &src, s.sequence_rate()).map_err(|e| EngineError::Other(format!("{path}: {e}")))?;let name = src.name();@@ -1093,7 +1101,7 @@ pub fn specs() -> Vec<CommandSpec> {"File...",["File", "Replace Footage"],Some("Cmd+H"),- "{path, item?, sequence?: bool (default true: a numbered still brings its image sequence), alphabetical?: bool}",+ "{path, item?, sequence?: bool (a numbered still brings its image sequence; default: the item keeps its kind, so a still stays a still and a sequence stays a sequence), alphabetical?: bool}",has_footage_selection,replace_footage),diff --git a/crates/engine/src/tests/sequence.rs b/crates/engine/src/tests/sequence.rsindex 3e81961ce..d99a600d3 100644--- a/crates/engine/src/tests/sequence.rs+++ b/crates/engine/src/tests/sequence.rs@@ -181,14 +181,30 @@ fn interpret_footage_start_timecode_relabels_source_time() {}#[test]-fn replace_footage_and_reload_keep_sequences() {+fn replace_footage_keeps_a_still_a_still() {let dir = folder(&RUN);let mut s = session();let item = s.execute("file.import", json!({"paths": [at(&dir, "shot_0001.png")], "sequence": false})).unwrap()["items"][0].clone();s.state.project_selection = vec![ItemId(item.as_u64().unwrap())];+ // Replacing with a numbered still does not silently turn the item into a sequence (#2073).+ s.execute("file.replaceFootage", json!({"path": at(&dir, "shot_0004.png")})).unwrap();+ let (name, f) = footage(&s, &item);+ assert_eq!((name.as_str(), f.kind), ("shot_0004.png", FootageKind::Still));+ // Asking for the run still brings it.+ s.execute("file.replaceFootage", json!({"path": at(&dir, "shot_0004.png"), "sequence": true})).unwrap();+ let (name, f) = footage(&s, &item);+ assert_eq!((name.as_str(), f.kind, f.sequence.len()), ("shot_[0001-0005].png", FootageKind::Sequence, 4));+}++#[test]+fn replace_footage_and_reload_keep_sequences() {+ let dir = folder(&RUN);+ let mut s = session();+ let item = s.execute("file.import", json!({"paths": [at(&dir, "shot_0001.png")], "sequence": true})).unwrap()["items"][0].clone();+ s.state.project_selection = vec![ItemId(item.as_u64().unwrap())];s.execute("file.replaceFootage", json!({"path": at(&dir, "shot_0004.png")})).unwrap();let (name, f) = footage(&s, &item);- assert_eq!((name.as_str(), f.sequence.len()), ("shot_[0001-0005].png", 4));+ assert_eq!((name.as_str(), f.kind, f.sequence.len()), ("shot_[0001-0005].png", FootageKind::Sequence, 4));// Reload finds a new frame and keeps the interpretation.s.execute("file.interpretFootage", json!({"items": [item], "frameRate": 12, "startTimecode": 2})).unwrap();std::fs::write(at(&dir, "shot_0003.png"), b"").unwrap();diff --git a/docs/footage.md b/docs/footage.mdindex bd99cbeb2..f23bcdcc7 100644--- a/docs/footage.md+++ b/docs/footage.md@@ -129,9 +129,10 @@ including files overwritten at the same path and byte size.and 3D models are not sources, and a composition can't be nested in itself. Alt-dragging onto alayer is one layer at a time, as in After Effects.Agents: `layer.replaceSource {"item": id, "layers": [ids]}`.-- **File ▸ Replace Footage ▸ File…** (Ctrl+H) points the item at another file. Pick a numbered- file to replace it with that file's whole sequence (`file.replaceFootage {"path": …,- "sequence": false}` for one frame).+- **File ▸ Replace Footage ▸ File…** (Ctrl+H) points the item at another file. A still stays a+ still, and a sequence item keeps bringing the new numbered file's run; pass+ `sequence: true` to bring a numbered still's whole run (`file.replaceFootage {"path": …,+ "sequence": true}`), or `sequence: false` for one frame.- **Replace with Precomposition (used N times)**, right-clicking a footage item or solid in theProject panel, puts the item in a new composition of its size,pixel aspect and frame rate, in the same folder, and switches every layer in every composition