Coder Social home page Coder Social logo

melleb / ts-whammy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from akimyou/ts-whammy

0.0 1.0 0.0 665 KB

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

License: MIT License

JavaScript 0.79% TypeScript 97.24% HTML 1.97%

ts-whammy's Introduction

This is a temp version of ts-whammy. Please use the original repository.

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

  • record canvas frames to webm video

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
  • images: An array of image base64 strings, image type must be 'image/webp', see more: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL
  • fps: frames per second number, FPS number can't be 0. (if you set FPS to equal 0, FPS will be reset to default of 1).
  • outputAsArray: return Uint8Array output, the default output is Blob. In node environments, the output always be Uint8Array.
fromImageArrayWithOptions(images: string[], options: IFromImageArrayOptions = {}): Blob | Uint8Array
  • images: Same as `fromImageArray's images
  • options:
    • fps: Same as fromImageArray's fps
    • duration set output video's duration in seconds. This will adjust the video's FPS to make sure the video has the exact duration.
    • outputAsArray: Same as fromImageArray's outputAsArray

Contribution

Feel free to contribute this project.

TODO

  • update the demo, support record canvas/HTML, upload images to video...
  • upgrade vite to vite@latest
  • support build out the esm lib
  • update tests case, up test codecov

ts-whammy's People

Contributors

akimyou avatar dependabot[bot] avatar melleb avatar mikemaccana avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.