Footage cache (#3271): channel selection is static, and only the channels picked are read

The parameters that pick which channels or Cryptomatte layer an effect reads (EXtractoR's Red/Green/Blue/Alpha, Cryptomatte's Layer and Layer Name, 3D Channel Extract's 3D Channel, ID Matte's Aux. Channel and Use Coverage, IDentifier's Channel Type) are static, as in After Effects where they have no stopwatch: no keyframes, no expression (prop.addKey, prop.toggleKey, prop.toggleAnimation and prop.setExpression refuse; prop.set changes the value). A document or an import that animated one keeps its first value and says so (a toast on open, a loss on .aep import). With that, what a frame reads is known from the values alone: the 'all channels' fallbacks for moving parameters and for effects that don't declare are gone (every channel effect declares; a test holds them to it), and a layer whose effects read no channels asks for none. Tests: the parameters refuse keys and expressions and the need is exactly the channel picked; a keyed channel selection opens static with its first value and is reported (both fail on the old code); the migration keeps the first key's value.
This commit is contained in:
vangel76 committed 2026-11-08 13:24:22 +01:00
1 parent f21b7d2a8f
commit c3464f640f
12 files changed
+231 -29

No files matched your search

+3 -4
View File
@@ -522,11 +522,10 @@ impl CryptoProbe {
let params = effectcraft_effects::flatten_params(g, &mut |pr| ctx.value(layer, pr));
// The channels the layer's effects read and this effect's (it may be switched off).
let own = match &g.kind {
effectcraft_project::GroupKind::Effect { effect } => effectcraft_effects::aux_needs(effect, &params),
_ => None,
effectcraft_project::GroupKind::Effect { effect } => effectcraft_effects::aux_need(effect, &params),
_ => effectcraft_raster::channels3d::AuxNeed::Lookups(vec![]),
};
let need =
r.layer_aux_need(&ctx, layer).union(own.map_or(effectcraft_raster::channels3d::AuxNeed::All, effectcraft_raster::channels3d::AuxNeed::Lookups));
let need = r.layer_aux_need(&ctx, layer).union(own);
let aux = r.layer_aux_with(&ctx, layer, &need).ok_or(NO_CRYPTO)?;
if !live() {
return Ok(None);
+13 -2
View File
@@ -461,7 +461,7 @@ fn toggle_key_selected(s: &mut Session, p: &Value) -> Result<Value> {
let want = added.as_bool().unwrap_or(true);
for (olid, ouid) in twins {
let _ = with_prop(s, "Add/Remove Keyframe", None, cid, olid, ouid, |pr, lt| {
if key_at(&pr.keys, lt).is_some() != want {
if !pr.static_only && key_at(&pr.keys, lt).is_some() != want {
toggle_key_at(pr, lt);
}
Ok(())
@@ -589,6 +589,9 @@ fn add_key(s: &mut Session, p: &Value) -> Result<Value> {
let at = snapped_key_time(s, cid, lid, p, "prop.addKey")?;
let value = p.get("value").cloned();
let count = with_prop(s, "Add Keyframe", None, cid, lid, uid, |pr, lt| {
if pr.static_only {
return Err(bad("prop.addKey", "this property can't be animated"));
}
let t = at.unwrap_or(lt);
let cur = pr.value_at(t);
let v = match &value {
@@ -611,7 +614,12 @@ fn add_key(s: &mut Session, p: &Value) -> Result<Value> {
fn toggle_key(s: &mut Session, p: &Value) -> Result<Value> {
let (cid, lid, uid) = prop_ref(s, p, "prop.toggleKey")?;
with_prop(s, "Add/Remove Keyframe", None, cid, lid, uid, |pr, lt| Ok(json!(toggle_key_at(pr, lt))))
with_prop(s, "Add/Remove Keyframe", None, cid, lid, uid, |pr, lt| {
if pr.static_only {
return Err(bad("prop.toggleKey", "this property can't be animated"));
}
Ok(json!(toggle_key_at(pr, lt)))
})
}
/// Add a keyframe at layer time `lt` (true), or remove the one there (false).
@@ -723,6 +731,9 @@ fn set_expr(s: &mut Session, p: &Value) -> Result<Value> {
let mut changed_types = vec![];
for (((cid, lid, uid), def), time) in targets.iter().zip(&defs).zip(&times) {
let pr = layer_mut(proj, *cid, *lid)?.props.find_mut(*uid).ok_or_else(|| bad(C, "property vanished"))?;
if pr.static_only && text.as_deref().is_some_and(|t| !t.trim().is_empty()) {
return Err(bad(C, format!("{} can't have an expression", pr.name)));
}
apply_expr(pr, &text, enabled, def);
out.push(json!(pr.expr.as_ref().map(|e| e.text.clone())));
if pr.match_id == "type" {
+16 -3
View File
@@ -208,7 +208,7 @@ impl Session {
self.drop_tasks();
self.script_ui.project_epoch = self.script_ui.project_epoch.wrapping_add(1);
p.fix_next_id();
upgrade_effects(&mut p);
let lost = upgrade_effects(&mut p);
// The media layer keys decoded frames by path: files of the new project may have changed
// since an earlier project decoded them (#1070).
for it in p.items.values() {
@@ -226,6 +226,12 @@ impl Session {
self.path = path;
self.bump();
self.mark_saved();
// (channel selection can't be animated, as in After Effects: a document that animated it
// keeps its first value; said once, not as an error)
if !lost.is_empty() {
log::warn!("channel selection is static: keyframes or expressions dropped on {}", lost.join("; "));
self.toast(format!("Channel selection can't be animated: kept the first value of {}", lost.join(", ")));
}
let first = self.project.comps().next().map(|(id, _)| *id);
if let Some(c) = first {
self.open_comp(c);
@@ -239,8 +245,11 @@ impl Session {
/// [`effectcraft_project::SCHEMA_EFFECT_SPACE`] into effect space
/// ([`effectcraft_effects::migrate::to_effect_space`]). Shape path operations get the
/// properties added since ([`effectcraft_project::build::upgrade_shape_contents`]). Stamps the
/// current schema.
pub fn upgrade_effects(p: &mut Project) {
/// current schema. Channel-selection parameters are made static
/// ([`effectcraft_effects::migrate::static_channel_params`]); returns what lost its animation
/// (`Layer: Effect: Parameter`).
pub fn upgrade_effects(p: &mut Project) -> Vec<String> {
let mut lost = vec![];
let to_effect_space = p.schema < effectcraft_project::SCHEMA_EFFECT_SPACE;
// Effect bounds per layer: (size, top-left in layer coordinates).
let mut bounds = std::collections::HashMap::new();
@@ -274,10 +283,14 @@ pub fn upgrade_effects(p: &mut Project) {
if to_effect_space {
effectcraft_effects::migrate::to_effect_space(spec, g, size, d, &clone_d);
}
for name in effectcraft_effects::migrate::static_channel_params(spec, g) {
lost.push(format!("{}: {}: {name}", l.name, g.name));
}
}
}
}
}
p.next_id = next;
p.schema = effectcraft_project::SCHEMA_VERSION;
lost
}
+11 -9
View File
@@ -197,9 +197,8 @@ impl Session {
/// What the effects of [`aux_footage`]'s layers read of each file's channels (#3271), by
/// [`effectcraft_project::Footage::path`], sorted: the union of what each enabled effect reading
/// them declares ([`effectcraft_effects::aux_needs`]) with its parameters' values. An effect that
/// doesn't declare, or whose parameters change over time (keyframes, an expression), reads all
/// channels. Several layers of one file add up.
/// them declares ([`effectcraft_effects::aux_needs`]) with its parameters' values (channel
/// selection is static, as in After Effects). Several layers of one file add up.
pub(crate) fn aux_needs(project: &effectcraft_project::Project) -> Vec<(String, effectcraft_raster::channels3d::AuxNeed)> {
use effectcraft_project::{GroupKind, ItemKind, LayerSource};
use effectcraft_raster::channels3d::AuxNeed;
@@ -215,12 +214,15 @@ pub(crate) fn aux_needs(project: &effectcraft_project::Project) -> Vec<(String,
if !effectcraft_effects::reads_aux(effect) {
continue;
}
let need = if commands::moves(g, None) {
AuxNeed::All
} else {
let params = effectcraft_effects::flatten_params(g, &mut |p| p.value.clone());
effectcraft_effects::aux_needs(effect, &params).map_or(AuxNeed::All, AuxNeed::Lookups)
};
// Channel selection is static (as in After Effects): the values say what is read. A
// parameter that moves anyway (it can't, see `static_channel_params`) is read at its
// static value.
if commands::moves(g, None) {
static SAID: std::sync::Once = std::sync::Once::new();
SAID.call_once(|| log::warn!("an effect reading footage channels has animated parameters; its channels are read at their static values"));
}
let params = effectcraft_effects::flatten_params(g, &mut |p| p.value.clone());
let need = effectcraft_effects::aux_need(effect, &params);
let merged = match out.remove(&f.path) {
Some(e) => e.union(need),
None => need,
+71
View File
@@ -18,6 +18,7 @@ use crate::render::{FootageSource, RenderOpts};
struct Recorder {
sets: Mutex<Vec<Vec<String>>>,
at_first_frame: Mutex<Option<Option<Vec<String>>>>,
needs: Mutex<Vec<(String, effectcraft_raster::channels3d::AuxNeed)>>,
}
impl Recorder {
@@ -37,6 +38,9 @@ impl FootageSource for Recorder {
fn set_aux_footage(&self, paths: &[String]) {
self.sets.lock().unwrap().push(paths.to_vec());
}
fn set_aux_needs(&self, needs: &[(String, effectcraft_raster::channels3d::AuxNeed)]) {
*self.needs.lock().unwrap() = needs.to_vec();
}
}
struct Probe;
@@ -198,3 +202,70 @@ fn a_watch_folder_render_gives_the_host_set_back() {
s.execute("file.watchFolder", json!({"stop": true})).unwrap();
let _ = std::fs::remove_dir_all(&dir);
}
/// #3271: the parameters that pick the channels an effect reads can't be animated, as in After
/// Effects (no stopwatch there either): a keyframe or an expression is refused, the value still
/// changes; what a frame reads is exactly the channels picked.
#[test]
fn channel_selection_is_static_and_says_what_is_read() {
use effectcraft_raster::channels3d::{AuxLookup, AuxNeed};
let rec = Arc::new(Recorder::default());
let mut s = session(&rec);
let item = import(&mut s, "/renders/static.exr");
let l = add_layer(&mut s, &item);
s.execute_checked("effect.apply", json!({"effect": "EXtractoR", "layers": [l]})).unwrap();
let red = "effects/#1/red";
let prop = |s: &Session, path: &str| {
let c = s.active_comp().unwrap();
c.layer(effectcraft_project::LayerId(l)).unwrap().props.prop(path).unwrap().clone()
};
assert!(prop(&s, red).static_only, "no stopwatch");
assert!(s.execute_checked("prop.addKey", json!({"layer": l, "path": red})).is_err(), "no keyframe");
assert!(s.execute_checked("prop.toggleKey", json!({"layer": l, "path": red})).is_err(), "no keyframe");
assert!(s.execute_checked("prop.toggleAnimation", json!({"layer": l, "path": red})).is_err(), "no stopwatch");
assert!(s.execute_checked("prop.setExpression", json!({"layer": l, "path": red, "expression": "'Z'"})).is_err(), "no expression");
assert!(prop(&s, red).keys.is_empty() && prop(&s, red).expr.is_none());
// The value changes; the channels read are exactly those picked.
s.execute_checked("prop.set", json!({"layer": l, "path": red, "value": "Z"})).unwrap();
for c in ["green", "blue", "alpha"] {
s.execute_checked("prop.set", json!({"layer": l, "path": format!("effects/#1/{c}"), "value": ""})).unwrap();
}
assert_eq!(prop(&s, red).value, effectcraft_keyframe::Value::Str("Z".into()));
let needs = rec.needs.lock().unwrap().clone();
assert_eq!(needs, [("/renders/static.exr".to_string(), AuxNeed::Lookups(vec![AuxLookup::Name("Z".into())]))]);
}
/// #3271: a document that animated a channel selection (it can't come from After Effects, nor
/// from EffectCraft now) opens with the first key's value as the static one, its keys and
/// expression dropped, and says so.
#[test]
fn a_keyed_channel_selection_opens_static() {
use effectcraft_keyframe::{Keyframe, Value as K};
let rec = Arc::new(Recorder::default());
let mut s = session(&rec);
let item = import(&mut s, "/renders/keyed.exr");
let l = add_layer(&mut s, &item);
s.execute_checked("effect.apply", json!({"effect": "EXtractoR", "layers": [l]})).unwrap();
let cid = s.active_comp_id().unwrap();
{
let p = Arc::make_mut(&mut s.project);
let pr = p.comp_mut(cid).unwrap().layer_mut(effectcraft_project::LayerId(l)).unwrap().props.prop_mut("effects/#1/red").unwrap();
// (as a document from before)
pr.static_only = false;
pr.keys = vec![Keyframe::new(Tick::ZERO, K::Str("Z".into())), Keyframe::new(Tick::from_seconds_f64(1.0), K::Str("N.X".into()))];
}
let dir = std::env::temp_dir().join(format!("ec-3271-static-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let path = dir.join("keyed.ecproj");
s.execute_checked("file.saveAs", json!({"path": path.to_string_lossy()})).unwrap();
let mut o = session(&rec);
o.drain_events();
o.execute_checked("file.open", json!({"path": path.to_string_lossy()})).unwrap();
let c = o.active_comp().unwrap();
let pr = c.layer(effectcraft_project::LayerId(l)).unwrap().props.prop("effects/#1/red").unwrap();
assert!(pr.static_only && pr.keys.is_empty() && pr.expr.is_none());
assert_eq!(pr.value, K::Str("Z".into()), "the first key's value");
let said = o.drain_events().into_iter().any(|e| matches!(e, crate::Event::Toast { message, .. } if message.contains("Channel selection")));
assert!(said, "the loss is reported");
let _ = std::fs::remove_dir_all(&dir);
}