Merge upstream/main into cache-defaults-3298

This commit is contained in:
vangel76 committed 2026-11-12 12:36:34 +01:00
commit dcd46af227
155 files changed
+6214 -17309

No files matched your search

+1
View File
@@ -1,4 +1,5 @@
pub mod camera_track;
pub(crate) mod frames_key;
pub mod mask_track;
pub mod models;
pub mod roto;
+14 -4
View File
@@ -26,9 +26,10 @@ use effectcraft_track::camtrack::linalg::{self, Similarity, V3};
use effectcraft_track::camtrack::{AnalyzeOpts, CameraSolve, CameraTracks, SolveSettings, Target, TrackAnalyzer};
use serde::Serialize;
use crate::analysis::frames_key::{self, signature};
use crate::offload::JobKind;
use crate::tracking::lock;
use crate::warp::{analysis_times, signature};
use crate::warp::analysis_times;
use crate::{Event, Session};
/// Live analysis progress (serde for agents / the control channel).
@@ -124,8 +125,17 @@ fn str_of(g: &PropGroup, m: &str) -> String {
/// What a tracker's tracks are made from: the layer's frames and Detailed Analysis.
fn tracks_key(project: &Project, cid: ItemId, l: &Layer, g: &PropGroup) -> String {
tracks_key_of(signature(project, cid, l), g)
}
fn tracks_key_of(signature: String, g: &PropGroup) -> String {
let detailed = effectcraft_effects::warp_stab::param(&static_params(g), "advanced/detailedAnalysis").is_some_and(Value::as_bool);
format!("{}{}", signature(project, cid, l), if detailed { "+detailed" } else { "" })
format!("{signature}{}", if detailed { "+detailed" } else { "" })
}
/// Whether the tracker's saved tracks are made from the layer's current frames and settings.
fn tracks_match(project: &Project, cid: ItemId, l: &Layer, g: &PropGroup) -> bool {
frames_key::key_matches(project, cid, l, &str_of(g, TRACKS_KEY), |s, _| tracks_key_of(s, g))
}
/// Parameters of an instance from static values (the tracker's settings are not animated).
@@ -165,7 +175,7 @@ pub(crate) fn invalidate(before: &Project, after: &mut Project) -> Vec<(ItemId,
let old_layer = before.comp(*cid).and_then(|bc| bc.layer(l.id));
for g in fx.groups().filter(|g| is_tracker(g)) {
let tracked = !str_of(g, TRACKS).is_empty();
if tracked && str_of(g, TRACKS_KEY) != tracks_key(after, *cid, l, g) {
if tracked && !tracks_match(after, *cid, l, g) {
clears.push((*cid, l.id, g.uid, true));
todo.push((*cid, l.id, g.uid));
} else if tracked && str_of(g, SOLVE_KEY) != ct::solve_key(&ct::settings(&static_params(g))) {
@@ -325,7 +335,7 @@ impl Session {
let key = tracks_key(&self.project, comp, l, g);
let settings = ct::settings(&params);
let solve_key = ct::solve_key(&settings);
let tracks = ct::tracks(&params).filter(|_| str_of(g, TRACKS_KEY) == key);
let tracks = ct::tracks(&params).filter(|_| tracks_match(&self.project, comp, l, g));
let n = times.len();
let work = CamWork {
project: self.project.clone(),
+545
View File
@@ -0,0 +1,545 @@
//! What an analysis of a layer is made from, as one key shared by the Warp Stabilizer, the 3D
//! Camera Tracker and Roto Brush / Object Matte.
//!
//! The key hashes a text this module writes field by field. The source item (footage and its
//! settings, solid), the Time Remap property and the masks and effect groups (their properties,
//! keyframes and values) are destructured or matched in full, and each variant is written as a
//! fixed word: a new field or variant doesn't compile until it is decided here, written if it
//! changes the layer's frames, left out (with a reason) if it doesn't. Renaming a field or variant
//! doesn't change keys. Of the layer and of a precomp, only the fields named in `layer_frames` are
//! read (a precomp's contents are #3535). The
//! text leaves out observations (whether footage is available) and data that never changes pixels
//! (colour labels, UI hints, markers), so they never drop saved analyses (#3534, #3536).
//!
//! Keys saved by 0.22–0.24 hashed derived `Debug` text instead. [`legacy`] still recognises
//! them, and a matching saved key is kept rather than rewritten: frozen Roto Brush mattes and
//! segmentations hash the saved key itself.
use std::fmt::Write as _;
use effectcraft_color::ColorSpace;
use effectcraft_keyframe::{Ease, FeatherPoint, Gradient, Interp, Keyframe, ShapePath, Value};
use effectcraft_project::{
AlphaMode, CineonSettings, CineonUnits, Expression, FeatherFalloff, FieldOrder, Footage, FootageKind, GroupKind, ItemId, ItemKind, Layer, LayerSource,
LightKind, MaskMode, MaskMotionBlur, Node, PrimitiveKind, Project, PropGroup, Property, Solid, SourceLayer, Uid,
};
use effectcraft_time::{FrameRate, Tick};
pub(crate) mod legacy;
/// The version of the text, its first word: a later change to what it writes bumps it.
const VERSION: &str = "frames/1";
/// Property groups nest a few levels (effect ▸ group ▸ property); deeper trees are cut here.
const MAX_DEPTH: usize = 32;
fn fnv(s: &str) -> u64 {
let mut h: u64 = 0xcbf2_9ce4_8422_2325;
for b in s.as_bytes() {
h ^= *b as u64;
h = h.wrapping_mul(0x0100_0000_01b3);
}
h
}
fn hex(s: &str) -> String {
format!("{:016x}", fnv(s))
}
/// Which signature a key is made from: today's, or one an earlier release saved.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum Era {
Current,
Legacy,
}
/// The signature of `layer`'s frames: its source (and the source item), In/Out, start time,
/// stretch, Time Remap and the comp frame rate. Warp Stabilizer and 3D Camera Tracker keys are
/// made from it.
pub(crate) fn signature(p: &Project, comp: ItemId, layer: &Layer) -> String {
hex(&signature_text(p, comp, layer))
}
/// The text [`signature`] hashes.
pub(crate) fn signature_text(p: &Project, comp: ItemId, layer: &Layer) -> String {
let mut t = Text::new();
t.word(VERSION);
t.layer_frames(p, comp, layer);
t.0
}
/// A Roto Brush's (or Object Matte's) Input Key: the layer's frames, its masks and the effects
/// above the instance `uid`.
pub(crate) fn input_key(p: &Project, comp: ItemId, layer: &Layer, uid: Uid) -> String {
input_key_of(signature(p, comp, layer), layer, uid)
}
/// An Input Key from a [`signature`].
pub(crate) fn input_key_of(signature: String, layer: &Layer, uid: Uid) -> String {
let mut t = Text::new();
t.word(VERSION);
t.word(&signature);
t.inputs_above(layer, uid);
hex(&t.0)
}
/// Whether `saved`, a key saved with an analysis of `layer`, is for the layer's current frames.
/// `key` makes such a key from a signature of the given era. A key an earlier release saved for
/// the same frames matches too: keep it rather than rewrite it (analysing writes today's).
pub(crate) fn key_matches(p: &Project, comp: ItemId, layer: &Layer, saved: &str, key: impl Fn(String, Era) -> String) -> bool {
key(signature(p, comp, layer), Era::Current) == saved || legacy::signatures(p, comp, layer).into_iter().any(|s| key(s, Era::Legacy) == saved)
}
/// The text a key is hashed from. Fields are `name=value;`; strings are quoted and escaped, so
/// no value can end its field early.
struct Text(String);
impl Text {
fn new() -> Text {
Text(String::new())
}
fn word(&mut self, w: &str) {
self.0.push_str(w);
self.0.push(';');
}
fn field(&mut self, name: &str, value: impl std::fmt::Display) {
let _ = write!(self.0, "{name}={value};");
}
fn str(&mut self, name: &str, s: &str) {
let _ = write!(self.0, "{name}={s:?};");
}
fn num(&mut self, name: &str, v: f64) {
let _ = write!(self.0, "{name}={v:?};");
}
fn nums(&mut self, name: &str, v: &[f64]) {
let _ = write!(self.0, "{name}={v:?};");
}
fn floats(&mut self, name: &str, v: &[f32]) {
let _ = write!(self.0, "{name}={v:?};");
}
fn opt<T>(&mut self, name: &str, v: Option<&T>, write: impl FnOnce(&mut Text, &T)) {
match v {
Some(v) => {
let _ = write!(self.0, "{name}{{");
write(self, v);
self.0.push_str("};");
}
None => self.word(&format!("{name}=none")),
}
}
fn tick(&mut self, name: &str, t: Tick) {
self.field(name, t.0);
}
fn rate(&mut self, name: &str, r: FrameRate) {
let FrameRate { num, den } = r;
let _ = write!(self.0, "{name}={num}/{den};");
}
/// What a layer's frames are made of, before its masks and effects.
fn layer_frames(&mut self, p: &Project, comp: ItemId, layer: &Layer) {
self.layer_source(&layer.source);
if let Some(item) = layer.source.item() {
match p.item(item).map(|i| &i.kind) {
Some(ItemKind::Footage(f)) => self.footage(f),
Some(ItemKind::Solid(s)) => self.solid(s),
// A precomp's own contents aren't in the signature yet (#3535).
Some(ItemKind::Comp(c)) => {
self.word("comp");
self.field("w", c.width);
self.field("h", c.height);
self.rate("rate", c.frame_rate);
self.tick("duration", c.duration);
}
Some(ItemKind::Folder) | None => self.word("item=none"),
}
}
self.tick("in", layer.in_point);
self.tick("out", layer.out_point);
self.tick("start", layer.start_time);
self.num("stretch", layer.stretch);
self.opt("timeRemap", layer.props.get("timeRemap"), |t, pr| t.property(pr));
self.opt("compRate", p.comp(comp).map(|c| &c.frame_rate), |t, r| t.rate("rate", *r));
}
fn layer_source(&mut self, s: &LayerSource) {
match s {
LayerSource::Footage { item } => self.field("footage", item.0),
LayerSource::Comp { item } => self.field("comp", item.0),
LayerSource::Solid { item } => self.field("solid", item.0),
LayerSource::Model { item } => self.field("model", item.0),
LayerSource::Text => self.word("text"),
LayerSource::Shape => self.word("shape"),
LayerSource::Null => self.word("null"),
LayerSource::Camera => self.word("camera"),
LayerSource::Light { kind } => self.field(
"light",
match kind {
LightKind::Parallel => "parallel",
LightKind::Spot => "spot",
LightKind::Point => "point",
LightKind::Ambient => "ambient",
LightKind::Environment => "environment",
},
),
LayerSource::Primitive { kind } => self.field(
"primitive",
match kind {
PrimitiveKind::Cube => "cube",
PrimitiveKind::Sphere => "sphere",
PrimitiveKind::Plane => "plane",
PrimitiveKind::Torus => "torus",
PrimitiveKind::Cone => "cone",
PrimitiveKind::Cylinder => "cylinder",
},
),
}
}
fn solid(&mut self, s: &Solid) {
let Solid { color, width, height, pixel_aspect } = s;
self.word("solid");
self.floats("color", color);
self.field("w", width);
self.field("h", height);
self.num("par", *pixel_aspect);
}
fn footage(&mut self, f: &Footage) {
let Footage {
path,
kind,
width,
height,
pixel_aspect,
frame_rate,
native_rate,
duration,
has_video,
has_audio,
alpha,
premul_color,
loop_count,
codec,
// Whether the file is there is an observation (`footage.check`), not an edit: an
// offline file is the same footage, and its analyses stay valid (#3534).
missing: _,
sequence,
color_profile,
layer,
fields,
invert_alpha,
linear_light,
preserve_rgb,
cineon,
data,
page,
alphabetical,
start_timecode,
file_timecode,
// Markers annotate the footage; they never change its frames.
markers: _,
placed_page,
} = f;
self.word("footage");
self.str("path", path);
self.field(
"kind",
match kind {
FootageKind::Video => "video",
FootageKind::Still => "still",
FootageKind::Sequence => "sequence",
FootageKind::Audio => "audio",
FootageKind::Model => "model",
FootageKind::Data => "data",
},
);
self.field("w", width);
self.field("h", height);
self.num("par", *pixel_aspect);
self.rate("rate", *frame_rate);
self.opt("nativeRate", native_rate.as_ref(), |t, r| t.rate("rate", *r));
self.tick("duration", *duration);
self.field("video", has_video);
self.field("audio", has_audio);
self.field(
"alpha",
match alpha {
AlphaMode::Straight => "straight",
AlphaMode::Premultiplied => "premultiplied",
AlphaMode::Ignore => "ignore",
},
);
self.floats("matte", premul_color);
self.field("loop", loop_count);
self.str("codec", codec);
self.field("frames", sequence.len());
for s in sequence {
self.str("file", s);
}
self.opt("profile", color_profile.as_ref(), |t, c| t.word(color_space(*c)));
self.opt("layer", layer.as_ref(), |t, l| t.source_layer(l));
self.field(
"fields",
match fields {
FieldOrder::Off => "off",
FieldOrder::UpperFirst => "upper",
FieldOrder::LowerFirst => "lower",
},
);
self.field("invertAlpha", invert_alpha);
self.field("linearLight", linear_light);
self.field("preserveRgb", preserve_rgb);
self.cineon(cineon);
self.opt("data", data.as_ref(), |t, d| t.str("text", d));
self.field("page", page);
self.field("alphabetical", alphabetical);
self.opt("startTimecode", start_timecode.as_ref(), |t, v| t.field("frame", v));
self.opt("fileTimecode", file_timecode.as_ref(), |t, v| t.field("frame", v));
self.field("placedPage", placed_page);
}
fn source_layer(&mut self, l: &SourceLayer) {
let SourceLayer { index, name, layer_size, embedded, placed } = l;
self.field("index", index);
// The layer is found by its index; the name only labels it.
let _ = name;
self.field("layerSize", layer_size);
self.opt("embedded", embedded.as_ref(), |t, e| t.str("id", e));
self.field("placed", placed);
}
fn cineon(&mut self, c: &CineonSettings) {
let CineonSettings { log_conversion, converted_black, converted_white, black, white, gamma, rolloff, units } = c;
self.word("cineon");
self.field("log", log_conversion);
self.floats("points", &[*converted_black, *converted_white, *black, *white, *gamma, *rolloff]);
self.field(
"units",
match units {
CineonUnits::TenBit => "10bit",
CineonUnits::EightBit => "8bit",
CineonUnits::Float => "float",
},
);
}
/// The layer's masks and the effects above the instance `uid`: what the effect's input is
/// made of besides the layer's frames.
fn inputs_above(&mut self, layer: &Layer, uid: Uid) {
if let Some(m) = layer.masks() {
self.word("masks");
self.group(m, 0);
}
if let Some(fx) = layer.effects() {
self.word("effects");
for g in fx.groups().take_while(|g| g.uid != uid) {
self.group(g, 0);
}
}
}
fn group(&mut self, g: &PropGroup, depth: usize) {
// Expressions find effects and groups by name (`effect("Blur")`, `propertyGroup(1).name`).
// The uid and colour label never change pixels.
let PropGroup { uid: _, match_id, name, kind, enabled, label: _, children } = g;
if depth >= MAX_DEPTH {
self.word("tooDeep");
return;
}
self.str("group", match_id);
self.str("name", name);
self.group_kind(kind);
self.field("enabled", enabled);
for c in children {
match c {
Node::Prop(p) => self.property(p),
Node::Group(g) => self.group(g, depth + 1),
}
}
self.word("end");
}
fn group_kind(&mut self, k: &GroupKind) {
match k {
GroupKind::Plain => self.word("plain"),
GroupKind::Indexed => self.word("indexed"),
// A mask's colour and lock only show it in the UI.
GroupKind::Mask { mode, inverted, color: _, locked: _, motion_blur, feather_falloff, roto_bezier } => {
self.field(
"mask",
match mode {
MaskMode::None => "none",
MaskMode::Add => "add",
MaskMode::Subtract => "subtract",
MaskMode::Intersect => "intersect",
MaskMode::Lighten => "lighten",
MaskMode::Darken => "darken",
MaskMode::Difference => "difference",
},
);
self.field("inverted", inverted);
self.field(
"motionBlur",
match motion_blur {
MaskMotionBlur::SameAsLayer => "layer",
MaskMotionBlur::On => "on",
MaskMotionBlur::Off => "off",
},
);
self.field(
"falloff",
match feather_falloff {
FeatherFalloff::Smooth => "smooth",
FeatherFalloff::Linear => "linear",
},
);
self.field("rotoBezier", roto_bezier);
}
GroupKind::Effect { effect } => self.str("effect", effect),
// A motion tracker's settings say how to track, not how to draw the layer.
GroupKind::Tracker { settings: _ } => self.word("tracker"),
GroupKind::Essential { overridden } => {
self.word("essential");
for u in overridden {
self.field("overridden", u);
}
}
}
}
fn property(&mut self, pr: &Property) {
// Expressions read the name (`thisProperty.name`) and seed `random`/`wiggle` with the
// uid: the uid is written for a property with an expression. UI hints and the 2D/3D-only
// and hold-only flags say where and how it can be edited, not what it evaluates to.
let Property { uid, match_id, name, value, keys, expr, ui: _, spatial, hold_only: _, three_d_only: _, two_d_only: _, shown_dims: _, static_only: _ } =
pr;
self.str("prop", match_id);
self.str("name", name);
if expr.is_some() {
self.field("uid", uid);
}
self.value(value);
self.field("spatial", spatial);
for k in keys {
self.keyframe(k);
}
self.opt("expr", expr.as_ref(), |t, e| {
let Expression { text, enabled } = e;
t.str("text", text);
t.field("enabled", enabled);
});
}
fn keyframe(&mut self, k: &Keyframe) {
// A key's colour label only shows it in the UI.
let Keyframe {
time,
value,
in_interp,
out_interp,
in_ease,
out_ease,
continuous,
auto_bezier,
spatial_in,
spatial_out,
spatial_auto,
spatial_continuous,
roving,
label: _,
muted,
} = k;
self.tick("key", *time);
self.value(value);
self.field("interp", format_args!("{}/{}", interp(*in_interp), interp(*out_interp)));
for (side, eases) in [("inEase", in_ease), ("outEase", out_ease)] {
for e in eases {
let Ease { speed, influence } = e;
self.nums(side, &[*speed, *influence]);
}
}
self.field("continuous", continuous);
self.field("autoBezier", auto_bezier);
self.nums("spatialIn", spatial_in);
self.nums("spatialOut", spatial_out);
self.field("spatialAuto", spatial_auto);
self.field("spatialContinuous", spatial_continuous);
self.field("roving", roving);
self.field("muted", muted);
}
fn value(&mut self, v: &Value) {
match v {
Value::Scalar(x) => self.num("scalar", *x),
Value::Vec2(x) => self.nums("vec2", x),
Value::Vec3(x) => self.nums("vec3", x),
Value::Color(x) => self.nums("color", x),
Value::Bool(b) => self.field("bool", b),
Value::Enum(i) => self.field("enum", i),
Value::Path(p) => self.shape_path(p),
// A text document has dozens of fields and no place in what a key covers today (a
// text layer's Source Text is not under its masks or effects): its project-file form.
Value::Text(d) => self.str("text", &serde_json::to_string(d).unwrap_or_default()),
Value::Layer(l) => self.opt("layer", l.as_ref(), |t, id| t.field("id", id)),
Value::Gradient(g) => {
let Gradient { colors, opacities } = g;
self.word("gradient");
for (at, c) in colors {
self.num("stop", *at);
self.floats("rgba", c);
}
for (at, o) in opacities {
self.num("stop", *at);
self.floats("opacity", &[*o]);
}
}
Value::Str(s) => self.str("str", s),
}
}
fn shape_path(&mut self, p: &ShapePath) {
let ShapePath { vertices, in_tangents, out_tangents, closed, feather } = p;
self.word("path");
for (name, points) in [("v", vertices), ("in", in_tangents), ("out", out_tangents)] {
for pt in points {
self.nums(name, pt);
}
}
self.field("closed", closed);
for f in feather {
let FeatherPoint { segment, t, radius, tension } = f;
self.field("featherSegment", segment);
self.nums("feather", &[*t, *radius, *tension]);
}
}
}
fn interp(i: Interp) -> &'static str {
match i {
Interp::Linear => "linear",
Interp::Bezier => "bezier",
Interp::Hold => "hold",
}
}
fn color_space(c: ColorSpace) -> &'static str {
match c {
ColorSpace::Srgb => "srgb",
ColorSpace::Rec709 => "rec709",
ColorSpace::Rec2020 => "rec2020",
ColorSpace::DisplayP3 => "p3",
ColorSpace::AcesCg => "acescg",
ColorSpace::Aces2065 => "aces2065",
ColorSpace::Rec2100Pq => "rec2100pq",
ColorSpace::Rec2100Hlg => "rec2100hlg",
}
}
@@ -0,0 +1,147 @@
//! Signatures as 0.22–0.24 wrote them, to recognise the keys those releases saved. Nothing new is
//! keyed with them. They hash derived `Debug` text, so `tests::analysis_signature` pins keys
//! those releases saved: if a type change alters this text, write that part out here.
use effectcraft_project::{Footage, ItemId, ItemKind, Layer, LayerSource, Project, Uid};
use super::fnv;
/// The signatures a saved key of `layer` may have been made from. The footage's availability is
/// tried both ways: those releases hashed it, though it isn't part of the footage (#3534). Before
/// `Footage::placed_page` was added in 0.23, the footage text ended without that field.
pub(crate) fn signatures(p: &Project, comp: ItemId, layer: &Layer) -> Vec<String> {
let src = match &layer.source {
LayerSource::Footage { item } | LayerSource::Solid { item } | LayerSource::Comp { item } => match p.item(*item).map(|i| &i.kind) {
Some(ItemKind::Footage(f)) => {
let mut out = Vec::with_capacity(4);
for missing in [false, true] {
out.push(signature_with_source(p, comp, layer, &footage_text(f, missing, true)));
if matches!(layer.source, LayerSource::Footage { .. }) && !f.placed_page {
out.push(signature_with_source(p, comp, layer, &footage_text(f, missing, false)));
}
}
return out;
}
Some(ItemKind::Solid(s)) => format!("{s:?}"),
Some(ItemKind::Comp(c)) => format!("{}x{}@{:?}/{:?}", c.width, c.height, c.frame_rate, c.duration),
_ => String::new(),
},
_ => String::new(),
};
vec![signature_with_source(p, comp, layer, &src)]
}
/// A Roto Brush Input Key as 0.22–0.24 made it from a [`signatures`] entry.
pub(crate) fn input_key_of(mut s: String, layer: &Layer, uid: Uid) -> String {
if let Some(m) = layer.masks() {
s.push_str(&format!("{m:?}"));
}
if let Some(fx) = layer.effects() {
for g in fx.groups() {
if g.uid == uid {
break;
}
s.push_str(&format!("{g:?}"));
}
}
format!("{:016x}", fnv(&s))
}
/// A footage item as 0.23–0.24 wrote it into a signature (without `placed_page` before 0.23),
/// with `missing` in place of the item's.
pub(crate) fn footage_text(f: &Footage, missing: bool, placed_page: bool) -> String {
format!("{:?}", FootageText { f, missing, placed_page })
}
struct FootageText<'a> {
f: &'a Footage,
missing: bool,
placed_page: bool,
}
impl std::fmt::Debug for FootageText<'_> {
fn fmt(&self, out: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// Every field is named so that a new one doesn't compile until it is decided here: a new
// field was never in these keys, so it stays out.
let Footage {
path,
kind,
width,
height,
pixel_aspect,
frame_rate,
native_rate,
duration,
has_video,
has_audio,
alpha,
premul_color,
loop_count,
codec,
missing: _,
sequence,
color_profile,
layer,
fields,
invert_alpha,
linear_light,
preserve_rgb,
cineon,
data,
page,
alphabetical,
start_timecode,
file_timecode,
markers,
placed_page,
} = self.f;
let mut d = out.debug_struct("Footage");
d.field("path", path)
.field("kind", kind)
.field("width", width)
.field("height", height)
.field("pixel_aspect", pixel_aspect)
.field("frame_rate", frame_rate)
.field("native_rate", native_rate)
.field("duration", duration)
.field("has_video", has_video)
.field("has_audio", has_audio)
.field("alpha", alpha)
.field("premul_color", premul_color)
.field("loop_count", loop_count)
.field("codec", codec)
.field("missing", &self.missing)
.field("sequence", sequence)
.field("color_profile", color_profile)
.field("layer", layer)
.field("fields", fields)
.field("invert_alpha", invert_alpha)
.field("linear_light", linear_light)
.field("preserve_rgb", preserve_rgb)
.field("cineon", cineon)
.field("data", data)
.field("page", page)
.field("alphabetical", alphabetical)
.field("start_timecode", start_timecode)
.field("file_timecode", file_timecode)
.field("markers", markers);
if self.placed_page {
d.field("placed_page", placed_page);
}
d.finish()
}
}
fn signature_with_source(p: &Project, comp: ItemId, layer: &Layer, src: &str) -> String {
let rate = p.comp(comp).map(|c| format!("{:?}", c.frame_rate)).unwrap_or_default();
let s = format!(
"{:?}|{src}|{:?}|{:?}|{:?}|{}|{:?}|{rate}",
layer.source,
layer.in_point,
layer.out_point,
layer.start_time,
layer.stretch,
layer.props.get("timeRemap")
);
format!("{:016x}", fnv(&s))
}
+9 -34
View File
@@ -8,8 +8,8 @@
//! (`Renderer::layer_input`, source → masks → the effects above it). `roto.freeze` runs the same
//! pass and stores the final mattes in the effect (one undo step). `sync`, run after every
//! edit, keeps each instance's hidden Input Key equal to a signature of what its frames are made
//! of (the layer's source and timing, its masks and the effects above it) and drops frozen
//! mattes made from other frames.
//! of (the layer's source and timing, its masks and the effects above it: `analysis::frames_key`),
//! and drops frozen mattes made from other frames. Footage going offline keeps them.
//!
//! Object Matte instances run through the same jobs (`objectMatte.propagate` / `.freeze`): the
//! frames are [`om::job_frames`] around the reference frame, each segmented through
@@ -31,6 +31,7 @@ use effectcraft_render::{EvalCtx, ExprHost, FootageSource, LayerCache, RenderOpt
use effectcraft_time::Tick;
use serde::{Deserialize, Serialize};
use crate::analysis::frames_key::{self, Era};
use crate::tracking::lock;
use crate::{Event, Session};
@@ -207,40 +208,10 @@ fn set_str(g: &mut PropGroup, m: &str, v: String) {
}
}
fn fnv(s: &str) -> u64 {
let mut h: u64 = 0xcbf2_9ce4_8422_2325;
for b in s.as_bytes() {
h ^= *b as u64;
h = h.wrapping_mul(0x0100_0000_01b3);
}
h
}
/// What the effect's input frames are made of: the layer's source and timing, its masks and the
/// effects above the Roto Brush.
pub fn input_key(p: &Project, comp: ItemId, layer: &Layer, uid: Uid) -> String {
input_key_with_signature(crate::warp::signature(p, comp, layer), layer, uid)
}
/// Recognize the input key serialized before 0.23 without re-keying its frozen matte.
fn input_key_before_placed_page(p: &Project, comp: ItemId, layer: &Layer, uid: Uid) -> Option<String> {
let signature = crate::warp::signature_before_placed_page(p, comp, layer)?;
Some(input_key_with_signature(signature, layer, uid))
}
fn input_key_with_signature(mut s: String, layer: &Layer, uid: Uid) -> String {
if let Some(m) = layer.masks() {
s.push_str(&format!("{m:?}"));
}
if let Some(fx) = layer.effects() {
for g in fx.groups() {
if g.uid == uid {
break;
}
s.push_str(&format!("{g:?}"));
}
}
format!("{:016x}", fnv(&s))
frames_key::input_key(p, comp, layer, uid)
}
/// After an edit: refresh Input Keys (Roto Brush and Object Matte); frozen mattes made from
@@ -258,7 +229,11 @@ pub(crate) fn sync(before: &Project, after: &mut Project) -> Vec<(ItemId, LayerI
let old = before.comp(*cid).and_then(|bc| bc.layer(l.id)).and_then(|ol| ol.props.find_group(g.uid));
let saved_key = str_of(g, INPUT_KEY);
// Keep a matching old key: the frozen cache itself also hashes that key.
if saved_key != key && input_key_before_placed_page(after, *cid, l, g.uid).as_deref() != Some(saved_key.as_str()) {
let key_of = |s, era| match era {
Era::Current => frames_key::input_key_of(s, l, g.uid),
Era::Legacy => frames_key::legacy::input_key_of(s, l, g.uid),
};
if !frames_key::key_matches(after, *cid, l, &saved_key, key_of) {
set.push((*cid, l.id, g.uid, key));
todo.push((*cid, l.id, g.uid));
} else if old.is_none_or(|o| guard_of(o) != guard_of(g)) {
+8 -55
View File
@@ -6,10 +6,11 @@
//! analyzer (step 1 of 2, "Analyzing in background"); step 2 ("Stabilizing") derives the
//! stabilization plan once to validate and cache the result. When the job finishes, the analysis is
//! written into the effect's hidden Analysis parameter as one undo step, together with a key of
//! what it was made from (the layer's source, In/Out, start, stretch and Time Remap). Edits that
//! change those clear the analysis (`invalidate`, run after every edit) and queue the effect
//! for re-analysis, which frontends start with [`Session::poll_warp`] (After Effects re-analyses
//! automatically too).
//! what it was made from (the layer's source, In/Out, start, stretch and Time Remap; the key is
//! `analysis::frames_key`'s, shared with the 3D Camera Tracker and Roto Brush). Edits that change
//! those clear the analysis (`invalidate`, run after every edit) and queue the effect for
//! re-analysis, which frontends start with [`Session::poll_warp`] (After Effects re-analyses
//! automatically too). Footage going offline is not such a change.
use crate::offload::{JobKind, rate};
use std::sync::atomic::{AtomicBool, Ordering};
@@ -17,13 +18,14 @@ use std::sync::{Arc, Mutex};
use effectcraft_effects::warp_stab::{self, ANALYSIS, ANALYSIS_KEY};
use effectcraft_keyframe::Value;
use effectcraft_project::{GroupKind, ItemId, ItemKind, Layer, LayerId, LayerSource, Project, PropGroup, Uid};
use effectcraft_project::{GroupKind, ItemId, ItemKind, Layer, LayerId, Project, PropGroup, Uid};
use effectcraft_raster::Image;
use effectcraft_render::{EvalCtx, ExprHost, FootageSource, LayerCache, Renderer};
use effectcraft_time::Tick;
use effectcraft_track::stabilize::{AnalyzeOpts, Analyzer, WarpAnalysis};
use serde::Serialize;
use crate::analysis::frames_key::{self, signature};
use crate::tracking::lock;
use crate::{Event, Session};
@@ -98,54 +100,6 @@ pub(crate) struct WarpWork {
pub times: Vec<Tick>,
}
fn fnv(s: &str) -> u64 {
let mut h: u64 = 0xcbf2_9ce4_8422_2325;
for b in s.as_bytes() {
h ^= *b as u64;
h = h.wrapping_mul(0x0100_0000_01b3);
}
h
}
/// What an analysis of `layer` depends on (its frames): source (and the footage item's
/// interpretation), In/Out, start time, stretch, Time Remap and the comp frame rate.
pub fn signature(p: &Project, comp: ItemId, layer: &Layer) -> String {
let src = match &layer.source {
LayerSource::Footage { item } | LayerSource::Solid { item } | LayerSource::Comp { item } => match p.item(*item).map(|i| &i.kind) {
Some(ItemKind::Footage(f)) => format!("{f:?}"),
Some(ItemKind::Solid(s)) => format!("{s:?}"),
Some(ItemKind::Comp(c)) => format!("{}x{}@{:?}/{:?}", c.width, c.height, c.frame_rate, c.duration),
_ => String::new(),
},
_ => String::new(),
};
signature_with_source(p, comp, layer, &src)
}
/// Before `Footage::placed_page` was added in 0.23, the persisted signature hashed the
/// same Debug representation without that last field. Only ordinary footage can match it.
pub(crate) fn signature_before_placed_page(p: &Project, comp: ItemId, layer: &Layer) -> Option<String> {
let LayerSource::Footage { item } = &layer.source else { return None };
let ItemKind::Footage(footage) = &p.item(*item)?.kind else { return None };
let src = format!("{footage:?}");
let old = src.strip_suffix(", placed_page: false }")?;
Some(signature_with_source(p, comp, layer, &format!("{old} }}")))
}
fn signature_with_source(p: &Project, comp: ItemId, layer: &Layer, src: &str) -> String {
let rate = p.comp(comp).map(|c| format!("{:?}", c.frame_rate)).unwrap_or_default();
let s = format!(
"{:?}|{src}|{:?}|{:?}|{:?}|{}|{:?}|{rate}",
layer.source,
layer.in_point,
layer.out_point,
layer.start_time,
layer.stretch,
layer.props.get("timeRemap")
);
format!("{:016x}", fnv(&s))
}
fn is_warp(g: &PropGroup) -> bool {
matches!(&g.kind, GroupKind::Effect { effect } if effect == warp_stab::ID)
}
@@ -169,11 +123,10 @@ pub(crate) fn invalidate(before: &Project, after: &mut Project) -> Vec<(ItemId,
if !fx.groups().any(is_warp) {
continue;
}
let sig = signature(after, *cid, l);
let old_layer = before.comp(*cid).and_then(|bc| bc.layer(l.id));
for g in fx.groups().filter(|g| is_warp(g)) {
let analysed = !str_of(g, ANALYSIS).is_empty();
if analysed && str_of(g, ANALYSIS_KEY) != sig {
if analysed && !frames_key::key_matches(after, *cid, l, &str_of(g, ANALYSIS_KEY), |s, _| s) {
clear.push((*cid, l.id, g.uid));
todo.push((*cid, l.id, g.uid));
} else if !analysed && old_layer.and_then(|ol| ol.props.find_group(g.uid)).is_none() {
+7 -3
View File
@@ -319,15 +319,19 @@ impl Prober {
return f.map(|footage| Probed { name, footage, ask_alpha: false, warning: None }).map_err(fail);
}
let importer = self.importer.as_ref().ok_or_else(|| fail("media import is not available in this build".into()))?;
let mut f = crate::sequence::probe(importer.as_ref(), src, self.sequence_rate).map_err(fail)?;
let mut warning = None;
// What the file's own import left out (a model's textures over the limits) is a warning too.
let (mut f, mut warning) = match src {
Source::File(_) => importer.probe_noting(path).map_err(fail)?,
_ => (crate::sequence::probe(importer.as_ref(), src, self.sequence_rate).map_err(fail)?, None),
};
// Settings ▸ Import ▸ Report Missing Frames (numbered sequences).
if f.kind == FootageKind::Sequence
&& !f.alphabetical
&& self.report_missing_frames
&& let Some(gaps) = crate::sequence::missing_report(&f.sequence)
{
warning = Some(format!("{name}: {gaps} (the previous frame is held)"));
let gaps = format!("{name}: {gaps} (the previous frame is held)");
warning = Some(warning.map_or(gaps.clone(), |w| format!("{w}; {gaps}")));
}
// Settings ▸ Import ▸ Interpret Unlabeled Alpha As: images only (a 3D model renders its
// own alpha, and audio and data have none).
+30 -1
View File
@@ -1408,6 +1408,13 @@ fn convert_expr_to_keys(s: &mut Session, p: &Value) -> Result<Value> {
if sel.is_empty() {
return Err(bad(CMD, "no `path` given and no selected property has an expression"));
}
// Every layer is checked before the first is converted: a refusal leaves them all as they were.
let step = comp.frame_duration().0;
for (lid, _) in &sel {
if let Some(l) = comp.layer(*lid) {
check_convertible(step, l)?;
}
}
let mut n = 0;
for (lid, uid) in sel {
n += convert_one_expr(s, cid, lid, uid)?.as_u64().unwrap_or(0);
@@ -1418,14 +1425,36 @@ fn convert_expr_to_keys(s: &mut Session, p: &Value) -> Result<Value> {
convert_one_expr(s, cid, lid, uid)
}
/// Most keyframes Convert Expression to Keyframes makes: 2^20, 4.8 hours at 60 fps (After Effects
/// compositions run to 3 hours, 648,000 frames at 60 fps).
const MAX_CONVERTED_KEYS: u64 = 1 << 20;
const _: () = assert!(MAX_CONVERTED_KEYS >= 3 * 3600 * 60);
/// One evaluation and one key per frame of the layer: its In and Out points and the composition's
/// frame duration are saved data, so the step must advance and the count (a partial last frame
/// rounded up, as the loop steps, in 128 bits) is checked before any key is made.
fn check_convertible(step: i64, layer: &Layer) -> Result<()> {
const CMD: &str = "prop.convertExpressionToKeyframes";
if step <= 0 {
return Err(bad(CMD, "the composition's frame duration is not positive"));
}
let (step, span) = (i128::from(step), i128::from(layer.out_point.0) - i128::from(layer.in_point.0));
let frames = if span > 0 { (span + step - 1) / step } else { 0 };
if frames > i128::from(MAX_CONVERTED_KEYS) {
return Err(bad(CMD, format!("the layer spans {frames} frames; at most {MAX_CONVERTED_KEYS} are converted")));
}
Ok(())
}
/// Replaces the expression on one property with keyframes sampled from its evaluated values.
/// Returns the number of properties converted.
fn convert_one_expr(s: &mut Session, cid: ItemId, lid: LayerId, uid: Uid) -> Result<Value> {
let comp = s.project.comp(cid).ok_or(EngineError::NoComp)?.clone();
let layer = comp.layer(lid).ok_or(EngineError::NoComp)?.clone();
let pr = layer.props.find(uid).ok_or_else(|| bad("prop.convertExpressionToKeyframes", "no property"))?.clone();
let mut keys = vec![];
let fd = comp.frame_duration();
check_convertible(fd.0, &layer)?;
let mut keys = vec![];
let mut t = layer.in_point;
while t < layer.out_point {
let ctx = effectcraft_render::EvalCtx {
+1
View File
@@ -1,6 +1,7 @@
pub mod doc_path;
pub mod footage_check;
pub mod footage_reload;
pub mod lut_reload;
pub mod media_browser;
pub mod media_cache;
pub mod sequence;
+90
View File
@@ -0,0 +1,90 @@
//! LUT files that change on disk (#3493).
//!
//! A render follows a LUT file by itself: [`effectcraft_effects::load_lut`] stamps the file and
//! reads it again once it changed, and a layer's cache key holds the stamp. What the desktop app
//! keeps of earlier renders, the frames of its viewer and RAM preview, is dropped when
//! [`effectcraft_effects::lut_generation`] moves. The [`Watcher`] looks at the LUT files in use
//! every two seconds, so an edit shows without anything rendering first, and wakes the interface
//! only when one changed.
use std::sync::mpsc::{RecvTimeoutError, SyncSender};
use std::time::Duration;
/// Moves each time a LUT file in use was found changed on disk: frames rendered before may show
/// the old LUT ([`effectcraft_effects::lut_generation`]).
pub fn generation() -> u64 {
effectcraft_effects::lut_generation()
}
/// Stamp the LUT files in use now ([`effectcraft_effects::check_lut_files`]): the ones that
/// changed are read again by the next render. Returns [`generation`].
pub fn check() -> u64 {
effectcraft_effects::check_lut_files()
}
/// How often the LUT files in use are stamped.
pub const INTERVAL: Duration = Duration::from_secs(2);
/// A worker thread that stamps the LUT files in use ([`effectcraft_effects::check_lut_files`])
/// and runs `wake` when one changed. Dropping the watcher ends the thread.
pub struct Watcher {
_stop: SyncSender<()>,
}
impl Watcher {
/// Start the worker. `None` where there are no threads (the web app, whose LUTs don't come
/// from files) or one couldn't be started.
pub fn start(wake: impl Fn() + Send + 'static) -> Option<Watcher> {
Self::start_with(wake, INTERVAL)
}
/// [`Watcher::start`] stamping every `every` (tests).
pub fn start_with(wake: impl Fn() + Send + 'static, every: Duration) -> Option<Watcher> {
if cfg!(target_arch = "wasm32") {
return None;
}
let (tx, rx) = std::sync::mpsc::sync_channel::<()>(1);
std::thread::Builder::new()
.name("lut-watch".into())
.spawn(move || {
let mut seen = effectcraft_effects::lut_generation();
// (ends once the watcher, the only sender, is dropped)
while let Err(RecvTimeoutError::Timeout) = rx.recv_timeout(every) {
let now = check();
if now != seen {
seen = now;
wake();
}
}
})
.ok()?;
Some(Watcher { _stop: tx })
}
}
#[cfg(all(test, not(target_arch = "wasm32")))]
mod tests {
use super::*;
/// A LUT file edited on disk wakes the interface without a render loading it.
#[test]
fn an_edited_lut_file_wakes_the_interface() {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("watched.cube");
std::fs::write(&path, "LUT_1D_SIZE 2\n0 0 0\n1 1 1\n").unwrap();
let src = path.to_string_lossy().into_owned();
assert!(effectcraft_effects::load_lut(&src).is_some());
let before = effectcraft_effects::lut_generation();
let (tx, rx) = std::sync::mpsc::channel();
let _watcher = Watcher::start_with(
move || {
let _ = tx.send(());
},
Duration::from_millis(10),
)
.unwrap();
std::fs::write(&path, "LUT_1D_SIZE 3\n0 0 0\n0.5 0.5 0.5\n1 1 1\n").unwrap();
rx.recv_timeout(Duration::from_secs(10)).unwrap();
assert!(effectcraft_effects::lut_generation() > before);
}
}
+1
View File
@@ -61,6 +61,7 @@ pub use effectcraft_track as track;
pub use footage::doc_path;
pub use footage::footage_check;
pub use footage::footage_reload;
pub use footage::lut_reload;
pub use footage::media_browser;
pub use footage::media_cache;
pub use footage::sequence;
+5
View File
@@ -106,6 +106,11 @@ pub trait Importer: Send + Sync {
/// Probe one file and return footage metadata. Image sequences are the engine's
/// ([`sequence`]): it groups numbered stills and probes their first file here.
fn probe(&self, path: &str) -> std::result::Result<effectcraft_project::Footage, String>;
/// [`probe`](Self::probe), and what the import left out of the file (a 3D model's textures
/// over the limits), which the import shows the user.
fn probe_noting(&self, path: &str) -> std::result::Result<(effectcraft_project::Footage, Option<String>), String> {
self.probe(path).map(|f| (f, None))
}
/// A footage file's bytes are now at `path` (extracted from a template): hosts whose media
/// layer reads from memory (the browser) register them; file-based ones need nothing.
fn register(&self, _path: &str, _data: &[u8]) {}
+3
View File
@@ -1,6 +1,7 @@
mod add_item_options;
mod aep_export;
mod aep_import;
mod analysis_signature;
mod anim_presets;
mod anim_tools;
mod aux_footage;
@@ -27,8 +28,10 @@ mod key_metadata_order;
mod key_time;
mod keyframe_text;
mod keylight;
mod legacy_analysis_keys;
mod limits;
mod lottie;
mod lut_files;
mod m137;
mod m145;
mod markers;
@@ -0,0 +1,315 @@
//! Warp Stabilizer, 3D Camera Tracker and Roto Brush keys saved by 0.24 keep matching their
//! layer's frames after edits that don't change them, and a real change still clears them.
use effectcraft_effects::camera_tracker::{TRACKS, TRACKS_KEY};
use effectcraft_effects::roto::{FROZEN, INPUT_KEY};
use effectcraft_effects::warp_stab::{ANALYSIS, ANALYSIS_KEY};
use effectcraft_keyframe::Value;
use effectcraft_project::{ItemId, LayerId, Project};
use serde_json::json;
use crate::Session;
const COMP: ItemId = ItemId(2);
const CLIP: LayerId = LayerId(3);
const WARP: u64 = 26;
const TRACKER: u64 = 54;
const ROTO: u64 = 86;
/// Saved by 0.24.1 (before #3534/#3536): the clip of `tracked-0.22.ecproj` with Time Remap, a
/// mask, a Gaussian Blur and a Roto Brush, its analyses replaced by short stand-ins. The keys
/// are the ones that version computed for it.
const ANALYSED_0_24: &str = include_str!("fixtures/analysed-0.24.ecproj");
const SIGNATURE_0_24: &str = "03efb7c4b0f27b65";
const ROTO_INPUT_0_24: &str = "7b319ce93027617c";
fn open(json: &str) -> Session {
let mut s = Session::default();
s.replace_project(Project::from_json(json).unwrap(), None);
s.open_comp(COMP);
s
}
/// The (data, key) of the Warp Stabilizer, the 3D Camera Tracker and the Roto Brush.
fn saved(s: &Session) -> [(String, String); 3] {
let layer = s.project.comp(COMP).unwrap().layer(CLIP).unwrap();
let get = |uid: u64, data: &str, key: &str| {
let params = crate::camera_track::static_params(layer.props.find_group(uid).unwrap());
let text = |id: &str| match params.get(id) {
Some(Value::Str(s)) => s.clone(),
other => panic!("{id}: {other:?}"),
};
(text(data), text(key))
};
[get(WARP, ANALYSIS, ANALYSIS_KEY), get(TRACKER, TRACKS, TRACKS_KEY), get(ROTO, FROZEN, INPUT_KEY)]
}
fn add_to_render_queue(s: &mut Session) {
s.execute_checked("renderQueue.add", json!({"comp": COMP.0, "format": "png", "output": "frame.png"})).unwrap();
}
#[test]
fn analyses_saved_by_0_24_survive_edits_that_keep_their_frames() {
let mut s = open(ANALYSED_0_24);
let before = saved(&s);
assert_eq!(before[0], ("saved analysis".into(), SIGNATURE_0_24.into()));
assert_eq!(before[1], ("saved tracks".into(), SIGNATURE_0_24.into()));
assert_eq!(before[2], ("saved frozen".into(), ROTO_INPUT_0_24.into()));
add_to_render_queue(&mut s);
assert_eq!(saved(&s), before);
s.execute_checked("edit.undo", json!({})).unwrap();
assert_eq!(saved(&s), before);
// Saved and reopened, the keys still match.
let mut s = open(&s.project.to_json());
add_to_render_queue(&mut s);
assert_eq!(saved(&s), before);
// Other frames: all three are cleared (the Roto Brush gets a new key), and undo brings them back.
s.execute_checked("layer.timing", json!({"layer": CLIP.0, "out": 0.25})).unwrap();
let after = saved(&s);
assert_eq!(after[0], (String::new(), String::new()));
assert_eq!(after[1], (String::new(), String::new()));
assert_eq!(after[2].0, "");
assert_ne!(after[2].1, ROTO_INPUT_0_24);
s.execute_checked("edit.undo", json!({})).unwrap();
assert_eq!(saved(&s), before);
// Time Remap is part of the frames.
s.execute_checked("prop.set", json!({"layer": CLIP.0, "path": "timeRemap", "value": 0.3})).unwrap();
assert!(saved(&s).iter().all(|(data, _)| data.is_empty()));
s.execute_checked("edit.undo", json!({})).unwrap();
// The Roto Brush's input also has the layer's masks and the effects above it.
s.execute_checked("prop.set", json!({"layer": CLIP.0, "path": "effects/#3/blurriness", "value": 4})).unwrap();
let after = saved(&s);
assert_eq!(after[2].0, "");
assert_ne!(after[2].1, ROTO_INPUT_0_24);
s.execute_checked("edit.undo", json!({})).unwrap();
s.execute_checked("prop.set", json!({"layer": CLIP.0, "path": "masks/#1/expansion", "value": 3})).unwrap();
assert_eq!(saved(&s)[2].0, "");
s.execute_checked("edit.undo", json!({})).unwrap();
assert_eq!(saved(&s), before);
}
/// The text keys are made from today, written field by field (#3536). It changes only when this
/// test is changed with it: a new field of a type it writes doesn't compile until it is decided
/// in `analysis::frames_key`, and renaming a field or variant doesn't change it.
#[test]
fn signature_text_is_pinned() {
let s = open(ANALYSED_0_24);
let layer = s.project.comp(COMP).unwrap().layer(CLIP).unwrap();
let key = r#"frames/1;footage=1;footage;path="/tmp/effectcraft-3456-shake.mp4";kind=video;w=160;h=120;par=1.0;rate=12/1;nativeRate=none;duration=254016000000;video=true;audio=false;alpha=ignore;matte=[0.0, 0.0, 0.0];loop=1;codec="H.264 (High)";frames=0;profile{rec709;};layer=none;fields=off;invertAlpha=false;linearLight=false;preserveRgb=false;cineon;log=false;points=[0.0, 1023.0, 95.0, 685.0, 1.7, 20.0];units=10bit;data=none;page=0;alphabetical=false;startTimecode=none;fileTimecode=none;placedPage=false;in=0;out=254016000000;start=0;stretch=100.0;timeRemap{prop="timeRemap";name="Time Remap";scalar=0.0;spatial=false;key=0;scalar=0.2;interp=linear/linear;continuous=false;autoBezier=false;spatialIn=[0.0, 0.0, 0.0];spatialOut=[0.0, 0.0, 0.0];spatialAuto=true;spatialContinuous=false;roving=false;muted=false;key=254016000000;scalar=1.0;interp=linear/linear;continuous=false;autoBezier=false;spatialIn=[0.0, 0.0, 0.0];spatialOut=[0.0, 0.0, 0.0];spatialAuto=true;spatialContinuous=false;roving=false;muted=false;expr=none;};compRate{rate=12/1;};"#;
assert_eq!(crate::analysis::frames_key::signature_text(&s.project, COMP, layer), key);
}
/// Keys made today (after analysing again) match through edits, undo and save/reopen too, and
/// renaming or relabelling never drops them.
#[test]
fn todays_keys_survive_edits_that_keep_their_frames() {
let mut s = open(ANALYSED_0_24);
// Analysing again writes today's keys.
let layer = s.project.comp(COMP).unwrap().layer(CLIP).unwrap();
let signature = crate::analysis::frames_key::signature(&s.project, COMP, layer);
let input = crate::roto::input_key(&s.project, COMP, layer, ROTO);
assert_ne!(signature, SIGNATURE_0_24);
s.edit("analyse", None, |p, _| {
let l = p.comp_mut(COMP).unwrap().layer_mut(CLIP).unwrap();
for (uid, id, key) in [(WARP, ANALYSIS_KEY, &signature), (TRACKER, TRACKS_KEY, &signature), (ROTO, INPUT_KEY, &input)] {
l.props.find_group_mut(uid).unwrap().get_mut(id).unwrap().value = Value::Str(key.clone());
}
Ok(())
})
.unwrap();
// The Roto Brush's key covers the effects above it: the Warp Stabilizer's new key changed it.
let layer = s.project.comp(COMP).unwrap().layer(CLIP).unwrap();
let input = crate::roto::input_key(&s.project, COMP, layer, ROTO);
s.edit("roto key", None, |p, _| {
let g = p.comp_mut(COMP).unwrap().layer_mut(CLIP).unwrap().props.find_group_mut(ROTO).unwrap();
g.get_mut(INPUT_KEY).unwrap().value = Value::Str(input.clone());
g.get_mut(FROZEN).unwrap().value = Value::Str("saved frozen".into());
Ok(())
})
.unwrap();
let before = saved(&s);
assert_eq!(before[0].1, signature);
assert_eq!(before[2], ("saved frozen".into(), input));
add_to_render_queue(&mut s);
assert_eq!(saved(&s), before);
s.execute_checked("edit.undo", json!({})).unwrap();
assert_eq!(saved(&s), before);
let mut s = open(&s.project.to_json());
add_to_render_queue(&mut s);
assert_eq!(saved(&s), before);
// Offline and back online (#3534).
for missing in [true, false] {
if let Some(effectcraft_project::ItemKind::Footage(f)) = std::sync::Arc::make_mut(&mut s.project).item_mut(ItemId(1)).map(|i| &mut i.kind) {
f.missing = missing;
}
add_to_render_queue(&mut s);
assert_eq!(saved(&s), before);
}
// Colour labels and footage markers only show things.
s.edit("label", None, |p, _| {
let l = p.comp_mut(COMP).unwrap().layer_mut(CLIP).unwrap();
l.props.find_group_mut(82).unwrap().label = Some(effectcraft_color::Label::Yellow);
if let Some(effectcraft_project::ItemKind::Footage(f)) = p.item_mut(ItemId(1)).map(|i| &mut i.kind) {
f.markers.push(effectcraft_project::Marker::default());
}
Ok(())
})
.unwrap();
assert_eq!(saved(&s), before);
// Expressions find effects by name: renaming the effect above the Roto Brush is a change for it.
s.edit("rename", None, |p, _| {
p.comp_mut(COMP).unwrap().layer_mut(CLIP).unwrap().props.find_group_mut(82).unwrap().name = "Soft".into();
Ok(())
})
.unwrap();
assert_eq!(saved(&s)[..2], before[..2]);
assert_eq!(saved(&s)[2].0, "");
s.execute_checked("edit.undo", json!({})).unwrap();
assert_eq!(saved(&s), before);
// A real change still clears them.
s.execute_checked("file.interpretFootage", json!({"items": [1], "invertAlpha": true})).unwrap();
assert!(saved(&s).iter().all(|(data, _)| data.is_empty()));
}
/// Footage going offline (or coming back) is an observation, not an edit: the next edit keeps
/// every analysis (#3534).
#[test]
fn offline_footage_keeps_analyses() {
let mut s = open(ANALYSED_0_24);
let before = saved(&s);
let missing = |s: &Session| matches!(&s.project.item(ItemId(1)).unwrap().kind, effectcraft_project::ItemKind::Footage(f) if f.missing);
// The fixture's footage path doesn't exist here: the check marks it missing.
let r = s.execute_checked("footage.check", json!({"wait": true})).unwrap();
assert_eq!(r["missing"], 1, "{r}");
assert!(missing(&s));
add_to_render_queue(&mut s);
assert_eq!(saved(&s), before);
// Saved and reopened while offline, then back online.
let mut s = open(&s.project.to_json());
assert!(missing(&s));
add_to_render_queue(&mut s);
assert_eq!(saved(&s), before);
if let Some(effectcraft_project::ItemKind::Footage(f)) = std::sync::Arc::make_mut(&mut s.project).item_mut(ItemId(1)).map(|i| &mut i.kind) {
f.missing = false;
}
add_to_render_queue(&mut s);
assert_eq!(saved(&s), before);
// A real change while offline still clears them.
s.execute_checked("file.interpretFootage", json!({"items": [1], "invertAlpha": true})).unwrap();
assert!(saved(&s).iter().all(|(data, _)| data.is_empty()));
}
/// A key 0.24.1 saved while the footage was offline (it hashed the availability) matches too,
/// online or offline. 0.24.1 gave the Roto Brush this Input Key when the fixture's footage went
/// offline and an edit cleared the other two analyses.
#[test]
fn keys_saved_by_0_24_while_offline_still_match() {
const ROTO_INPUT_0_24_OFFLINE: &str = "6183fdd46b514259";
let mut s = open(ANALYSED_0_24);
s.edit("offline", None, |p, _| {
if let Some(effectcraft_project::ItemKind::Footage(f)) = p.item_mut(ItemId(1)).map(|i| &mut i.kind) {
f.missing = true;
}
let l = p.comp_mut(COMP).unwrap().layer_mut(CLIP).unwrap();
// What 0.24.1's edit cleared then.
use effectcraft_effects::camera_tracker::{AVERAGE_ERROR, METHOD_USED, SOLVE, SOLVE_KEY};
for (uid, id) in
[(WARP, ANALYSIS), (WARP, ANALYSIS_KEY), (TRACKER, SOLVE), (TRACKER, SOLVE_KEY), (TRACKER, METHOD_USED), (TRACKER, TRACKS), (TRACKER, TRACKS_KEY)]
{
l.props.find_group_mut(uid).unwrap().prop_mut(id).unwrap().value = Value::Str(String::new());
}
l.props.find_group_mut(TRACKER).unwrap().prop_mut(AVERAGE_ERROR).unwrap().value = Value::Scalar(0.0);
let g = l.props.find_group_mut(ROTO).unwrap();
g.get_mut(INPUT_KEY).unwrap().value = Value::Str(ROTO_INPUT_0_24_OFFLINE.into());
Ok(())
})
.unwrap();
let roto = |s: &Session| saved(s)[2].clone();
assert_eq!(roto(&s), ("saved frozen".into(), ROTO_INPUT_0_24_OFFLINE.into()));
for missing in [true, false] {
if let Some(effectcraft_project::ItemKind::Footage(f)) = std::sync::Arc::make_mut(&mut s.project).item_mut(ItemId(1)).map(|i| &mut i.kind) {
f.missing = missing;
}
add_to_render_queue(&mut s);
assert_eq!(roto(&s), ("saved frozen".into(), ROTO_INPUT_0_24_OFFLINE.into()));
}
}
/// Expressions seed `random` and `wiggle` with the property's uid: a Time Remap with an expression
/// keys its uid (a duplicated layer gets new uids), one without doesn't.
#[test]
fn an_expression_keys_its_property_uid() {
let s = open(ANALYSED_0_24);
let layer = s.project.comp(COMP).unwrap().layer(CLIP).unwrap().clone();
let text = |l: &effectcraft_project::Layer| crate::analysis::frames_key::signature_text(&s.project, COMP, l);
let renumbered = |l: &effectcraft_project::Layer| {
let mut l = l.clone();
l.props.get_mut("timeRemap").unwrap().uid += 1000;
l
};
assert_eq!(text(&renumbered(&layer)), text(&layer));
let mut with_expr = layer.clone();
with_expr.props.get_mut("timeRemap").unwrap().expr =
Some(effectcraft_project::Expression { text: "seedRandom(0, true); random(0, 1)".into(), enabled: true });
assert_ne!(text(&renumbered(&with_expr)), text(&with_expr));
}
/// Non-default values of the types the key writes are written as their fixed words (#3536).
#[test]
fn nested_values_are_written_as_fixed_words() {
use effectcraft_project::{
AlphaMode, CineonUnits, FieldOrder, FootageKind, GroupKind, ItemKind, LayerSource, MaskMode, MaskMotionBlur, Solid, SourceLayer,
};
let mut s = open(ANALYSED_0_24);
let p = std::sync::Arc::make_mut(&mut s.project);
if let Some(ItemKind::Footage(f)) = p.item_mut(ItemId(1)).map(|i| &mut i.kind) {
f.kind = FootageKind::Sequence;
f.sequence = vec!["a_0001.png".into(), "a_0002.png".into()];
f.alpha = AlphaMode::Premultiplied;
f.premul_color = [0.5, 0.25, 1.0];
f.fields = FieldOrder::UpperFirst;
f.cineon.units = CineonUnits::Float;
f.cineon.log_conversion = true;
f.color_profile = Some(effectcraft_color::ColorSpace::DisplayP3);
f.layer = Some(SourceLayer { index: 3, name: "Sky".into(), layer_size: true, embedded: Some("id-7".into()), placed: true });
f.native_rate = Some(effectcraft_time::FrameRate { num: 30000, den: 1001 });
f.start_timecode = Some(42);
f.data = Some("{\"k\":1}".into());
}
let layer = p.comp(COMP).unwrap().layer(CLIP).unwrap().clone();
let text = crate::analysis::frames_key::signature_text(p, COMP, &layer);
let footage = text.split(";in=").next().unwrap();
assert_eq!(
footage,
r#"frames/1;footage=1;footage;path="/tmp/effectcraft-3456-shake.mp4";kind=sequence;w=160;h=120;par=1.0;rate=12/1;nativeRate{rate=30000/1001;};duration=254016000000;video=true;audio=false;alpha=premultiplied;matte=[0.5, 0.25, 1.0];loop=1;codec="H.264 (High)";frames=2;file="a_0001.png";file="a_0002.png";profile{p3;};layer{index=3;layerSize=true;embedded{id="id-7";};placed=true;};fields=upper;invertAlpha=false;linearLight=false;preserveRgb=false;cineon;log=true;points=[0.0, 1023.0, 95.0, 685.0, 1.7, 20.0];units=float;data{text="{\"k\":1}";};page=0;alphabetical=false;startTimecode{frame=42;};fileTimecode=none;placedPage=false"#
);
let solid = p.add_item("Solid", Default::default(), None, ItemKind::Solid(Solid { color: [1.0, 0.5, 0.0], width: 64, height: 48, pixel_aspect: 2.0 }));
let mut on_solid = layer.clone();
on_solid.source = LayerSource::Solid { item: solid };
let text = crate::analysis::frames_key::signature_text(p, COMP, &on_solid);
assert_eq!(text.split(";in=").next().unwrap(), format!("frames/1;solid={};solid;color=[1.0, 0.5, 0.0];w=64;h=48;par=2.0", solid.0));
// Every mask mode and motion blur setting gives its own Input Key.
let mask = layer.masks().unwrap().groups().next().unwrap().uid;
let mut keys = std::collections::BTreeSet::new();
for mode in MaskMode::ALL {
for blur in [MaskMotionBlur::SameAsLayer, MaskMotionBlur::On, MaskMotionBlur::Off] {
let mut l = layer.clone();
if let GroupKind::Mask { mode: m, motion_blur, .. } = &mut l.props.find_group_mut(mask).unwrap().kind {
(*m, *motion_blur) = (mode, blur);
}
keys.insert(crate::analysis::frames_key::input_key(p, COMP, &l, ROTO));
}
}
assert_eq!(keys.len(), MaskMode::ALL.len() * 3);
}
+1
View File
@@ -0,0 +1 @@
{"schema":2,"settings":{"bit_depth":"Bpc8","linearize":false,"working_space":null,"blend_linear":false,"time_display":"Timecode","frame_start":0,"audio_sample_rate":48000,"gpu_acceleration":true,"color_engine":"Adobe","hdr":"Clip","output_space":null,"working_gamma":2.2},"items":{"1":{"id":1,"name":"effectcraft-3456-shake.mp4","label":"Aqua","comment":"","parent":null,"kind":{"type":"Footage","path":"/tmp/effectcraft-3456-shake.mp4","kind":"Video","width":160,"height":120,"pixel_aspect":1.0,"frame_rate":{"num":12,"den":1},"native_rate":null,"duration":254016000000,"has_video":true,"has_audio":false,"alpha":"Ignore","premul_color":[0.0,0.0,0.0],"loop_count":1,"codec":"H.264 (High)","missing":false,"color_profile":"Rec709"}},"2":{"id":2,"name":"effectcraft-3456-shake","label":"Sandstone","comment":"","parent":null,"kind":{"type":"Comp","width":160,"height":120,"pixel_aspect":1.0,"frame_rate":{"num":12,"den":1},"duration":254016000000,"display_start":0,"background":[0.0,0.0,0.0],"work_area":[0,254016000000],"layers":[{"id":3,"name":"effectcraft-3456-shake.mp4","source":{"type":"Footage","item":1},"label":"Aqua","comment":"","start_time":0,"in_point":0,"out_point":254016000000,"stretch":100.0,"switches":{"video":true,"audio":true,"solo":false,"locked":false,"shy":false,"collapse":false,"quality":"Best","sampling":"Bilinear","effects":true,"frame_blend":"Off","motion_blur":false,"adjustment":false,"three_d":false,"guide":false},"blend_mode":"Normal","preserve_transparency":false,"track_matte":null,"parent":null,"markers":[],"auto_orient":"Off","props":{"uid":4,"match":"layer","name":"effectcraft-3456-shake.mp4","kind":{"kind":"Plain"},"enabled":true,"children":[{"node":"Prop","uid":76,"match":"timeRemap","name":"Time Remap","value":{"t":"Scalar","v":0.0},"keys":[{"time":0,"value":{"t":"Scalar","v":0.2},"in_interp":"Linear","out_interp":"Linear","in_ease":[],"out_ease":[],"continuous":false,"auto_bezier":false,"spatial_in":[0.0,0.0,0.0],"spatial_out":[0.0,0.0,0.0],"spatial_auto":true,"spatial_continuous":false,"roving":false},{"time":254016000000,"value":{"t":"Scalar","v":1.0},"in_interp":"Linear","out_interp":"Linear","in_ease":[],"out_ease":[],"continuous":false,"auto_bezier":false,"spatial_in":[0.0,0.0,0.0],"spatial_out":[0.0,0.0,0.0],"spatial_auto":true,"spatial_continuous":false,"roving":false}],"ui":{"kind":"Number"},"spatial":false,"hold_only":false,"three_d_only":false,"two_d_only":false,"shown_dims":0,"static_only":false},{"node":"Group","uid":5,"match":"masks","name":"Masks","kind":{"kind":"Plain"},"enabled":true,"children":[{"node":"Group","uid":77,"match":"mask","name":"Mask 1","kind":{"kind":"Mask","mode":"Add","inverted":false,"color":[177,180,79],"locked":false,"motion_blur":"SameAsLayer","feather_falloff":"Smooth","roto_bezier":false},"enabled":true,"children":[{"node":"Prop","uid":78,"match":"path","name":"Mask Path","value":{"t":"Path","v":{"vertices":[[10.0,10.0],[120.0,10.0],[120.0,100.0],[10.0,100.0]],"in_tangents":[[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0]],"out_tangents":[[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0]],"closed":false}},"ui":{"kind":"Path"},"spatial":false,"hold_only":false,"three_d_only":false,"two_d_only":false,"shown_dims":0,"static_only":false},{"node":"Prop","uid":79,"match":"feather","name":"Mask Feather","value":{"t":"Vec2","v":[0.0,0.0]},"ui":{"kind":"Pixels"},"spatial":false,"hold_only":false,"three_d_only":false,"two_d_only":false,"shown_dims":0,"static_only":false},{"node":"Prop","uid":80,"match":"opacity","name":"Mask Opacity","value":{"t":"Scalar","v":100.0},"ui":{"kind":"Slider","min":0.0,"max":100.0,"slider_min":0.0,"slider_max":100.0,"decimals":0},"spatial":false,"hold_only":false,"three_d_only":false,"two_d_only":false,"shown_dims":0,"static_only":false},{"node":"Prop","uid":81,"match":"expansion","name":"Mask Expansion","value":{"t":"Scalar","v":0.0},"ui":{"kind":"Pixels"},"spatial":false,"hold_only":false,"three_d_only":false,"two_d_only":false,"shown_dims":0,"static_only":false}]}]},{"node":"Group","uid":6,"match":"effects","name":"Effects","kind":{"kind":"Plain"},"enabled":true,"children":[{"node":"Group","uid":26,"match":"ec.distort.warpstabilizer","name":"Warp Stabilizer","kind":{"kind":"Effect","effect":"ec.distort.warpstabilizer"},"enabled":true,"children":[{"node":"Group","uid":28,"match":"stabilization","name":"Stabilization","kind":{"kind":"Plain"},"enabled":true,"children":[{"node":"Prop","uid":27,"match":"result","name":"Result","value":{"t":"Enum","v":0},"ui":{"kind":"Popup","options":["Smooth Motion","No Motion"]},"spatial":false,"hold_only":true,"three_d_only":false,"two_d_only":false,"shown_dims":0,"static_only":false},{"node":"Prop","uid":29,"match":"smoothness","name":"Smoothness","value":{"t":"Scalar","v":50.0},"ui":{"kind":"Slider","min":0.0,"max":1000.0,"slider_min":0.0,"slider_max":100.0,"decimals":0},"spatial":false,"hold_only":false,"three_d_only":false,"two_d_only":false,"shown_dims":0,"static_only":false},{"node":"Prop","uid":30,"match":"mLine truncated
@@ -0,0 +1,8 @@
asset: analysed-0.24.ecproj
title: The tracked-0.22 clip with Time Remap, a mask, Gaussian Blur and Roto Brush, keyed by EffectCraft 0.24.1
author: arnav-hiwarkar
source: original work
license: MIT OR Apache-2.0
license-file: ../../../../../LICENSE-MIT
added: 2026-11-12 by arnav-hiwarkar
notes: Made from tracked-0.22.ecproj with 0.24.1 engine commands (enable Time Remap, a rectangle mask, Gaussian Blur and Roto Brush), its saved analyses replaced by short stand-in strings, and the Warp Stabilizer, 3D Camera Tracker and Roto Brush keys that 0.24.1 computed for it. Written as compact JSON. No media is needed: the tests only check that the keys are kept or cleared.
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,8 @@
asset: tracked-0.22.ecproj
title: One clip with an analysed Warp Stabilizer and 3D Camera Tracker from EffectCraft 0.22.0
author: arnav-hiwarkar
source: original work
license: MIT OR Apache-2.0
license-file: ../../../../../LICENSE-MIT
added: 2026-11-12 by arnav-hiwarkar
notes: Saved by the released 0.22.0 CLI after importing a generated 160x120, 12-frame shaking crop of an ffmpeg testsrc2 pattern, applying both effects and analysing them. The source path is a generic test path; the video is not needed by the tests, which only check that the saved analyses are kept or cleared.
@@ -0,0 +1,127 @@
//! Warp Stabilizer and 3D Camera Tracker analyses saved by an earlier release keep matching
//! their footage after an edit that doesn't change it (#3456), and a real change still clears them.
use effectcraft_effects::camera_tracker::{SOLVE, TRACKS, TRACKS_KEY};
use effectcraft_effects::warp_stab::{ANALYSIS, ANALYSIS_KEY};
use effectcraft_keyframe::Value;
use effectcraft_project::{ItemId, LayerId, Project};
use serde_json::json;
use crate::Session;
const FOOTAGE: ItemId = ItemId(1);
const COMP: ItemId = ItemId(2);
const CLIP: LayerId = LayerId(3);
const WARP: u64 = 26;
const TRACKER: u64 = 54;
/// The analysis (as its length and a hash: it's long) and key of the Warp Stabilizer and the
/// 3D Camera Tracker.
fn saved(s: &Session) -> [(usize, u64, String); 2] {
use std::hash::{Hash, Hasher};
let layer = s.project.comp(COMP).unwrap().layer(CLIP).unwrap();
let get = |uid: u64, data: &str, key: &str| {
let params = crate::camera_track::static_params(layer.props.find_group(uid).unwrap());
let text = |id: &str| match params.get(id) {
Some(Value::Str(s)) => s.clone(),
other => panic!("{id}: {other:?}"),
};
let analysis = text(data);
let mut h = std::collections::hash_map::DefaultHasher::new();
analysis.hash(&mut h);
(analysis.len(), h.finish(), text(key))
};
[get(WARP, ANALYSIS, ANALYSIS_KEY), get(TRACKER, TRACKS, TRACKS_KEY)]
}
fn open(json: &str) -> Session {
let mut s = Session::default();
s.replace_project(Project::from_json(json).unwrap(), None);
s.open_comp(COMP);
s
}
#[test]
fn analyses_saved_by_0_22_survive_edits_that_keep_their_frames() {
// Saved by the released 0.22.0 CLI after analysing both effects; its footage is offline here.
let mut s = open(include_str!("fixtures/tracked-0.22.ecproj"));
let before = saved(&s);
let layer = s.project.comp(COMP).unwrap().layer(CLIP).unwrap();
for (len, _, key) in &before {
assert!(*len > 0);
// The key predates Footage::placed_page, so it isn't today's signature.
assert_ne!(key, &crate::analysis::frames_key::signature(&s.project, COMP, layer));
}
// Adding to the render queue edits the project, as `effectcraft-cli render` does.
s.execute_checked("renderQueue.add", json!({"comp": COMP.0, "format": "png", "output": "frame.png"})).unwrap();
assert_eq!(saved(&s), before);
s.execute_checked("edit.undo", json!({})).unwrap();
assert_eq!(saved(&s), before);
// Saved and reopened (by this version), the old keys are kept and still match.
let mut s = open(&s.project.to_json());
s.execute_checked("renderQueue.add", json!({"comp": COMP.0, "format": "png", "output": "frame.png"})).unwrap();
assert_eq!(saved(&s), before);
// Other frames, from other timing or a reinterpreted footage item: both analyses are
// cleared, and undo brings them back.
let cleared = |s: &Session| saved(s).iter().all(|(len, _, key)| *len == 0 && key.is_empty());
s.execute_checked("layer.timing", json!({"layer": CLIP.0, "out": 0.5})).unwrap();
assert!(cleared(&s));
s.execute_checked("edit.undo", json!({})).unwrap();
assert_eq!(saved(&s), before);
s.execute_checked("file.interpretFootage", json!({"items": [FOOTAGE.0], "invertAlpha": true})).unwrap();
assert!(cleared(&s));
s.execute_checked("edit.undo", json!({})).unwrap();
assert_eq!(saved(&s), before);
// Footage framed as a placed page has other frames too, though 0.22 had no such field.
s.edit("place page", None, |p, _| {
if let Some(effectcraft_project::ItemKind::Footage(f)) = p.item_mut(FOOTAGE).map(|i| &mut i.kind) {
f.placed_page = true;
}
Ok(())
})
.unwrap();
assert!(cleared(&s));
}
/// Solving again reuses the 0.22 tracks rather than tracking the (here offline) footage again.
#[test]
fn camera_tracker_solves_again_from_tracks_saved_by_0_22() {
let mut s = open(include_str!("fixtures/tracked-0.22.ecproj"));
let tracks = saved(&s)[1].clone();
let solve = |s: &Session| {
let g = s.project.comp(COMP).unwrap().layer(CLIP).unwrap().props.find_group(TRACKER).unwrap();
crate::camera_track::static_params(g).get(SOLVE).cloned().unwrap()
};
// Another solve method, and back, clears the solve and keeps the tracks.
for method in [1, 0] {
s.execute_checked("prop.set", json!({"layer": CLIP.0, "path": "effects/#2/advanced/solveMethod", "value": method})).unwrap();
}
assert_eq!(solve(&s), Value::Str(String::new()));
assert_eq!(saved(&s)[1], tracks);
s.execute_checked("camera.analyze", json!({"layer": CLIP.0, "effect": TRACKER, "wait": true})).unwrap();
assert!(matches!(solve(&s), Value::Str(v) if !v.is_empty()));
assert_eq!(saved(&s)[1], tracks);
}
/// The footage text analysis keys are hashed from, as 0.23 saved it. A new `Footage` field must
/// not change it (or every saved analysis is dropped again).
#[test]
fn footage_signature_text_is_pinned() {
use effectcraft_project::{Footage, FootageKind};
let f = Footage {
path: "clip.mp4".into(),
kind: FootageKind::Video,
width: 160,
height: 120,
invert_alpha: true,
page: 2,
placed_page: true,
..Footage::default()
};
let fields = r#"path: "clip.mp4", kind: Video, width: 160, height: 120, pixel_aspect: 1.0, frame_rate: FrameRate { num: 30, den: 1 }, native_rate: None, duration: Tick(0), has_video: false, has_audio: false, alpha: Straight, premul_color: [0.0, 0.0, 0.0], loop_count: 1, codec: "", missing: false, sequence: [], color_profile: None, layer: None, fields: Off, invert_alpha: true, linear_light: false, preserve_rgb: false, cineon: CineonSettings { log_conversion: false, converted_black: 0.0, converted_white: 1023.0, black: 95.0, white: 685.0, gamma: 1.7, rolloff: 20.0, units: TenBit }, data: None, page: 2, alphabetical: false, start_timecode: None, file_timecode: None, markers: []"#;
assert_eq!(crate::analysis::frames_key::legacy::footage_text(&f, false, true), format!("Footage {{ {fields}, placed_page: true }}"));
assert_eq!(crate::analysis::frames_key::legacy::footage_text(&f, false, false), format!("Footage {{ {fields} }}"));
}
+188
View File
@@ -0,0 +1,188 @@
//! A LUT file that changes on disk renders again (#3493): Apply Color LUT and Lumetri's Input
//! LUT name a `.cube` file; an edit to it, or a file created, deleted or repaired, shows on the
//! next render of the same frame, from warm layer caches in memory and on disk, through a precomp
//! and a layer reading that precomp, and a frame kept on disk made with the old file is refused.
use std::path::Path;
use std::time::{Duration, UNIX_EPOCH};
use serde_json::{Value, json};
use crate::Session;
use crate::render::RenderOpts;
use effectcraft_project::ItemId;
use effectcraft_render::disk_cache::{DiskCache, comp_content_key, frame_key};
use effectcraft_render::reads::ReadLog;
use effectcraft_time::Tick;
/// Every input to black, or to white (1D, two entries: the same size, so only the modification
/// time tells the two apart).
const BLACK: &str = "LUT_1D_SIZE 2\n0 0 0\n0 0 0\n";
const WHITE: &str = "LUT_1D_SIZE 2\n1 1 1\n1 1 1\n";
const GREY: f32 = 128.0 / 255.0;
/// Write `text` to `path` with its modification time `secs` after the epoch.
fn write(path: &Path, text: &str, secs: u64) {
std::fs::write(path, text).unwrap();
let f = std::fs::File::options().write(true).open(path).unwrap();
f.set_modified(UNIX_EPOCH + Duration::from_secs(secs)).unwrap();
}
/// A session, its layer buffers written to a disk cache in `disk` when given.
fn session(disk: Option<&Path>) -> Session {
let mut s = Session::default();
if let Some(dir) = disk {
s.execute_checked("prefs.set", json!({"values": {"disk.diskCacheFolder": dir.to_string_lossy(), "disk.diskCacheEnabled": true}})).unwrap();
s.disk_cache.as_ref().unwrap().set_min_layer_ms(0);
}
s
}
/// Comp "Grade": a grey solid graded by `effect` (`params` set on it). Comp "Shot" shows it as a
/// precomp layer, under a solid that copies the precomp's channels (Set Channels): that layer is
/// cached with what the precomp shows. Returns (Grade, Shot).
fn shot(s: &mut Session, effect: &str, params: &[(&str, Value)]) -> (ItemId, ItemId) {
s.execute_checked("comp.new", json!({"name": "Shot", "width": 8, "height": 8, "frameRate": 24, "duration": 1})).unwrap();
let shot = s.active_comp_id().unwrap();
let plate = s.execute_checked("layer.newSolid", json!({"name": "Plate", "color": "#808080", "width": 8, "height": 8})).unwrap()["layer"].clone();
s.execute_checked("effect.apply", json!({"layer": plate, "effect": effect})).unwrap();
for (path, value) in params {
s.execute_checked("prop.set", json!({"layer": plate, "path": format!("effects/#1/{path}"), "value": value})).unwrap();
}
let pre = s.execute_checked("layer.precompose", json!({"layers": [plate], "name": "Grade"})).unwrap();
let grade = ItemId(pre["comp"].as_u64().unwrap());
let copy = s.execute_checked("layer.newSolid", json!({"name": "Copy", "color": "#00ff00", "width": 8, "height": 8})).unwrap()["layer"].clone();
s.execute_checked("effect.apply", json!({"layer": copy, "effect": "Set Channels"})).unwrap();
for i in 1..=3 {
s.execute_checked("prop.set", json!({"layer": copy, "path": format!("effects/#1/sourceLayer{i}"), "value": pre["layer"]})).unwrap();
}
(grade, shot)
}
/// The red and green of the centre of both comps' first frame.
fn colours(s: &Session, (grade, shot): (ItemId, ItemId)) -> [f32; 4] {
let at = |comp| {
let img = s.render(comp, Tick::ZERO, RenderOpts::default());
img.get(i64::from(img.width / 2), i64::from(img.height / 2))
};
let (g, c) = (at(grade), at(shot));
[g[0], g[1], c[0], c[1]]
}
#[track_caller]
fn assert_all(got: [f32; 4], want: f32) {
assert!(got.iter().all(|v| (v - want).abs() < 0.01), "{got:?}, want {want}");
}
#[test]
fn an_edited_lut_file_renders_again_from_warm_caches() {
let dir = tempfile::tempdir().unwrap();
let lut = dir.path().join("grade.cube");
write(&lut, BLACK, 1_000);
let mut s = session(None);
let comps = shot(&mut s, "Apply Color LUT", &[("lut", json!(lut.to_string_lossy()))]);
assert_all(colours(&s, comps), 0.0);
let misses = s.layer_cache.stats().misses;
assert_all(colours(&s, comps), 0.0);
assert_eq!(s.layer_cache.stats().misses, misses, "an unchanged file keeps the cached layers");
// A frame on disk made with the file names it.
let frames = DiskCache::open(dir.path().join("frames"), 1 << 30).unwrap();
let key = frame_key(comp_content_key(&s.project, comps.1), 0, 1000, 0);
let log = ReadLog::new();
let mut r = s.renderer(RenderOpts::default());
r.reads = Some(&log);
let _ = r.comp_frame(comps.1, Tick::ZERO);
let files = log.into_files();
assert!(files.get(&lut.to_string_lossy()).is_some(), "the render notes the LUT file: {files:?}");
frames.put_frame_now(key, 1, 1, &[0; 4], &files);
assert!(frames.get_frame(key, None).is_some());
let generation = effectcraft_effects::lut_generation();
write(&lut, WHITE, 2_000);
assert_all(colours(&s, comps), 1.0);
assert!(effectcraft_effects::lut_generation() > generation, "the viewer's frames made before are dropped");
assert!(frames.get_frame(key, None).is_none(), "the frame on disk made with the old file");
}
#[test]
fn an_edited_lut_file_is_not_served_from_the_disk_cache() {
let dir = tempfile::tempdir().unwrap();
let (lut, disk) = (dir.path().join("grade.cube"), dir.path().join("cache"));
write(&lut, BLACK, 1_000);
let mut s = session(Some(&disk));
let comps = shot(&mut s, "Apply Color LUT", &[("lut", json!(lut.to_string_lossy()))]);
assert_all(colours(&s, comps), 0.0);
let dc = s.disk_cache.clone().unwrap();
dc.flush();
assert!(dc.stats().entries > 0, "layer buffers written");
let project = s.project.clone();
drop((s, dc));
// A restart on the same cache, after the file changed.
write(&lut, WHITE, 2_000);
let mut s = session(Some(&disk));
s.project = project;
s.bump();
assert_all(colours(&s, comps), 1.0);
}
#[test]
fn a_lut_file_created_deleted_or_repaired_renders_again() {
let dir = tempfile::tempdir().unwrap();
let lut = dir.path().join("later.cube");
let mut s = session(None);
let comps = shot(&mut s, "Apply Color LUT", &[("lut", json!(lut.to_string_lossy()))]);
assert_all(colours(&s, comps), GREY);
write(&lut, WHITE, 1_000);
assert_all(colours(&s, comps), 1.0);
std::fs::remove_file(&lut).unwrap();
assert_all(colours(&s, comps), GREY);
write(&lut, "not a LUT", 2_000);
assert_all(colours(&s, comps), GREY);
write(&lut, BLACK, 3_000);
assert_all(colours(&s, comps), 0.0);
}
#[test]
fn lumetri_follows_its_input_lut_file() {
let dir = tempfile::tempdir().unwrap();
let lut = dir.path().join("input.cube");
write(&lut, BLACK, 1_000);
let mut s = session(None);
let comps = shot(&mut s, "Lumetri Color", &[("basicCorrection/inputLut", json!(1)), ("basicCorrection/inputLutFile", json!(lut.to_string_lossy()))]);
assert_all(colours(&s, comps), 0.0);
write(&lut, WHITE, 2_000);
assert_all(colours(&s, comps), 1.0);
}
/// A precomp instance whose Essential Property names another LUT file follows that file, also
/// for a layer that reads the instance through a layer parameter.
#[test]
fn an_overridden_lut_file_renders_again() {
let dir = tempfile::tempdir().unwrap();
let (base, overridden) = (dir.path().join("base.cube"), dir.path().join("override.cube"));
write(&base, WHITE, 1_000);
write(&overridden, BLACK, 1_000);
let mut s = session(None);
s.execute_checked("comp.new", json!({"name": "Grade", "width": 8, "height": 8, "frameRate": 24, "duration": 1})).unwrap();
let grade = s.active_comp_id().unwrap();
let plate = s.execute_checked("layer.newSolid", json!({"name": "Plate", "color": "#808080", "width": 8, "height": 8})).unwrap()["layer"].clone();
s.execute_checked("effect.apply", json!({"layer": plate, "effect": "Apply Color LUT"})).unwrap();
s.execute_checked("prop.set", json!({"layer": plate, "path": "effects/#1/lut", "value": base.to_string_lossy()})).unwrap();
let control = s.execute_checked("essential.addProperty", json!({"layer": plate, "path": "effects/#1/lut", "name": "LUT"})).unwrap()["controls"][0].clone();
s.execute_checked("comp.new", json!({"name": "Shot", "width": 8, "height": 8, "frameRate": 24, "duration": 1})).unwrap();
let shot = s.active_comp_id().unwrap();
let instance = s.execute_checked("layer.addItem", json!({"item": grade.0})).unwrap()["layer"].clone();
s.execute_checked("essential.set", json!({"layer": instance, "control": control, "value": overridden.to_string_lossy()})).unwrap();
let copy = s.execute_checked("layer.newSolid", json!({"name": "Copy", "color": "#00ff00", "width": 8, "height": 8})).unwrap()["layer"].clone();
s.execute_checked("effect.apply", json!({"layer": copy, "effect": "Set Channels"})).unwrap();
for i in 1..=3 {
s.execute_checked("prop.set", json!({"layer": copy, "path": format!("effects/#1/sourceLayer{i}"), "value": instance})).unwrap();
}
let centre = |s: &Session| {
let img = s.render(shot, Tick::ZERO, RenderOpts::default());
let p = img.get(i64::from(img.width / 2), i64::from(img.height / 2));
[p[0], p[1], p[0], p[1]]
};
assert_all(centre(&s), 0.0);
write(&overridden, WHITE, 2_000);
assert_all(centre(&s), 1.0);
}
+19
View File
@@ -96,6 +96,25 @@ fn imported_files_go_into_the_comp_where_they_were_dropped() {
assert!(s.execute("layer.addItem", json!({"item": "a.png", "position": [1.0]})).is_err(), "position needs x and y");
}
/// What an import left out of a file (a 3D model's textures over the limits) comes back in the
/// import's `warnings`.
#[test]
fn what_an_import_left_out_is_a_warning() {
use effectcraft_project::{Footage, FootageKind};
struct Probe;
impl crate::Importer for Probe {
fn probe(&self, path: &str) -> Result<Footage, String> {
Ok(Footage { path: path.into(), kind: FootageKind::Model, ..Default::default() })
}
fn probe_noting(&self, path: &str) -> Result<(Footage, Option<String>), String> {
Ok((self.probe(path)?, Some(format!("{path}: texture `a.png` left out"))))
}
}
let mut s = Session { importer: Some(std::sync::Arc::new(Probe)), ..Default::default() };
let r = s.execute("file.import", json!({"paths": ["/m/scene.obj"]})).unwrap();
assert_eq!(r["warnings"], json!(["/m/scene.obj: texture `a.png` left out"]));
}
/// #270: files dropped or picked in the Import dialog (`file.import {background}`) are probed in
/// a background job that says which file it is reading and how many are left; then they arrive
/// in one undo step, all selected, with a count. The same file imported again arrives again.
+25
View File
@@ -1581,3 +1581,28 @@ fn a_typed_component_moves_its_follow_components_by_each_layers_own_change() {
let keys: Vec<Vec<f64>> = prop(&s, b, "audio/levels").keys.iter().map(|k| k.value.components()).collect();
assert_eq!(keys, vec![vec![-20.0, -30.0], vec![-4.0, -34.0]], "B's 1 s key rises 6 dB on both channels");
}
#[test]
fn convert_expression_to_keyframes_refuses_a_layer_of_millions_of_frames() {
let (mut s, l) = setup();
s.execute("prop.setExpression", json!({"layer": l, "path": "transform/rotation", "expression": "value"})).unwrap();
// A saved Out point a million seconds after the In point.
let cid = s.active_comp_id().unwrap();
std::sync::Arc::make_mut(&mut s.project).comp_mut(cid).unwrap().layer_mut(effectcraft_project::LayerId(l)).unwrap().out_point =
effectcraft_time::Tick::from_seconds_f64(1e6);
let e = s.execute("prop.convertExpressionToKeyframes", json!({"layer": l, "path": "transform/rotation"})).unwrap_err().to_string();
assert!(e.contains("at most"), "{e}");
assert!(prop(&s, l, "transform/rotation").keys.is_empty());
}
#[test]
fn convert_expression_to_keyframes_refuses_a_zero_frame_duration() {
let (mut s, l) = setup();
s.execute("prop.setExpression", json!({"layer": l, "path": "transform/rotation", "expression": "value"})).unwrap();
// A saved frame rate of 0/1 s has a frame duration of 0: the sampling loop never advanced.
let cid = s.active_comp_id().unwrap();
std::sync::Arc::make_mut(&mut s.project).comp_mut(cid).unwrap().frame_rate.den = 0;
let e = s.execute("prop.convertExpressionToKeyframes", json!({"layer": l, "path": "transform/rotation"})).unwrap_err().to_string();
assert!(e.contains("frame duration"), "{e}");
assert!(prop(&s, l, "transform/rotation").keys.is_empty());
}