#762: import animated WebP as footage with its frames
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 #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>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
9a7d3e7699
commit
5ba0c60a15
@@ -186,7 +186,7 @@ struct Inner {
|
||||
files: Mutex<HashMap<String, Arc<[u8]>>>,
|
||||
/// Parsed 3D models by path (`None`: failed to load; not retried until `forget`).
|
||||
models: Mutex<HashMap<String, Option<Arc<effectcraft_model::Model>>>>,
|
||||
/// Decoded animated GIFs by path, loaded by the first caller while the others wait (an
|
||||
/// Decoded animated GIFs and WebPs by path, loaded by the first caller while the others wait (an
|
||||
/// `Err` is not retried until `forget`).
|
||||
gifs: Mutex<HashMap<Arc<str>, GifSlot>>,
|
||||
cache: Mutex<CacheState>,
|
||||
@@ -590,7 +590,7 @@ impl Inner {
|
||||
.clone()
|
||||
}
|
||||
|
||||
/// The decoded frames of the animated GIF at `path`. The first caller decodes it, outside the
|
||||
/// The decoded frames of the animated GIF or WebP at `path`. The first caller decodes it, outside the
|
||||
/// map's lock; callers asking for the same file meanwhile wait for that.
|
||||
fn gif(&self, path: &Arc<str>) -> Result<Arc<Anim>> {
|
||||
let slot = lock(&self.gifs).entry(path.clone()).or_default().clone();
|
||||
@@ -745,7 +745,7 @@ impl Inner {
|
||||
};
|
||||
Ok(dynamic_to_image(&img, op))
|
||||
}
|
||||
Some(mt) if gif_anim::is_gif(footage) => {
|
||||
Some(mt) if gif_anim::is_animated(footage) => {
|
||||
let anim = self.gif(path)?;
|
||||
let frame = anim.frame_at(Tick(mt.0)).ok_or_else(|| MediaError::Decode(format!("{path}: no frames")))?;
|
||||
Ok(dynamic_to_image(frame, op))
|
||||
|
||||
Reference in New Issue
Block a user