
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
virtual-bg
Advanced tools
Easily add virtual background effects to your video/camera input inside any web browser
Install from npm using:
npm install virtual-bg
or include directly in HTML:
<script src="https://cdn.jsdelivr.net/npm/virtual-bg@latest/virtual-bg.min.js"></script>
<div>
<video autoplay="true" id="inputVideoElement"></video>
<canvas id="output_canvas"></canvas>
</div>
import { segmentBackground, applyBlur, applyImageBackground } from'virtual-bg';
const inputVideoElement = document.querySelector('#inputVideoElement');
const outputCanvasElement = document.querySelector('#output_canvas');
let myStream = await navigator.mediaDevices.getUserMedia({
video: true
});
inputVideoElement.srcObject = myStream;
// segments foreground & background
segmentBackground(inputVideoElement, outputCanvasElement);
// applies a blur intensity of 7px to the background
applyBlur(7);
// applies an image background
const image = new Image();
image.src = 'https://imageurl.jpg'
applyImageBackground(image);
segmentBackground(inputVideoElement, outputCanvasElement, modelSelection <optional>);
Parameters:
inputVideoElement
: <HTMLVideoElement> Source of video which is to be used for applying segmentation.outputCanvasElement
: <HTMLCanvasElement> Canvas Element where output is to be displayed.modelSelection
: Numerical value to select type of model to be used for segmentation. applyBlur(blurIntensity <optional>);
Parameters:
blurIntensity
: Numerical value in pixels to apply a blur filter to the background. This uses the same filter as used in CSS blur filterapplyImageBackground(imageElement);
Parameters:
imageElement
: <HTMLImageElement> Image element to be set as background. You can create a new element dynamically using the Image() constructor.applyVideoBackground(videoElement);
Parameters:
videoElement
: <HTMLVideoElement> Video element to be set as background.applyScreenBackground(screenCaptureStream);
Parameters:
screenCaptureStream
: <MediaStream> Stream obtained from the Screen Capture APIAn example use case for this can be when user has set screen capture as the background and want to present something.
changeForegroundType(foregroundType, offset<optional>);
Parameters:
foregroundType
: normal | presenter
Type of foreground. Presenter mode shrinks the foreground and displays it in the bottom right corner.offset
: Numerical value in pixels for setting custom offset when presenter mode is selected.Note: I'm using mediapipe's selfie segmentation model and library as a base.
For any doubts/feedback/suggestions, please start an issue/discussion at https://github.com/akhil-rana/virtual-bg or contact me at contact@akhilrana.com
FAQs
Easily add virtual background effects to your video/camera input inside any web browser
The npm package virtual-bg receives a total of 49 weekly downloads. As such, virtual-bg popularity was classified as not popular.
We found that virtual-bg demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.