Skip to content

#329: scrubbing a long movie: superseded viewer frames call off their decodes - #784

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
vangel76:fix-329-seek-latency
Oct 12, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
vangel76:fix-329-seek-latency

Conversation

@vangel76

Copy link
Copy Markdown
Contributor

Fixes #329.

Problem

Scrubbing a long movie (dragging the current-time indicator or clicking around a 45 min clip) showed the frame under the pointer only seconds after the pointer stopped.

A single far jump is not the slow part: FilmCraft's GOP cache seeks to the preceding keyframe and decodes forward from there (one keyframe-to-target run per jump, 0.1–0.4 s here). The time goes into superseded viewer frames. While dragging, the viewer asks for a new frame every UI frame. Queued requests were already dropped (#284), but each request that a free frame-pool thread had started kept running: it seeked the movie's one decoder and decoded up to a whole GOP, and the frame the pointer stopped on queued behind all of them on the decoder's lock. Nothing in EffectCraft used FilmCraft's cooperative cancellation (filmcraft_media::cancel), although the decoder already checks it before a seek and between samples.

Fix

  • effectcraft-render: FootageSource::cancellable(cancel, f) (default: just runs f) and FootageSource::called_off(), plus CancellableFootage, a per-render view of a source whose frame/frame_at_size reads each run inside cancellable with the render's own flag. The flag travels with the render's footage reference, not with the thread, so reads made for the render on other threads (parallel loops) answer to it and reads for other renders never do. A render whose reads were called off keeps nothing in the layer cache (an effect's layer parameter could otherwise cache a layer made from a frame that came back empty).
  • effectcraft-media: MediaPool implements cancellable with filmcraft_media::cancel::with_cancel; a called-off read is MediaError::Cancelled (not logged as a decode error, not cached).
  • effectcraft-ui-egui (frames.rs): every frame job carries a cancel flag and renders through CancellableFootage. A new viewer (urgent) frame calls off the comp's running viewer frames of other times (another revision of the same frame, a live edit, still finishes, as the viewer shows it meanwhile). A called-off render is released without being cached (RAM or disk), and the viewer asks again if it still wants it.

Prefetch, RAM preview and playback read-ahead jobs are never called off.

Measurements

Generated 1080p30 testsrc2 clips at 900 kb/s (x264 superfast -bf 3, x265 ultrafast). Measured through MediaPool (the viewer's decode path) with a throwaway example (not committed). Machine: AMD Ryzen, 16 threads, Linux, shared with other builds (load average ~20). Ranges are over repeated runs.

Single jumps (unchanged by this PR; mean over 12 random far jumps):

file GOP far jump, ms to frame frames decoded per jump next frame after the jump ffmpeg -ss t -frames:v 1 (incl. ~80 ms process start/open)
H.264 MP4, 45 min 250 155–205 19–256 (mean ~130) 2–10 ms, 0–6 decoded 124 ms
H.264 MKV, 45 min 250 153–191 same same 118 ms
H.264 MP4, 45 min 30 84 ≤ 30 ~3 ms 144 ms
HEVC MP4, 15 min 250 435 20–250 — 224 ms

Scrub (20 viewer requests 16 ms apart, each started on its own thread as the frame pool does; latency = last request until its frame):

file GOP drag 2 s of media per step: before → after frames decoded before → after drag 0.3 s per step: before → after
H.264 MP4 250 1849–3615 ms → 168–279 ms 1316–1362 → 230–249 225–798 ms → 53–162 ms
H.264 MKV 250 1838–3066 ms → 210 ms 1353–1360 → 243 247–710 ms → 138 ms
H.264 MP4 30 2042 ms → 168 ms 897 → 214 129 ms → 218 ms (noise: small GOPs barely pile up)
HEVC MP4 250 3325 ms → 116 ms 1309 → 186 509 ms → 133 ms

After the fix, the frame under the pointer costs about one keyframe-to-target decode, as for a single jump.

Not changed here (FilmCraft codec side, for a follow-up there): a far jump still decodes up to a whole GOP. FilmCraft's HEVC decoding is about 2× slower than ffmpeg's per jump on these clips. Footage is also read whole into memory when it is opened (probe and the first frame of a file).

Tests

  • effectcraft-ui-egui frames::tests::a_newer_viewer_frame_calls_off_the_one_rendering: a viewer frame stuck in a long seek is called off by a newer viewer frame of another time, is not cached, and the newer frame renders. Without the fix it fails: the old render runs its full 5 s and gets cached.
  • effectcraft-media tests/footage.rs::a_called_off_read_does_not_decode: a called-off MediaPool read returns no frame and caches nothing, and the frame decodes normally when it is wanted again. Fails without the fix.
  • effectcraft-render tests::a_called_off_render_keeps_nothing_in_the_layer_cache.

Gates

cargo fmt --check; cargo clippy -D warnings --all-targets for render, media and ui-egui; full tests of effectcraft-render, effectcraft-media and effectcraft-ui-egui (--no-fail-fast); cargo xtask layers; cargo check --target wasm32-unknown-unknown for render and media. I did not run the full cargo xtask ci because the machine is shared.

🤖 Generated with Claude Code

Problem: scrubbing a long movie showed the frame under the pointer
seconds after the pointer stopped. Every viewer frame a free frame-pool
thread had started kept running: each seeked the movie's one decoder and
decoded up to a GOP, and the newest frame waited behind all of them on
the decoder's lock (45 min 1080p H.264/HEVC, GOP 250: 1.8-3.6 s for the
last frame of a drag; a single jump is 0.1-0.4 s). FilmCraft's decoder
already polls a cancellation flag, but nothing set one.

Fix: FootageSource::cancellable / called_off and CancellableFootage (a
per-render view whose frame reads run under the render's own flag, so
reads on other threads answer to the right render). MediaPool runs them
under filmcraft_media::cancel::with_cancel. The frame workers render
through it, and a newer viewer frame calls off the comp's running viewer
frames of other times. A called-off render is not cached (frames, disk,
layer cache). Drag latency is now 0.1-0.3 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vangel76

Copy link
Copy Markdown
Contributor Author

Extra verification: since this changes the FootageSource trait, I also ran the full test suites of the other crates that depend on effectcraft-render on this branch (engine, lottie, export, expr, script, gpu): 960 passed, 0 failed.

eliasx45 pushed a commit to eliasx45/effectcraft that referenced this pull request Oct 11, 2026
…first (storytold#595)

Ports the still-needed part of upstream PR storytold#793 onto the fork's protected
window (fdafa81):
- Frames::set_playhead (set by playback every UI frame, cleared on stop and
  while scrubbing): while a preview plays, eviction takes frames it doesn't
  reach first, then the one it reaches last, instead of LRU outside the small
  protected window. A looping preview longer than the cache re-rendered every
  frame on every loop (60 renders in 3 laps of 20 frames with 8 cached; now 47).
- Prefetch order: urgent, then the frame the preview reaches first, then
  request order, disk-only last; queued prefetch frames of the playing series
  it no longer reaches are dropped and leave the in-flight set.
- The playback prefetch window stops at what the RAM preview holds.
Not ported: storytold#793's viewer Arc sharing (fork already has fit_texture_shared)
and the media/render footage cancellation (storytold#784, separate).

Tests run: cargo test -p effectcraft-ui-egui --lib frames::tests (25 ok,
3 new: a_full_cache_keeps_the_frames_just_ahead_of_the_playhead,
a_looping_preview_longer_than_the_cache_renders_only_what_does_not_fit,
prefetch_renders_the_frames_the_playhead_reaches_first; all 3 failed before),
playback_budget/playback_pacing lib tests (11 ok); clippy -D warnings on
effectcraft-ui-egui --all-targets.
@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 565fd41 into storytold:main Oct 12, 2026
@echelon

echelon commented Oct 12, 2026

Copy link
Copy Markdown
Member

Merged. Thank you for the contribution, @vangel76!

If you haven't already, come join us on Discord: https://discord.gg/artcraft. It's the best place to discuss what you're working on next and to coordinate with other contributors.

h-a-n-a-s-h-i pushed a commit that referenced this pull request Oct 12, 2026
- Footage sources: the cancellable wrapper (#784) forwards frame_with (#752 float curves)
  and problem (#887); problem's default lives on the trait.
- Media: a called-off decode (#784) is not a footage problem (#887).
- Effect Controls rename (#953): Escape cancels (egui drops focus on Escape the same
  frame), the Rename item is translated; regression test.
- i18n (#873): drop the /out-i18n/ ignore rule and the note about an uncommitted script.
- Tests: text range selector caps (#926) re-borrow the layer; the RAM preview test (#793)
  sets the comp's own Resolution (#462).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
eliasx45 pushed a commit to eliasx45/effectcraft that referenced this pull request Oct 12, 2026
…ng a long movie shows the frame under the pointer quickly (storytold#329, port of upstream storytold#784)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EffectCraft - timeline scrubbing and interactions slow and not realtime responsive

3 participants