npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@api.video/media-stream-person-segmentation

v0.0.1

Published

api.video media stream person segmentation - change the background and emphasize the person in your media streams

Downloads

12

Readme

badge   badge   badge

api.video is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and managing on-demand & low latency live streaming features in your app.

Table of contents

Project description

This library allows you to easily blur the background of a webcam video stream in real-time using TensorFlow.

With this library, you can create a more professional and visually appealing video conferencing experience by keeping the focus on the person in front of the camera and reducing visual distractions from the surrounding environment.

Please note that this project is currently experimental and may not be suitable for production use. This works pretty well on Chrome and Firefox, it may not work as well on Safari.

Getting started

Installation

Simple include in a javascript project

Include the library in your HTML file like so:

<head>
    ...
    <script src="https://unpkg.com/@api.video/media-stream-person-segmentation" defer></script>
</head>
...
<script type="text/javascript"> 
    navigator.mediaDevices.getUserMedia(constraints).then((webcamStream) => {
        const segmentation = new ApiVideoMediaStreamPersonSegmentation(webcamStream)

        segmentation.applyBlurEffect()

        segmentation.onReady((ouputStream) => {
            // use the ouputStream to display the video
            // ...
        });

    });
</script>

Documentation

Instanciation

Options

The library is instanciated with a MediaStream object as parameter.

const segmentation = new ApiVideoMediaStreamPersonSegmentation(webcamStream)

Methods

applyBlurEffect(options: BlurEffectOptions)

Apply a blur effect on the background of the video stream.

Options

| Name | Default | Type | Description | | :------ | :------| :------ | :------ | | backgroundBlurAmount | 15 | number | The amount of blur to apply to the background. | | edgeBlurAmount | 8 | number | The amount of blur to apply to the edges of the person. |

segmentation.applyBlurEffect({
    backgroundBlurAmount: 15,
    edgeBlurAmount: 8
})

onReady(callback: (stream: MediaStream) => void)

Call the callback when the stream is ready.

segmentation.onReady((stream) => {
    // use the stream to display the video
    // ...
});

Full example

<html>

<head>
    <script src="https://unpkg.com/@api.video/media-stream-person-segmentation"></script>
    <style>
        #container {
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        #video {
            width: 640;
            height: 480;
            border: 1px solid gray;
        }

        #container div {
            margin: 10px 0;
        }

        label {
            display: inline-block;
            width: 160px;
            text-align: right;
        }

        input {
            display: inline-block;
            width: 300px;
        }
    </style>
</head>

<body>
    <div id="container">
        <div>
            <video muted id="video"></video>
        </div>
        <div>
            <div>
                <label for="blur">Blur background</label>
                <input type="range" id="blur" min="0" max="100" value="15" />
            </div>
            <div>
                <label for="blurEdges">Blur edges</label>
                <input type="range" id="blurEdges" min="0" max="10" value="8" />
            </div>
        </div>
    </div>

    <script>
        const video = document.querySelector('#video');

        var constraints = window.constraints = {
            audio: true,
            video: true
        };

        navigator.mediaDevices.getUserMedia(constraints).then((stream) => {
            const segmentation = new ApiVideoMediaStreamPersonSegmentation(stream)

            segmentation.applyBlurEffect({
                backgroundBlurAmount: 15,
                edgeBlurAmount: 8
            })

            document.getElementById("blur").addEventListener("input", (e) => segmentation.applyBlurEffect({
                backgroundBlurAmount: e.target.value
            }));
            document.getElementById("blurEdges").addEventListener("input", (e) => segmentation.applyBlurEffect({
                edgeBlurAmount: e.target.value
            }));

            segmentation.onReady((stream) => {
                video.srcObject = stream;
                video.play();
            });

        });
    </script>
</body>

</html>