Git Product home page Git Product logo

webcodecs-demo's Introduction

WebCodecs API Demo

This is a demo of the WebCodecs API. It initializes a camera stream using the webcam with the highest resolution. Over a period of 10 seconds the screen will toggle between black and white. The frames are captured and encoded using the WebCodecs API. The encoded frames are then displayed on the webpage using a canvas element and can be toggled between using the buttons on the page.

Instructions

The website can be accessed at webcodecs-demo.netlify.app.

Since this demo has no external dependencies, all you need to run it locally is clone the repository and run:

    python3 -m http.server 9091 -d .

You can then access the demo at localhost:9091.

Configuration

The configuration for the demo is in the config.js file. The following parameters can be configured:

For the camera encoder

  • videoWidth: The width of the video stream.
  • bitRate: The bit rate to use for encoding.
  • codec: The codec to use for encoding.

For the pattern

  • pattern: The pattern to use for the frame capture.
  • handlers: The handlers to use for the pattern. This should be a map of the form { 'char': handler } where char is a character in the pattern and handler is a function that will be run before capturing the frame corresponding to the character in the pattern.
  • duration: The duration of the pattern in seconds.

Running tests

I have written tests for the function which handles running the frame capture according to the configuration pattern. The tests can be run using npm run test.

Notes

  • Due to lack of time I decided to write unit tests for the most important part of the application.
  • I have tried to keep the code cleanly encapsulated and write all classes so that they could be potentially swapped out for a different implementation as long as the "duck type" interface is maintained.
  • Many of the functions are pure functions and I have tried to keep the code as functional as possible where practical and useful to do so.
  • Given more time I would have refactored to make dependency injection possible in more places as to make testing easier.

webcodecs-demo's People

Contributors

luk-pio avatar

Stargazers

Alice 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.