Skip to content

#762: import animated WebP as footage with its frames - #768

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
vangel76:fix-762-animated-webp
Oct 12, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
vangel76:fix-762-animated-webp

Conversation

@vangel76

Copy link
Copy Markdown
Contributor

Fixes #762.

Found while measuring #719.

Problem

An animated WebP (for example one with alpha made by ffmpeg -c:v libwebp_anim -loop 0) imported as a still and showed only its first frame: probe_bytes sent every WebP down the still path. Animated GIF already plays its frames through gif_anim.

Fix

  • New crates/media/src/webp_anim.rs, following the animated GIF path:
    • Probe: reads the RIFF chunk headers: the VP8X animation and alpha flags, plus one ANMF chunk per frame. A WebP with two or more frames becomes Video footage with codec WebP. Alpha is Straight when the VP8X alpha flag is set and Ignore otherwise. A still WebP, or an animation with one frame, stays a still.
    • Timing:
      • Delays that differ by at most 1 ms are read as the standard rate they round to. ffmpeg's 24 fps output (41/42 ms) becomes 24 fps and 1.0 s, not 1000 fps; 29.97 is handled the same way.
      • Any other timing gets 1000 / the gcd of the delays, so uneven timing stays exact.
      • Delays of 10 ms or less count as 100 ms, as in browsers and as for GIF.
    • Decode: every frame is decoded once with the image crate's WebP AnimationDecoder. No new dependency. Frames are cached in the pool's existing GIF slot.
  • gif_anim::Anim now stores frame starts as Ticks. It serves both formats: Anim::load sends RIFF/WEBP data to webp_anim::load. is_gif is renamed is_animated. GIF behaviour is unchanged and its tests still pass.
  • Robustness:
    • If canvas × frames is above the existing GIF memory cap (1 GiB, or 256 MiB on wasm32), the file is refused before decoding with a clear message.
    • A damaged tail keeps the frames before it.
    • A file with no decodable frames gives a decode error. Nothing panics or hangs.
  • docs/file-format-parity.md: WebP row updated.

Tests

  • an_animated_webp_is_a_movie_with_its_frames: a hand-built 3-frame animated WebP probes as Video with 20 fps, 0.2 s and Straight alpha. Frame N differs from frame 0, alpha is kept, and the last frame holds past the end. On main this test fails because the footage is a Still.
  • delays_rounded_to_milliseconds_read_as_the_standard_rate: covers the 24 fps and 29.97 fps snapping, exact uneven timing, and the 100 ms rule for very short delays.
  • a_still_webp_stays_a_still: a lossless still WebP stays a still, and so does a one-frame animation.
  • a_truncated_animated_webp_is_an_error_not_a_panic: several cut points; no panic, and a cut before the frame data is an error.
  • a_huge_animation_is_refused_before_decoding: a 16384² × 10-frame header is refused.
  • Manual run against the Poor performance with WebP files #719 fixture anim_a_1080.webp. This file is not committed. It probed as Video, 1920×1080, 24 fps, 1.0 s, and frame 12 differed from frame 0. A still WebP from the same set stays a Still.

Gates

cargo fmt --check, clippy -p effectcraft-media --all-targets -D warnings, the full effectcraft-media tests, cargo xtask layers, and cargo check -p effectcraft-media --target wasm32-unknown-unknown all passed. The full cargo xtask ci was not run because the machine is shared. No UI strings changed.

Overlaps

What remains

  • The WebP loop count is not mapped to Footage::loop_count. Footage plays once, as for GIF; Interpret Footage ▸ Loop still works.
  • The Media Browser lists .webp under images and .gif under video.
  • Animated GIF at rates like 24 fps (4/4/5 cs) still gets 100 fps. The millisecond snapping could be extended to GIF in a follow-up.

🤖 Generated with Claude Code

Problem: an animated WebP (e.g. ffmpeg -c:v libwebp_anim) imported as a
still and showed only its first frame; probe_bytes handed every WebP to
the still path. Found while measuring storytold#719.

Fix: a webp_anim module, following the animated GIF path. Probing reads
the RIFF chunk headers (VP8X animation and alpha flags, one ANMF per
frame) and describes a WebP with two or more frames as Video footage
(codec "WebP", alpha Straight or Ignore from VP8X). Frame delays give the
rate: delays within 1 ms of each other read as the standard rate they
round to (24, 25, 29.97...), else 1000 / gcd of the delays so uneven
timing is exact; delays of 10 ms or less count as 100 ms as in browsers.
Frames are decoded once with the image crate's WebP AnimationDecoder and
cached in the pool's existing GIF slot; gif_anim::Anim now keeps frame
starts as Ticks and serves both formats. Canvas x frames beyond the
existing memory cap is refused before decoding; a damaged tail keeps the
frames before it; a file without frames is a clear decode error. Still
WebP stays a still.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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.

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.

Import animated WebP as footage with its frames (not only the first frame)

3 participants