Skip to content

Some-0ne-Else/get-webp-duration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@some0neelse/get-webp-duration

Get WebP animation duration by parsing RIFF structure directly in the browser.

Installation

npm install @some0neelse/get-webp-duration

Usage

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 milliseconds
  • 0 - 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

About

get-webp-duration

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors