Socket
Socket
Sign inDemoInstall

@mux/blurup

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mux/blurup

Generate a blurry image placeholder for a Mux video.


Version published
Weekly downloads
1.5K
increased by9.31%
Maintainers
1
Weekly downloads
 
Created
Source

@mux/blurup

JavaScript API to generate a blurry image placeholder for a Mux video.

The library retrieves a tiny video poster image from the Mux API and generates a blurry image placeholder by upscaling the image and applying a Gaussian blur.

See the blog post for more information: www.mux.com/blog/blurry-image-placeholders-on-the-web

Installation

npm install @mux/blurup

Usage (Demo)

import { createBlurUp } from '@mux/blurup';

const options = {};
const muxPlaybackId = 'O6LdRc0112FEJXH00bGsN9Q31yu5EIVHTgjTKRkKtEq1k';

const { blurDataURL, aspectRatio } = await createBlurUp(muxPlaybackId, options);
console.log(blurDataURL, aspectRatio);
// data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="100%" ...

Options

ParameterTypeDescriptionDefault
timenumberThe video timestamp from which to grab the blurhash. (If you're using a thumbnailToken, then the time option will have no effect; encode time in your token according to the secure video playback guide linked below)undefined
widthstringWidth of the output blurry image placeholder.100%
heightstringHeight of the output blurry image placeholder.100%
blurnumberStandard deviation of the Gaussian blur.20
qualitynumberQuality of the output image. Increase this value to see more details but also increase the length of the data URL.1
thumbnailTokenstringVideos with playback restrictions may require a thumbnail token. See https://docs.mux.com/guides/video/secure-video-playback for details.undefined
typewebp png jpgImage type to use in the output blurry image placeholder.webp

Using blurDataURL with Mux Player

Be sure to escape the double quotes in the blurDataURL string when using it in an HTML attribute.

mux-player element
<mux-player placeholder="{blurDataURL}" style="aspect-ratio: {aspectRatio}"></mux-player>
mux-player element with slotted poster (Demo)
<mux-player style="aspect-ratio: {aspectRatio}">
  <img 
    slot="poster"
    src="{posterURL}"
    style='
      width: 100%;
      background-size: cover;
      background-position: center;
      background-repeat: no-repeat;
      background-image: url("{blurDataURL}");
    '
  >
</mux-player>
mux-player-react and mux-player-react/lazy
<MuxPlayer placeholder={blurDataURL} style={{ aspectRatio }} />

Using blurDataURL with native elements

Be sure to escape the double quotes in the blurDataURL string when using it in an HTML attribute.

HTML
<img src="{blurDataURL}" width="300" style="aspect-ratio: {aspectRatio}" />
CSS
background-image: url('{blurDataURL}');
aspect-ratio: {aspectRatio};

Keywords

FAQs

Package last updated on 31 May 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc