Github | Npm | Home


ts-whammy

A modern typescript version of whammy. You can use it to encode images(webp) to webm video.

ts-whammy only includes the core video encoding functions of whammy, you can use it whatever modern frontend stack you prefer.

Status

Quick start

ts-whammy

npm install ts-whammy -S
// for js
import tsWhammy from 'ts-whammy'

// for ts
// import tsWhammy from 'ts-whammy/src/libs'

// image URLs can from: canvas.toDataURL(type, encoderOptions)
const images = ['data:image/webp;base64,UklGRkZg....',
  'data:image/webp;base64,UklGRkZg....']

// create a video at 1 FPS
const blob = tsWhammy.fromImageArray(images, 1)
// create a 5 second video
const blob = tsWhammy.fromImageArrayWithOptions(images, { duration: 5 })

console.log(blob.type, blob.size)

Usage

Compatibility

Performance

# test data
images info length(5),
total base64 size(157.37890625 kb),
total blob size(118.029296875 kb)

# MacBook Pro I7 2.2G
# node v10.13.0, benchmark
--- testFromImageArray ---
fromImageArray x 63.06 ops/sec ±2.74% (64 runs sampled)

# chrome 79, simple loop test
--- start test total count(100) ---
...
...
end test total count(100),
time(697 ms),
avg time(6.97 ms),
ops/sec (143.47202295552367),
webm size (118.1572265625 kb)

Docs

index

fromImageArray(images: string[], fps: number, outputAsArray?: boolean): Blob | Uint8Array
fromImageArrayWithOptions(images: string[], options: IFromImageArrayOptions = {}): Blob | Uint8Array
async fixImageDataList(images: string[], options?: ImageSrcToWebpDataUrlOptions): Promise<string[]>

This function can make common image(jpg,png,webp…) url or base64 to be an valid webp image. Then can send it to fromImageArrayWithOptions make an video. See this demo: Convert Canvas-recorded images into a video

Contribution

Feel free to contribute this project.

TODO