Skip to content

feat(preview): play animated WebP previews - #2734

Merged
l0gicgate merged 6 commits into
lgse:mainfrom
kettleofketchup:feat/2710-animated-webp-preview
Nov 24, 2026
Merged

l0gicgate merged 6 commits into
lgse:mainfrom
kettleofketchup:feat/2710-animated-webp-preview

Conversation

@kettleofketchup

Copy link
Copy Markdown
Contributor

Description

Animated WebP files showed only their first frame: every WebP went to the still-image decoder. A local WebP whose header declares an animation (the VP8X animation flag) now plays in the media sandbox the way a GIF does, looping from the start with only the play/pause control.

It depends on the runtime FFmpeg having the webp_anim decoder, which arrived in FFmpeg 9.0. Strata asks ffmpeg -decoders once per process; with an older FFmpeg the file keeps today's still preview, so nothing regresses on distributions that have not moved to 9.0 yet.

FFmpeg's animated WebP demuxer reports no duration and cannot seek: -stream_loop stalls and -ss skips to the end. So for this format only:

  • the loop period is the sum of the frame durations in the ANMF chunk headers, read without decoding;
  • short animations loop with the loop filter, placed before the 30 fps conversion so it holds source frames, within a 256 MiB budget (and FFmpeg's 32,767-frame limit); a larger one plays once;
  • offsets (resume, seek by phase) are reached by decoding from the start and trimming, and decoding stays in software.

GIF commands are unchanged. docs/preview-sandbox.md and docs/preferences.md describe the new behaviour.

Validation notes: the new playback test needs FFmpeg 9 (the pinned test image has 9.0.1), so a native run on an older FFmpeg fails it rather than skipping. scripts/code-health.sh was not run because no CodeScene token was available.

Visual evidence

N/A: no captures attached. In words: selecting an animated WebP shows it playing and looping in the preview pane with a single play/pause control, as GIFs already do; a still WebP looks the same as before.

How to test

  1. On a system with FFmpeg 9.0 or newer, create an animated WebP, for example ffmpeg -f lavfi -i testsrc2=size=320x240:rate=10:duration=2 -c:v libwebp_anim -loop 0 anim.webp, or use any animated WebP from the web.
  2. Open its folder in Strata and select the file with the preview pane open.
  3. Pause and play it, select another file and come back, and also select a still .webp for comparison.

Expected result: the animated WebP plays and loops with only a play/pause control, and resumes in phase. The still WebP shows its usual image preview. With an FFmpeg older than 9.0, the animated file shows its first frame as before.

Related issue

Closes #2710

Animated WebP files showed only their first frame because every WebP went
to the still-image decoder. A local WebP whose header declares an
animation now plays in the media sandbox, like a GIF, when the runtime
FFmpeg has the webp_anim decoder (9.0 or newer, asked once per process).
With an older FFmpeg it keeps the still preview.

FFmpeg's animated WebP demuxer reports no duration and cannot seek, so
-stream_loop stalls and -ss skips to the end. The period comes from the
container's frame durations instead, short animations loop with the loop
filter ahead of the 30 fps conversion within a 256 MiB frame budget, and
offsets are reached by decoding and trimming.

Refs lgse#2710
The frame budget multiplied the frame count by a canvas size read from an
untrusted header. A 16,384-frame file declaring a 16,777,216 pixel square
canvas wraps to zero bytes, which panics a debug build and passes the
budget in a release build.

Refs lgse#2710
Split the RIFF walk into header and chunk readers, name the software-only,
animation and demuxer-loop conditions, pass the probe request as a struct,
move the WebP routing out of classify, and share one long-animation
assertion between the GIF and WebP playback tests. No behaviour changes.

Refs lgse#2710
@l0gicgate

Copy link
Copy Markdown
Contributor

Review and cleanup

Merged main at cd76a5ab4, no conflicts.

Review against the description and #2710. There were no earlier review comments or threads.

  • Animated WebP plays in the media sandbox with only play/pause: confirmed. A local file whose VP8X header has the animation flag is routed to media in PreviewLoad::route_animated_webp; adapters::local_preview::tests::resolution::animated_webps_play_as_media_only_where_ffmpeg_decodes_them guards it.
  • Still preview is kept when FFmpeg lacks webp_anim: the gate is sandbox::decodes_animated_webp. Read in code only; both my host (9.0.2) and the pinned image (9.0.1) have the decoder.
  • The FFmpeg constraints the design rests on hold on 9.0.2: ffprobe reports format_name: webp_anim and no duration, -ss 0.5 yields 0 frames, and -stream_loop -1 never returns.
  • The period from the ANMF durations matches the loop filter's period for uneven frames: a 100/300/500/300 ms file repeats every 36 frames at 30 fps.
  • GIF commands are unchanged; short_gifs_loop_inside_the_bounded_decode_generation_and_seek_by_phase still passes.

Fixes pushed

  • df5c7431c fix(preview): keep the animated WebP loop budget from overflowing. fits_loop_budget multiplied the frame count by a canvas size read from the file. 16,384 frames on a 16,777,216 px square canvas is exactly 2^64 bytes: a debug build panics and a release build wraps to 0 and accepts the loop. Now saturating, with a row in animated_webps_loop_only_within_the_frame_budget_and_never_seek_the_source.
  • 98420c8fb refactor(preview): clear code-health findings in animated WebP playback. scripts/code-health.sh had not been run. Against main, load.rs had dropped 9.68 → 9.38 (classify cc 10) and tests/playback.rs 10.0 → 9.38 (duplicated long-animation assertion); the new webp_animation.rs scored 9.24 (read_webp_animation cc 13). Now 9.68, 10.0 and 10.0, and sandbox_helper/media.rs is 6.5 (6.33 on main). No behaviour change.
  • 3f96da6d9 docs(preview): drop comments that restate animated WebP tests.

Tests. None removed. The parser, decoder-listing, command and real-FFmpeg playback tests each fail on a realistic regression. images_in_the_media_player_are_looping_animations is a thin table, but it is the only guard on WebP getting the play/pause-only controls, so it stays.

Manual check in the pinned QA container (./scripts/qa-drive.sh, FFmpeg 9.0.1, autoplay on), on the final code:

  • anim.webp (320×240, 10 fps, 2 s): the preview shows a moving picture and one Play/Pause button, with no seek bar or volume. Pausing freezes the frame.
  • The same bytes named misnamed.png play the same way.
  • still.webp shows the image preview with no media controls.

Validation

  • ./scripts/test-headless.py -- webp decoder_listings sandbox_helper::media local_preview images_in_the_media_player: 74 passed
  • ./scripts/test-headless.py -- ui::preview: 124 passed
  • ./scripts/qa.sh video-preview-badges-next-video: 6 passed
  • cargo fmt --all --check and cargo clippy --workspace --all-targets --all-features -- -D warnings: clean (native toolchain, not quality.sh)
  • Not run locally: the full Rust suite and the full QA run. The change is confined to preview classification, the media sandbox helper and the media controls; CI runs the full suite.

Not blocking

  • An animated WebP that FFmpeg cannot play (for example a canvas over the 50-megapixel -max_pixels cap) now shows a preview error where it used to show its first frame. GIF behaves the same way.
  • read_webp_animation does one seek and read per chunk with no chunk cap, so a multi-gigabyte file of empty chunks is stopped only by the helper's 10-second CPU limit.
  • short_animated_webps_loop_and_seek_by_phase_without_seeking_the_source fails on a native run with FFmpeg older than 9.0, as the description says.

CI: the fork's run needed maintainer approval; approved and in progress for 3f96da6d9.

The 100 ms flush timer from lgse#2634 stayed attached to the default main
context after its browser was dropped. Its closure is bound to the
thread that created it, so the next test thread that iterated the
context fired it and glib's thread guard aborted the test binary. This
failed Rust tests shard 0 in the local_departures monitor test on
unrelated pull requests.

Refs lgse#2710
@l0gicgate

Copy link
Copy Markdown
Contributor

CI fix pushed: 9970f1bcd fix(browser): remove the live-change flush timer when the browser drops

Rust tests shard 0 failed twice on this PR, both times in app::browser::tests::monitor::local_departures::the_open_directory_follows_an_outside_rename_and_leaves_an_outside_removal. The panic was Value accessed from different thread than where it was created, raised in Browser::schedule_live_change_flush. The same failure hit ci/2797-rpm-pr-paths, so it does not come from this PR.

The cause is the 100 ms flush timer added in #2634: it stayed attached to the default main context after its Browser was dropped. The tests are serialized by ASYNC_MAIN_CONTEXT_DEFAULT but run on different libtest threads. The next thread to iterate the context therefore fired a closure bound to another thread, and glib aborted the binary. LiveChanges now removes the timer on drop.

New test app::browser::tests::live_changes::dropping_a_browser_removes_its_pending_flush passes with the fix and fails when the drop leaks the source.

  • ./scripts/test-headless.py -- app::browser: 414 passed
  • cargo fmt --all --check and cargo clippy --workspace --all-targets --all-features -- -D warnings: clean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] .webp Animation preview

2 participants