@some0neelse/get-webp-duration
v1.0.0
Published
Get WebP animation duration by parsing RIFF structure directly in the browser
Maintainers
Readme
@some0neelse/get-webp-duration
Get WebP animation duration by parsing RIFF structure directly in the browser.
Installation
npm install @some0neelse/get-webp-durationUsage
import { getWebPDurationMs } from '@some0neelse/get-webp-duration';
const duration = await getWebPDurationMs('https://example.com/animation.webp');
// Returns: number (duration in milliseconds) | 0 (static WebP) | null (error)API
getWebPDurationMs(url: string): Promise<number | null>
Calculates the total duration of a WebP animation by analyzing its RIFF binary structure directly in the browser.
Parameters:
url- URL of the WebP file
Returns:
number- Total duration of all animation frames in milliseconds0- If WebP is valid but static (no ANIM/ANMF chunks)null- If the file cannot be loaded or doesn't match WebP format
Note: This calculates the "duration from file metadata", not the actual playback duration in browsers (browsers may override very small delays).
License
MIT
