FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Timeline: Show Duplicate Frame Markers marks media frames used more than once
dotCooCoo9952c31e6b04
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rsindex 580098090..4a1aed9a6 100644--- a/crates/engine/src/lib.rs+++ b/crates/engine/src/lib.rs@@ -385,6 +385,10 @@ pub struct EditorState {/// Sequence ▸ Show Through Edits: the timeline marks cuts between continuous pieces of a clip.#[serde(default)]pub show_through_edits: bool,+ /// Timeline Display Settings ▸ Show Duplicate Frame Markers: a stripe along the bottom of a+ /// clip under the media frames another clip also shows.+ #[serde(default)]+ pub show_duplicate_frame_markers: bool,/// Markers ▸ Ripple Sequence Markers: ripple edits move (and delete) sequence markers too.#[serde(default)]pub ripple_sequence_markers: bool,diff --git a/crates/engine/src/sequence_tools.rs b/crates/engine/src/sequence_tools.rsindex 90716d2fc..980e571c1 100644--- a/crates/engine/src/sequence_tools.rs+++ b/crates/engine/src/sequence_tools.rs@@ -10,6 +10,8 @@//! | `sequence.showThroughEdits` | Sequence ▸ Show Through Edits | |//! | `sequence.joinThroughEdits` | (clip and edit point context menus) Join Through Edits | |//! | `sequence.throughEdits` | query: the through edits of the active sequence | |+//! | `sequence.showDuplicateFrameMarkers` | (Timeline Display Settings) Show Duplicate Frame Markers | |+//! | `sequence.duplicateFrames` | query: the duplicate frame markers of the active sequence | |//! | `sequence.makeSubsequence` | Sequence ▸ Make Subsequence | Shift+U |//! | `sequence.deleteTracks` | Sequence ▸ Delete Tracks… | |//! | `markers.markSplitVideoIn` … `markers.markSplitAudioOut` | Markers ▸ Mark Split ▸ Video In … Audio Out | |@@ -26,9 +28,12 @@//! that side. Insert / Overwrite from the Source monitor honour source split points: each channel//! takes its own range and lands offset by the difference of the In points (J- and L-cuts).+use std::collections::{BTreeMap, HashMap, HashSet};+use filmcraft_edit as edit;-use filmcraft_project::{AudioChannels, ClipId, ItemId, Label, Marker, MarkerId, MarkerKind, SplitMarks, TrackId, TrackItem, TrackKind};-use filmcraft_time::{Tick, TimeRange};+use filmcraft_media::MediaKind;+use filmcraft_project::{AudioChannels, ClipId, ItemId, Label, Marker, MarkerId, MarkerKind, Project, Sequence, SplitMarks, TrackId, TrackItem, TrackKind};+use filmcraft_time::{FrameRate, Tick, TimeRange};use serde_json::{Value, json};use crate::commands::{@@ -105,6 +110,22 @@ fn groups() -> Vec<(&'static str, Vec<CommandSpec>)> {s.state.show_through_edits = bool_p(p, "on").unwrap_or(!s.state.show_through_edits);Ok(json!({"showThroughEdits": s.state.show_through_edits}))}),+ spec("sequence.showDuplicateFrameMarkers", "Show Duplicate Frame Markers", &[], None, r#"{"on":bool?}"#, always, |s, p| {+ s.state.show_duplicate_frame_markers = bool_p(p, "on").unwrap_or(!s.state.show_duplicate_frame_markers);+ Ok(json!({"showDuplicateFrameMarkers": s.state.show_duplicate_frame_markers}))+ }),+ query("sequence.duplicateFrames", "List Duplicate Frames", "{}", |s, _| {+ let q = s.active_sequence().ok_or(EngineError::NoSequence)?;+ Ok(Value::Array(+ duplicate_frames(&s.project, q)+ .iter()+ .map(|d| {+ let ranges: Vec<Value> = d.ranges.iter().map(|r| json!({"start": r.start.0, "end": r.end().0})).collect();+ json!({"clip": d.clip.0, "color": d.color, "ranges": ranges})+ })+ .collect(),+ ))+ }),spec("sequence.joinThroughEdits","Join Through Edits",@@ -376,6 +397,110 @@ fn join_through_edit_at(s: &mut Session, cut: &Value) -> Result<Value> {Ok(json!({"joined": n}))}+// ---------- duplicate frames ----------++/// How many colors duplicate frame markers use; master clips past the last one share it.+pub const DUPLICATE_FRAME_COLORS: usize = 10;++/// One clip's duplicate frame markers: where on the timeline it shows media frames that another+/// video clip of the same sequence also shows.+#[derive(Clone, Debug, PartialEq, Eq)]+pub struct DuplicateFrames {+ pub clip: ClipId,+ /// The color of the clip's master clip, 0 to [`DUPLICATE_FRAME_COLORS`] - 1: master clips with+ /// duplicate frames are numbered in the order they first appear in the sequence.+ pub color: usize,+ /// Timeline ranges inside the clip, in order and apart from each other.+ pub ranges: Vec<TimeRange>,+}++/// The most timeline frames [`duplicate_frames`] compares in one sequence. A clip whose frames+/// would pass that count, in timeline order, is not compared and gets no markers, and later clips+/// that still fit are compared.+pub const MAX_DUPLICATE_FRAME_CHECKS: i64 = 1_000_000;++/// Timeline Display Settings ▸ Show Duplicate Frame Markers: the video clips of `q` that show a+/// media frame another video clip of `q` also shows. Each frame of the sequence is compared by the+/// media frame the clip shows there ([`TrackItem::source_time_at`] at the frame's start, counted in+/// the media's frame rate). A subclip counts as its master clip. Clips of still images,+/// generators, nested sequences, graphics and adjustment layers, frame holds and clips whose Time+/// Remapping speed has keyframes get no markers and are not compared.+pub fn duplicate_frames(project: &Project, q: &Sequence) -> Vec<DuplicateFrames> {+ let rate = q.settings.frame_rate;+ // every clip that can be compared, with its master clip and the media frame rate, in timeline+ // order (track order for clips that start together)+ let mut clips: Vec<(u64, FrameRate, &TrackItem)> =+ q.video_tracks.iter().flat_map(|tr| &tr.items).filter_map(|it| comparable_master(project, it).map(|(m, r)| (m.0, r, it))).collect();+ clips.sort_by_key(|(_, _, it)| it.start);+ // the sequence frames each clip covers, while the limit allows+ let mut budget = MAX_DUPLICATE_FRAME_CHECKS;+ let spans: Vec<Option<(i64, i64)>> = clips+ .iter()+ .map(|(_, _, it)| {+ let first = rate.frame_at(it.start);+ let first = if rate.tick_of(first) < it.start { first.saturating_add(1) } else { first };+ let last = rate.frame_at(it.end() - Tick(1));+ let n = last.saturating_sub(first).saturating_add(1);+ (n > 0 && n <= budget).then(|| {+ budget -= n;+ (first, last)+ })+ })+ .collect();+ let shows = |media_rate: FrameRate, it: &TrackItem, f: i64| media_rate.frame_at(it.source_time_at(rate.tick_of(f)));+ // (master clip, media frame) → the first clip that shows it, and whether another clip does too+ let mut seen: HashMap<(u64, i64), (ClipId, bool)> = HashMap::new();+ for ((m, media_rate, it), span) in clips.iter().zip(&spans) {+ let Some((first, last)) = *span else { continue };+ for f in first..=last {+ let e = seen.entry((*m, shows(*media_rate, it, f))).or_insert((it.id, false));+ e.1 |= e.0 != it.id;+ }+ }+ // colors go to the master clips with a repeated frame, in the order they first appear+ let repeated: HashSet<u64> = seen.iter().filter(|(_, e)| e.1).map(|((m, _), _)| *m).collect();+ let mut colors: BTreeMap<u64, usize> = BTreeMap::new();+ for (m, ..) in clips.iter().filter(|(m, ..)| repeated.contains(m)) {+ let next = colors.len().min(DUPLICATE_FRAME_COLORS - 1);+ colors.entry(*m).or_insert(next);+ }+ let mut out = Vec::new();+ for ((m, media_rate, it), span) in clips.iter().zip(&spans) {+ let Some((first, last)) = *span else { continue };+ let mut ranges: Vec<TimeRange> = Vec::new();+ let mut run: Option<i64> = None;+ for f in first..=last.saturating_add(1) {+ let repeated = f <= last && seen.get(&(*m, shows(*media_rate, it, f))).is_some_and(|e| e.1);+ match (repeated, run) {+ (true, None) => run = Some(f),+ (false, Some(from)) => {+ let (a, b) = (rate.tick_of(from).max(it.start), rate.tick_of(f).min(it.end()));+ ranges.push(TimeRange::new(a, b - a));+ run = None;+ }+ _ => {}+ }+ }+ if !ranges.is_empty() {+ out.push(DuplicateFrames { clip: it.id, color: colors.get(m).copied().unwrap_or(0), ranges });+ }+ }+ out+}++/// The master clip `it` shows frames of and the master clip's frame rate, when its frames can be+/// compared.+fn comparable_master(project: &Project, it: &TrackItem) -> Option<(ItemId, FrameRate)> {+ if it.frame_hold.is_some() || !(it.speed.is_finite() && it.speed.abs() > 0.0) || it.duration <= Tick::ZERO {+ return None;+ }+ if it.effect("time_remap").and_then(|e| e.param("speed")).is_some_and(|p| p.is_animated()) {+ return None;+ }+ let (master, media, _) = project.resolve_media(it.item)?;+ (matches!(media.info.kind, MediaKind::Movie | MediaKind::ImageSequence) && media.info.video.is_some()).then(|| (master, media.frame_rate()))+}+// ---------- subsequence ----------/// Sequence ▸ Make Subsequence: a new sequence (same settings and track layout) holding copies of thediff --git a/crates/engine/src/sequence_tools_tests.rs b/crates/engine/src/sequence_tools_tests.rsindex 8f1ae2d4d..74398a6a4 100644--- a/crates/engine/src/sequence_tools_tests.rs+++ b/crates/engine/src/sequence_tools_tests.rs@@ -142,6 +142,171 @@ fn through_edits_show_and_join() {assert_eq!(s.execute("sequence.throughEdits", json!({})).unwrap().as_array().unwrap().len(), n - 2);}+/// The demo project with a new empty sequence active, and its first two movie items.+fn demo_with_empty_sequence() -> (Session, u64, u64) {+ let mut s = demo();+ let mut movies: Vec<u64> = s+ .project+ .items+ .values()+ .filter(|i| i.as_media().is_some_and(|m| m.info.kind == filmcraft_media::MediaKind::Movie && m.info.video.is_some()))+ .map(|i| i.id.0)+ .collect();+ movies.sort();+ s.execute("file.newSequence", json!({"name": "Duplicates"})).unwrap();+ (s, movies[0], movies[1])+}++/// The video clip on video track `track` (0 = V1) that starts at `frame`.+fn video_clip_at(s: &Session, track: usize, frame: i64) -> u64 {+ let start = f(s, frame);+ s.active_sequence().unwrap().video_tracks[track].items.iter().find(|c| c.start == start).unwrap().id.0+}++fn clip_duration(s: &Session, clip: u64) -> Tick {+ s.active_sequence().unwrap().find_item(ClipId(clip)).unwrap().1.duration+}++/// `sequence.duplicateFrames` as (clip, color, [(start frame, end frame)]).+fn duplicates(s: &mut Session) -> Vec<(u64, u64, Vec<(i64, i64)>)> {+ let frame = f(s, 1).0;+ let r = s.execute("sequence.duplicateFrames", json!({})).unwrap();+ r.as_array()+ .unwrap()+ .iter()+ .map(|d| {+ let ranges = d["ranges"].as_array().unwrap().iter().map(|r| (r["start"].as_i64().unwrap() / frame, r["end"].as_i64().unwrap() / frame)).collect();+ (d["clip"].as_u64().unwrap(), d["color"].as_u64().unwrap(), ranges)+ })+ .collect()+}++#[test]+fn duplicate_frame_markers_cover_the_repeated_frames() {+ let (mut s, forest, other) = demo_with_empty_sequence();+ assert_eq!(s.execute("sequence.showDuplicateFrameMarkers", json!({})).unwrap()["showDuplicateFrameMarkers"], json!(true));+ assert_eq!(s.execute("sequence.showDuplicateFrameMarkers", json!({"on": false})).unwrap()["showDuplicateFrameMarkers"], json!(false));+ // media frames 0–48 at 0, media frames 24–72 at 100: frames 24–48 are shown twice+ place(&mut s, forest, "V1", 0, 0, 48);+ place(&mut s, forest, "V1", 100, 24, 48);+ // another master clip, used once+ place(&mut s, other, "V2", 0, 0, 48);+ // a generator used twice has no markers+ let matte = s.execute("file.newColorMatte", json!({"width": 64, "height": 64, "color": "#ff0000"})).unwrap()["item"].as_u64().unwrap();+ s.execute("timeline.place", json!({"item": matte, "track": "V2", "frame": 200, "duration": f(&s, 24).0})).unwrap();+ s.execute("timeline.place", json!({"item": matte, "track": "V2", "frame": 300, "duration": f(&s, 24).0})).unwrap();+ let (a, b) = (video_clip_at(&s, 0, 0), video_clip_at(&s, 0, 100));+ assert_eq!(duplicates(&mut s), [(a, 0, vec![(24, 48)]), (b, 0, vec![(100, 124)])]);+ // the second master clip used again (frames 40–60 twice) takes the next color+ place(&mut s, other, "V2", 400, 40, 20);+ place(&mut s, other, "V3", 400, 40, 20);+ let (c, d, e) = (video_clip_at(&s, 1, 0), video_clip_at(&s, 1, 400), video_clip_at(&s, 2, 400));+ assert_eq!(+ duplicates(&mut s),+ [(a, 0, vec![(24, 48)]), (c, 1, vec![(40, 48)]), (b, 0, vec![(100, 124)]), (d, 1, vec![(400, 420)]), (e, 1, vec![(400, 420)])]+ );+ // clips that only touch in the media share no frame+ s.execute("edit.undo", json!({})).unwrap();+ s.execute("edit.undo", json!({})).unwrap();+ place(&mut s, forest, "V3", 500, 72, 24);+ assert_eq!(duplicates(&mut s), [(a, 0, vec![(24, 48)]), (b, 0, vec![(100, 124)])]);+}++/// Only master clips with duplicate frames take a color: a master clip used once ahead of a+/// duplicated one leaves the first color to the duplicated one.+#[test]+fn duplicate_frame_markers_color_only_master_clips_with_duplicates() {+ let (mut s, forest, other) = demo_with_empty_sequence();+ place(&mut s, other, "V1", 0, 0, 48);+ place(&mut s, forest, "V1", 100, 0, 24);+ place(&mut s, forest, "V1", 200, 0, 24);+ let (a, b) = (video_clip_at(&s, 0, 100), video_clip_at(&s, 0, 200));+ assert_eq!(duplicates(&mut s), [(a, 0, vec![(100, 124)]), (b, 0, vec![(200, 224)])]);+}++#[test]+fn duplicate_frame_markers_follow_speed_reverse_and_holds() {+ let (mut s, forest, _) = demo_with_empty_sequence();+ place(&mut s, forest, "V1", 0, 0, 48);+ // at 200 % from media frame 24, timeline frames 100–112 show media frames 24, 26 … 46+ place(&mut s, forest, "V2", 100, 24, 24);+ let (a, b) = (video_clip_at(&s, 0, 0), video_clip_at(&s, 1, 100));+ let set = |s: &mut Session, clip: u64, change: fn(&mut filmcraft_project::TrackItem)| {+ s.edit_sequence("test", |q, _, _| {+ change(q.find_item_mut(ClipId(clip)).unwrap().1);+ Ok(())+ })+ .unwrap();+ };+ set(&mut s, b, |it| it.speed = 2.0);+ let every_other: Vec<(i64, i64)> = (24..48).step_by(2).map(|f| (f, f + 1)).collect();+ assert_eq!(duplicates(&mut s), [(a, 0, every_other), (b, 0, vec![(100, 112)])]);+ // reversed, 100 %: timeline frames 0–48 show media frames 47 down to 0, so 0–24 shows 24–48+ set(&mut s, b, |it| it.speed = 1.0);+ set(&mut s, a, |it| it.reverse = true);+ assert_eq!(duplicates(&mut s), [(a, 0, vec![(0, 24)]), (b, 0, vec![(100, 124)])]);+ // a frame hold and Time Remapping keyframes take a clip out of the comparison+ set(&mut s, a, |it| it.frame_hold = Some(it.source_in));+ assert!(duplicates(&mut s).is_empty());+ set(&mut s, a, |it| it.frame_hold = None);+ assert_eq!(duplicates(&mut s).len(), 2);+ // a clip longer than the comparison limit is skipped instead of walked frame by frame+ let dur = clip_duration(&s, a);+ set(&mut s, a, |it| it.duration = Tick(i64::MAX / 4));+ assert!(duplicates(&mut s).is_empty());+ s.edit_sequence("test", |q, _, _| {+ q.find_item_mut(ClipId(a)).unwrap().1.duration = dur;+ Ok(())+ })+ .unwrap();+ assert_eq!(duplicates(&mut s).len(), 2);+ set(&mut s, b, |it| {+ let p = it+ .effect_mut("time_remap")+ .unwrap()+ .params+ .entry("speed".into())+ .or_insert_with(|| filmcraft_project::Param::new(filmcraft_project::ParamValue::Float(100.0)));+ p.keyframes.push(filmcraft_project::Keyframe::new(Tick::ZERO, filmcraft_project::ParamValue::Float(100.0)));+ p.keyframes.push(filmcraft_project::Keyframe::new(Tick(1), filmcraft_project::ParamValue::Float(50.0)));+ });+ assert!(duplicates(&mut s).is_empty());+ // parameters of the wrong type are ignored: `on` that is not a boolean toggles+ s.state.show_duplicate_frame_markers = false;+ for p in [json!({"on": "yes"}), json!({"on": [1]}), json!(null), json!(7)] {+ let on = s.state.show_duplicate_frame_markers;+ assert_eq!(s.execute("sequence.showDuplicateFrameMarkers", p).unwrap()["showDuplicateFrameMarkers"], json!(!on));+ }+ assert!(s.execute("sequence.duplicateFrames", json!({"clips": "x", "ranges": -1})).is_ok());+ // without a sequence there is nothing to list+ s.state.active_sequence = None;+ assert!(s.execute("sequence.duplicateFrames", json!({})).is_err());+}++/// A clip at 200 % skips every other media frame: clips are compared by the frames they show,+/// not by the media between their In and Out.+#[test]+fn duplicate_frame_markers_compare_the_frames_a_fast_clip_shows() {+ let (mut s, forest, _) = demo_with_empty_sequence();+ assert_eq!(s.active_sequence().unwrap().settings.frame_rate, s.project.item(ItemId(forest)).unwrap().as_media().unwrap().frame_rate());+ // media frames 0, 2, 4 … 46 and 1, 3, 5 … 47: no frame in common+ place(&mut s, forest, "V1", 0, 0, 24);+ place(&mut s, forest, "V2", 0, 1, 24);+ let (even, odd) = (video_clip_at(&s, 0, 0), video_clip_at(&s, 1, 0));+ for c in [even, odd] {+ s.edit_sequence("test", |q, _, _| {+ q.find_item_mut(ClipId(c)).unwrap().1.speed = 2.0;+ Ok(())+ })+ .unwrap();+ }+ assert!(duplicates(&mut s).is_empty());+ // media frames 0 and 1 at 100 %: the even clip shows frame 0 at timeline frame 0+ place(&mut s, forest, "V3", 100, 0, 2);+ let slow = video_clip_at(&s, 2, 100);+ assert_eq!(duplicates(&mut s), [(even, 0, vec![(0, 1)]), (odd, 0, vec![(0, 1)]), (slow, 0, vec![(100, 102)])]);+}+/// `cut: [left, right]` (the timeline's edit point menu, #219) joins exactly that cut and its/// linked partner, even when one of its pieces is also part of another through edit.#[test]diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsvindex 76991909c..5482b6a04 100644--- a/crates/ui-egui/src/i18n/de.tsv+++ b/crates/ui-egui/src/i18n/de.tsv@@ -348,6 +348,7 @@Show Active Caption Tracks Only Nur aktive Untertitelspuren anzeigenShow All Caption Tracks Alle Untertitelspuren anzeigenShow All Marker Colors Alle Markerfarben anzeigen+ Show Duplicate Frame Markers Markierungen für doppelte Frames anzeigenShow Guides Hilfslinien anzeigenShow Rulers Lineale anzeigenShow Through Edits Durchgehende Schnitte anzeigendiff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsvindex b13e79d6e..0e2e2bb74 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -322,6 +322,7 @@Show Active Caption Tracks Only Mostrar solo pistas de subtítulos activasShow All Caption Tracks Mostrar todas las pistas de subtítulosShow All Marker Colors Mostrar todos los colores de marcador+ Show Duplicate Frame Markers Mostrar marcadores de fotogramas duplicadosShow Guides Mostrar guíasShow Rulers Mostrar reglasShow Through Edits Mostrar cortes continuosdiff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsvindex 6778b0322..0077c8662 100644--- a/crates/ui-egui/src/i18n/fr.tsv+++ b/crates/ui-egui/src/i18n/fr.tsv@@ -321,6 +321,7 @@Show Active Caption Tracks Only Afficher uniquement les pistes de sous-titres activesShow All Caption Tracks Afficher toutes les pistes de sous-titresShow All Marker Colors Afficher toutes les couleurs de marqueur+ Show Duplicate Frame Markers Afficher les marqueurs d'images en doubleShow Guides Afficher les repèresShow Rulers Afficher les règlesShow Through Edits Afficher les points de montage traversantsdiff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsvindex 8ffc4f5b3..500db2c7a 100644--- a/crates/ui-egui/src/i18n/id.tsv+++ b/crates/ui-egui/src/i18n/id.tsv@@ -326,6 +326,7 @@Show Active Caption Tracks Only Tampilkan Hanya Trek Takarir AktifShow All Caption Tracks Tampilkan Semua Trek TakarirShow All Marker Colors Tampilkan Semua Warna Penanda+ Show Duplicate Frame Markers Tampilkan Penanda Bingkai DuplikatShow Guides Tampilkan Garis BantuShow Rulers Tampilkan PenggarisShow Through Edits Tampilkan Edit Tembusdiff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsvindex ef02460c3..adfc59fb8 100644--- a/crates/ui-egui/src/i18n/it.tsv+++ b/crates/ui-egui/src/i18n/it.tsv@@ -316,6 +316,7 @@Show Active Caption Tracks Only Mostra solo le tracce sottotitoli attiveShow All Caption Tracks Mostra tutte le tracce sottotitoliShow All Marker Colors Mostra tutti i colori dei marcatori+ Show Duplicate Frame Markers Mostra marcatori dei fotogrammi duplicatiShow Guides Mostra guideShow Rulers Mostra righelliShow Through Edits Mostra tagli passantidiff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex eacaa51a2..4e4c55225 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -323,6 +323,7 @@Show Active Caption Tracks Only アクティブなキャプショントラックのみ表示Show All Caption Tracks すべてのキャプショントラックを表示Show All Marker Colors すべての色のマーカーを表示+ Show Duplicate Frame Markers 重複フレームマーカーを表示Show Guides ガイドを表示Show Rulers ルーラーを表示Show Through Edits スルー編集点を表示diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsvindex 73d5adf68..bcfe7f799 100644--- a/crates/ui-egui/src/i18n/ko.tsv+++ b/crates/ui-egui/src/i18n/ko.tsv@@ -2820,6 +2820,7 @@Show Audio Waveform 오디오 파형 표시Show Clip Mismatch Warning dialog 클립 불일치 경고 대화 상자 표시Show clip names 클립 이름 표시+ Show Duplicate Frame Markers 중복 프레임 마커 표시Show Dot 점 표시Show durations 길이 표시Show Event Indicator 이벤트 표시기 표시diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsvindex 7cbb49a58..d1bb7d835 100644--- a/crates/ui-egui/src/i18n/pt-br.tsv+++ b/crates/ui-egui/src/i18n/pt-br.tsv@@ -323,6 +323,7 @@Show Active Caption Tracks Only Mostrar apenas faixas de legendas ativasShow All Caption Tracks Mostrar todas as faixas de legendasShow All Marker Colors Mostrar todas as cores de marcador+ Show Duplicate Frame Markers Mostrar marcadores de quadros duplicadosShow Guides Mostrar guiasShow Rulers Mostrar réguasShow Through Edits Mostrar edições contíguasdiff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsvindex 08bf8c076..a0c4e2494 100644--- a/crates/ui-egui/src/i18n/ru.tsv+++ b/crates/ui-egui/src/i18n/ru.tsv@@ -310,6 +310,7 @@Show Active Caption Tracks Only Показать только активные дорожки субтитровShow All Caption Tracks Показать все дорожки субтитровShow All Marker Colors Показать все цвета маркеров+ Show Duplicate Frame Markers Показать маркеры повторяющихся кадровShow Guides Показать направляющиеShow Rulers Показать линейкиShow Through Edits Показать сквозные склейкиdiff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsvindex 99033017b..c2f119d21 100644--- a/crates/ui-egui/src/i18n/uk.tsv+++ b/crates/ui-egui/src/i18n/uk.tsv@@ -311,6 +311,7 @@Show Active Caption Tracks Only Показати лише активні доріжки субтитрівShow All Caption Tracks Показати всі доріжки субтитрівShow All Marker Colors Показати всі кольори маркерів+ Show Duplicate Frame Markers Показати маркери повторюваних кадрівShow Guides Показати напрямніShow Rulers Показати лінійкиShow Through Edits Показати розрізи без зміни кадруdiff --git a/crates/ui-egui/src/i18n/zh-cn.tsv b/crates/ui-egui/src/i18n/zh-cn.tsvindex 3e3e2f5bf..3badabf5b 100644--- a/crates/ui-egui/src/i18n/zh-cn.tsv+++ b/crates/ui-egui/src/i18n/zh-cn.tsv@@ -317,6 +317,7 @@Show Active Caption Tracks Only 仅显示活动字幕轨道Show All Caption Tracks 显示所有字幕轨道Show All Marker Colors 显示所有标记颜色+ Show Duplicate Frame Markers 显示重复帧标记Show Guides 显示参考线Show Rulers 显示标尺Show Through Edits 显示贯通编辑diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rsindex 3d59a0c6c..761dcdbc5 100644--- a/crates/ui-egui/src/panels/timeline.rs+++ b/crates/ui-egui/src/panels/timeline.rs@@ -13,6 +13,7 @@ use std::collections::HashMap;use std::sync::{Arc, Mutex};use egui::{Align2, Color32, CursorIcon, Pos2, Rect, Sense, Stroke, StrokeKind, pos2, vec2};+use filmcraft_engine::sequence_tools::{DuplicateFrames, duplicate_frames};use filmcraft_project::{ClipId, ItemId, MarkerId, Sequence, TrackId, TrackItem, TrackKind};use filmcraft_time::{FrameRate, TICKS_PER_SECOND, Tick, TimeDisplay, TimeRange, format_time};use serde_json::{Value, json};@@ -32,6 +33,20 @@ const DIVIDER_H: f32 = 5.0;const MASTER_H: f32 = 34.0;/// The selected gap between two clips (#648, #668).const GAP_FILL: Color32 = Color32::from_gray(224);+/// Duplicate frame marker colors, one per master clip with duplicate frames in the order they+/// appear in the sequence.+const DUPLICATE_FRAME_COLORS: [Color32; filmcraft_engine::sequence_tools::DUPLICATE_FRAME_COLORS] = [+ Color32::from_rgb(0xe8, 0x4a, 0x4a),+ Color32::from_rgb(0x3d, 0x9b, 0xe9),+ Color32::from_rgb(0x4c, 0xc2, 0x5a),+ Color32::from_rgb(0xf2, 0xc2, 0x2e),+ Color32::from_rgb(0xb0, 0x5c, 0xe0),+ Color32::from_rgb(0xf0, 0x8a, 0x2c),+ Color32::from_rgb(0x2c, 0xd4, 0xc8),+ Color32::from_rgb(0xec, 0x5e, 0xb0),+ Color32::from_rgb(0x9a, 0xcd, 0x32),+ Color32::from_rgb(0xf5, 0xf5, 0xf5),+];const SNAP_PX: f32 = 9.0;/// Waveform peaks are kept per audio stream: (item, index into the media's `audio_streams`).@@ -62,6 +77,26 @@ pub struct TlState {zoom_anchor: Option<(f64, f32)>,/// The zoom (points a second) the video thumbnails are laid out at while the view is zooming (#1094).thumb_pps: Option<f64>,+ /// Show Duplicate Frame Markers: the markers of a sequence, with the session revision, the+ /// sequence and the project they were worked out for.+ duplicates: Option<(DuplicatesKey, Arc<HashMap<ClipId, DuplicateFrames>>)>,+}++/// (session revision, sequence, project address)+type DuplicatesKey = (u64, ItemId, usize);++/// The duplicate frame markers of sequence `seq_id`, worked out again only after the project+/// changes.+fn duplicate_markers(app: &mut FilmcraftApp, seq_id: ItemId, seq: &Sequence) -> Arc<HashMap<ClipId, DuplicateFrames>> {+ let key = (app.session.revision, seq_id, Arc::as_ptr(&app.session.project) as usize);+ if let Some((k, d)) = &app.tl.duplicates+ && *k == key+ {+ return d.clone();+ }+ let d: Arc<HashMap<ClipId, DuplicateFrames>> = Arc::new(duplicate_frames(&app.session.project, seq).into_iter().map(|d| (d.clip, d)).collect());+ app.tl.duplicates = Some((key, d.clone()));+ d}impl TlState {@@ -502,6 +537,7 @@ pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {if copying {ctx.set_cursor_icon(CursorIcon::Copy);}+ let duplicates = if app.session.state.show_duplicate_frame_markers { duplicate_markers(app, seq_id, seq) } else { Arc::default() };for r in &rows {let Some(tr) = seq.track(r.track) else { continue };let clip_rect = if r.kind == TrackKind::Video { vclip } else { aclip };@@ -537,6 +573,14 @@ pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {if volume_line {super::timeline_volume::paint(&p, body, it);}+ // Show Duplicate Frame Markers: a stripe along the bottom under each repeated frame,+ // in the color of the clip's master clip+ if let Some(d) = duplicates.get(&it.id) {+ let col = DUPLICATE_FRAME_COLORS.get(d.color).or(DUPLICATE_FRAME_COLORS.last()).copied().unwrap_or(Color32::WHITE);+ // kept inside the clip while a trim drag shortens it+ let inside = p.with_clip_rect(body.intersect(p.clip_rect()));+ paint_duplicate_stripes(app, &inside, &layout, &d.ranges, start - it.start, (body.max.y - 3.0, body.max.y), visible, col, it.id);+ }app.auto.add(&format!("timeline.clip.{}", it.id.0), body.intersect(content), &it.name);// a nest that runs past the end of its sequence's contents: that part is emptyif !previews.contains_key(&it.id)@@ -804,6 +848,52 @@ fn paint_through_edit(p: &egui::Painter, x: f32, row: Rect) -> Rect {Rect::from_center_size(pos2(x, cy), vec2(2.0 * w + 2.0, 2.0 * h + 2.0))}+/// The duplicate frame stripes of one clip, between `ys`: its `ranges` (timeline ranges in order)+/// drawn `offset` later, as the clip is while it is dragged. Only the ranges in the `visible` time+/// and inside the painter's clip rect are drawn, and ranges a point or less apart are drawn as+/// one stripe; each stripe takes the automation id `timeline.duplicateFrames.<clip>.<n>`, `n`+/// being its first range.+#[allow(clippy::too_many_arguments)]+fn paint_duplicate_stripes(+ app: &mut FilmcraftApp,+ p: &egui::Painter,+ layout: &Layout,+ ranges: &[TimeRange],+ offset: Tick,+ ys: (f32, f32),+ visible: (Tick, Tick),+ col: Color32,+ clip: ClipId,+) {+ let first = ranges.partition_point(|r| r.end() + offset < visible.0);+ let mut stripe: Option<(usize, f32, f32)> = None;+ let flush = |app: &mut FilmcraftApp, s: (usize, f32, f32)| {+ let r = Rect::from_min_max(pos2(s.1, ys.0), pos2(s.2.max(s.1 + 1.0), ys.1));+ let shown = r.intersect(p.clip_rect());+ if shown.width() > 0.0 && shown.height() > 0.0 {+ p.rect_filled(r, 0.0, col);+ app.auto.add(&format!("timeline.duplicateFrames.{}.{}", clip.0, s.0), shown, "Duplicate frames");+ }+ };+ for (i, range) in ranges.iter().enumerate().skip(first) {+ if range.start + offset > visible.1 {+ break;+ }+ let (x0, x1) = (layout.x_of(range.start + offset), layout.x_of(range.end() + offset));+ stripe = match stripe {+ Some((n, a, b)) if x0 <= b + 1.0 => Some((n, a, b.max(x1))),+ Some(s) => {+ flush(app, s);+ Some((i, x0, x1))+ }+ None => Some((i, x0, x1)),+ };+ }+ if let Some(s) = stripe {+ flush(app, s);+ }+}+fn lighten(c: Color32, f: f32) -> Color32 {let l = |v: u8| (v as f32 + (255.0 - v as f32) * f).round() as u8;Color32::from_rgb(l(c.r()), l(c.g()), l(c.b()))@@ -1547,6 +1637,12 @@ fn draw_top(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect, seq: &Sequencif c.changed() {let _ = app.session.execute("sequence.showThroughEdits", json!({"on": te}));}+ let mut df = app.session.state.show_duplicate_frame_markers;+ let c = ui.checkbox(&mut df, tl!("Show Duplicate Frame Markers"));+ app.auto.add("timeline.settings.showDuplicateFrameMarkers", c.rect, "Show Duplicate Frame Markers");+ if c.changed() {+ let _ = app.session.execute("sequence.showDuplicateFrameMarkers", json!({"on": df}));+ }ui.separator();if ui.button(tl!("Expand All Tracks")).clicked() {app.ui.timeline.video_track_h = 64.0;diff --git a/crates/ui-egui/tests/it/sequence_ui.rs b/crates/ui-egui/tests/it/sequence_ui.rsindex 229821d1a..701426a49 100644--- a/crates/ui-egui/tests/it/sequence_ui.rs+++ b/crates/ui-egui/tests/it/sequence_ui.rs@@ -1,5 +1,5 @@//! Headless UI tests of the Sequence / Markers menu additions: the Add Tracks and Delete Tracks dialogs, the-//! through-edit marks on the timeline, the Markers panel colour filter and the Shift+; gap key.+//! through-edit marks and duplicate frame markers on the timeline, the Markers panel colour filter and the Shift+; gap key.//! The real `FilmcraftApp` under `egui_kittest`, driven over the control channel by automation id.//!//! Set `FILMCRAFT_UI_SNAPSHOT_DIR=<dir>` to also render the window offscreen with wgpu and write@@ -316,6 +316,68 @@ fn through_edits_are_marked_on_the_timeline() {assert!(d.ids("timeline.throughEdit.").is_empty(), "joined");}+#[test]+fn duplicate_frame_markers_are_drawn_on_repeated_clips() {+ let mut d = Driver::demo();+ // the demo's first V1 clip placed again on V2 at the same time: both show the same frames+ let (first, item, start, source_in, duration) = {+ let c = &d.app().session.active_sequence().unwrap().video_tracks[0].items[0];+ (c.id.0, c.item.0, c.start.0, c.source_in.0, c.duration.0)+ };+ let r = d.exec("timeline.place", json!({"item": item, "track": "V2", "time": start, "sourceIn": source_in, "duration": duration, "audio": false}));+ let copy = r["clips"][0].as_u64().unwrap();+ d.frames(3);+ assert!(d.ids("timeline.duplicateFrames.").is_empty(), "hidden until Show Duplicate Frame Markers");+ d.click("timeline.toggle.settings");+ d.click("timeline.settings.showDuplicateFrameMarkers");+ d.frames(3);+ assert!(d.app().session.state.show_duplicate_frame_markers);+ let marks = d.ids("timeline.duplicateFrames.");+ for clip in [first, copy] {+ assert!(marks.contains(&format!("timeline.duplicateFrames.{clip}.0")), "clip {clip}: {marks:?}");+ }+ // the markers follow edits: without the copy the first clip repeats nothing (the demo+ // repeats frames of another clip elsewhere, and those markers stay)+ let ours = |marks: &[String]| marks.iter().filter(|m| [first, copy].iter().any(|c| m.starts_with(&format!("timeline.duplicateFrames.{c}.")))).count();+ d.exec("edit.undo", json!({}));+ d.frames(3);+ let marks = d.ids("timeline.duplicateFrames.");+ assert_eq!(ours(&marks), 0, "the copy is gone: {marks:?}");+ assert!(!marks.is_empty(), "the demo's own repeat: {marks:?}");+ d.exec("edit.redo", json!({}));+ d.frames(3);+ assert_eq!(ours(&d.ids("timeline.duplicateFrames.")), 2, "the copy is back");+ // at 200 % the copy shows every other frame of the original, so the original repeats in+ // single frames+ d.app()+ .session+ .edit_sequence("test", |q, _, _| {+ q.find_item_mut(filmcraft_project::ClipId(copy)).unwrap().1.speed = 2.0;+ Ok(())+ })+ .unwrap();+ let listed = d.exec("sequence.duplicateFrames", json!({}));+ let runs = listed.as_array().unwrap().iter().find(|e| e["clip"] == json!(first)).unwrap()["ranges"].as_array().unwrap().len();+ assert!(runs > 4, "{listed}");+ // only the stripes in view are drawn: scrolled to the middle of the clip, the first is not+ let (scroll, pps) = (d.app().ui.timeline.scroll, d.app().ui.timeline.pps);+ let middle = (start + duration / 2) as f64 / filmcraft_time::TICKS_PER_SECOND as f64;+ (d.app().ui.timeline.scroll, d.app().ui.timeline.target_scroll) = (middle, middle);+ d.frames(3);+ let marks = d.ids(&format!("timeline.duplicateFrames.{first}."));+ assert!(!marks.is_empty() && !marks.contains(&format!("timeline.duplicateFrames.{first}.0")), "{marks:?}");+ (d.app().ui.timeline.scroll, d.app().ui.timeline.target_scroll) = (scroll, scroll);+ // zoomed far out, the single frames make one stripe+ (d.app().ui.timeline.pps, d.app().ui.timeline.target_pps) = (1.0, 1.0);+ d.frames(3);+ let marks = d.ids(&format!("timeline.duplicateFrames.{first}."));+ assert_eq!(marks.len(), 1, "{marks:?}");+ (d.app().ui.timeline.pps, d.app().ui.timeline.target_pps) = (pps, pps);+ d.exec("sequence.showDuplicateFrameMarkers", json!({"on": false}));+ d.frames(3);+ assert!(d.ids("timeline.duplicateFrames.").is_empty(), "turned off");+}+#[test]fn markers_panel_colour_filter() {let mut d = Driver::demo();diff --git a/crates/ui-egui/tests/it/timeline_trim_ui.rs b/crates/ui-egui/tests/it/timeline_trim_ui.rsindex d6243d548..739cd01fb 100644--- a/crates/ui-egui/tests/it/timeline_trim_ui.rs+++ b/crates/ui-egui/tests/it/timeline_trim_ui.rs@@ -181,6 +181,61 @@ fn dragging_an_out_edge_inward_trims_the_clip() {assert_eq!(d.undo_steps(), undo0 + 1, "one undo step");}+/// Duplicate frame markers stay inside a clip while its Out edge is dragged in, and follow the+/// trim once it is released.+#[test]+fn duplicate_frame_markers_stay_inside_a_clip_being_trimmed() {+ let mut d = Driver::demo();+ let city = d.v1_clip(CITY);+ let (item, start, source_in, duration) = {+ let (_, it) = d.app().session.active_sequence().expect("sequence").find_item(ClipId(city)).expect("clip");+ (it.item.0, it.start.0, it.source_in.0, it.duration.0)+ };+ d.exec("timeline.place", json!({"item": item, "track": "V2", "time": start, "sourceIn": source_in, "duration": duration, "audio": false}));+ d.exec("sequence.showDuplicateFrameMarkers", json!({"on": true}));+ d.frames(3);+ let (x0, x1, y) = d.edges(city);+ let by = ((x1 - x0) / 2.0).round();+ let stripe_right = |d: &mut Driver| {+ let els = d.ok("ui.elements", json!({"prefix": format!("timeline.duplicateFrames.{city}.")}));+ els.as_array()+ .expect("elements")+ .iter()+ .map(|e| (e["rect"][0].as_f64().expect("x") + e["rect"][2].as_f64().expect("w")) as f32)+ .fold(f32::MIN, f32::max)+ };+ assert!((stripe_right(&mut d) - x1).abs() <= 2.0, "the stripe runs to the Out edge");+ // press on the Out edge and move half the clip inward, without releasing+ let push = |d: &mut Driver, e: egui::Event| d.harness.input_mut().events.push(e);+ push(&mut d, egui::Event::PointerMoved(pos2(x1 - 3.0, y)));+ d.frames(1);+ push(&mut d, egui::Event::PointerButton { pos: pos2(x1 - 3.0, y), button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() });+ d.frames(1);+ for i in 1..=by as usize {+ push(&mut d, egui::Event::PointerMoved(pos2(x1 - 3.0 - i as f32, y)));+ d.frames(1);+ }+ // (the painter's clip rect is rounded to whole pixels)+ let body_right = |d: &mut Driver| {+ let id = format!("timeline.clip.{city}");+ let els = d.ok("ui.elements", json!({"prefix": id}));+ let r = &els.as_array().expect("elements").iter().find(|e| e["id"] == id.as_str()).expect("clip")["rect"];+ (r[0].as_f64().expect("x") + r[2].as_f64().expect("w")) as f32+ };+ let (during, right) = (stripe_right(&mut d), body_right(&mut d));+ assert!(right < x1 - by / 2.0, "the clip is drawn trimmed: {right}");+ assert!(during <= right + 1.5, "inside the trimmed clip during the drag: {during} > {right}");+ push(+ &mut d,+ egui::Event::PointerButton { pos: pos2(x1 - 3.0 - by, y), button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() },+ );+ d.frames(3);+ let (_, e1) = d.span(city);+ assert!(e1 < start + duration, "trimmed");+ let (after, right) = (stripe_right(&mut d), body_right(&mut d));+ assert!(after <= right + 1.5, "after the trim: {after} > {right}");+}+/// Just right of a cut the clip on the right is grabbed: its In edge trims, and the clip on the/// left stays as it was. The left clip's Out edge used to claim both sides of the cut.#[test]diff --git a/docs/ui-parity.md b/docs/ui-parity.mdindex 838a98ad0..0df7cd1d4 100644--- a/docs/ui-parity.md+++ b/docs/ui-parity.md@@ -23,7 +23,7 @@ open interaction reports (about 40 of the 188 open issues).| Effect Controls | property rows, keyframe area with zoom, divider, graphs, eyedroppers | rows, keyframes, value / velocity graphs, eyedropper (#518); missing keyframe zoom (#641, #645), draggable divider (#643), row lines (#640), Position curves (#448) | 60% | #412, #640–#645, #448 | 15–25 h || Panels and docking | 17 workspaces, dock / undock / float, drop zones | 11 workspaces, docking; rearranging windows reported missing (#493); multi-monitor floating windows (#466) | 60% | #493, #466 | 20–35 h || Project panel | List / Icon / Freeform, hover scrub, marquee | all three views, hover scrub, view presets; no marquee (#578), Freeform bins and pan (#579), bins can't be left on Windows (#587), duplicate imports allowed (#356) | 75% | #578, #579, #587, #456 | 10–20 h |-| Timeline display | filmstrip thumbnails, waveforms, track heights, renaming | clip thumbnails, waveforms, heights; no continuous filmstrip (#614), no track rename (#654), wheel scroll in audio area (#400) | 70% | #614, #654, #400 | 8–15 h |+| Timeline display | filmstrip thumbnails, waveforms, track heights, renaming, duplicate frame markers | clip thumbnails, waveforms, heights, duplicate frame markers; no continuous filmstrip (#614), no track rename (#654), wheel scroll in audio area (#400) | 70% | #614, #654, #400 | 8–15 h || Transitions | drag, resize, alignment, edit in Effect Controls | drag / select / resize (#503); settings and the transition's own timeline in Effect Controls, drag to slide or resize (#577); no A/B previews with Start / End sliders | 70% | #577 | 5–10 h || Numeric entry and scrubbing | scrubbable hot text, typed values | scrubbable values, timecode scrub-edit (#576); audio clip mixer values cannot be typed (#481) | 80% | #481 | 3–6 h || Drag and drop | OS files into Project / Timeline, clipboard paste | OS drops into the timeline (#517); no clipboard paste of images / files (#611) | 70% | #519, #611 | 5–10 h |