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 🙏

© 2025 – Pkg Stats / Ryan Hefner

transparent-video-react

v1.4.0

Published

transparent video react component

Readme

Transparent Video React Component

🚧 Work in progress, use with caution in production.

Release workflow NPM Version License

A react component for stacked-alpha video.

The stacked-alpha video rendering technique is based on Jake Archibald's research: article and his web component repo. This approach provides high compression efficiency while preserving excellent visual quality for transparent videos.

Enhanced for React.

Enhancements

  • Optimized for React - Compatiable with React's ref and state management.
  • Automatic canvas resizing - Canvas automatically resizes to match its display size.
  • HIDPI/Retina support - Automatically detects and adapts to high-DPI displays for crisp rendering.
  • Automatic source refresh - Video automatically reloads when source props change.
  • Object-fit support - Supports contain, cover, and fill modes for flexible video scaling.
  • Optimized render size - Canvas render size is optimized to be as small as possible based on video dimensions and container size.
  • Optimized GL context - Efficient WebGL context creation and cleanup.

Usage

import { TransparentVideo, TransparentVideoSource } from 'transparent-video-react';

<TransparentVideo autoPlay loop muted>
  <TransparentVideoSource src="video.mp4" type="video/mp4" />
  {/* or */}
  {/* <TransparentVideo.Source src="video.mp4" type="video/mp4" /> */}
</TransparentVideo>;

Props

<TransparentVideo>

| Name | Type | Default | Description | | -------------------- | ---------------------------------------------------- | -------- | --------------------------------------------------------------- | | className | string | | CSS class name for the container | | style | CSSProperties | | Inline CSS styles for the container | | muted | boolean | | Whether the video is muted | | autoPlay | boolean | | Whether the video plays automatically | | loop | boolean | | Whether the video loops | | playsInline | boolean | | Whether the video plays inline (mobile) | | preMultipliedAlpha | boolean | false | Whether the video uses premultiplied alpha | | objectFit | 'contain' \| 'cover' \| 'fill' | 'fill' | How the video is fitted to the container | | videoProps | React.HTMLProps<HTMLVideoElement> | | Additional props for the video element | | canvasProps | React.HTMLProps<HTMLCanvasElement> | | Additional props for the canvas element | | children | TransparentVideoSource \| TransparentVideoSource[] | | <TransparentVideoSource> or <TransparentVideo.Source> nodes | | onPlayStateChange | (isPlaying: boolean) => void | | Callback when play state changes |

<TransparentVideoSource> or <TransparentVideo.Source>

| Name | Type | Default | Description | | ------ | -------- | ------- | ------------------------------------------ | | src | string | | URL of the video source | | type | string | | MIME type of the video (e.g., video/mp4) |

Ref API (TransparentVideoRef)

The TransparentVideo component exposes a TransparentVideoRef with the following methods and properties:

| Name | Type | Description | | --------------------- | --------------------------------- | ----------------------------------------------------------------------------------------------- | | play() | () => void | Play the video | | pause() | () => void | Pause the video | | seek(time) | (time: number) => void | Seek to a specific time (in seconds) | | forceUpdate(resize) | (resize?: boolean) => void | Force draw the current frame. When resize is true, the canvas layout is recalculated first. | | isPlaying | boolean | Whether the video is currently playing | | getVideoElement() | () => HTMLVideoElement \| null | Get the underlying video element | | getCanvasElement() | () => HTMLCanvasElement \| null | Get the underlying canvas element |

Alpha Video Generation

Install ffmpeg to generate a stacked alpha video from a video with alpha channel.
See Jake Archibald's repo for more details, here is the generation method taken from that doc:

Encoding AV1

This is the ideal format, used by Chrome, Firefox, and Safari on iPhone 15 Pro or M3 MacBook Pro & newer.

INPUT="in.mov" OUTPUT="av1.mp4" CRF=45 CPU=3 bash -c 'ffmpeg -y -i "$INPUT" -filter_complex "[0:v]format=pix_fmts=yuva444p[main]; [main]split[main][alpha]; [alpha]alphaextract[alpha]; [main][alpha]vstack" -pix_fmt yuv420p -an -c:v libaom-av1 -cpu-used "$CPU" -crf "$CRF" -pass 1 -f null /dev/null && ffmpeg -y -i "$INPUT" -filter_complex "[0:v]format=pix_fmts=yuva444p[main]; [main]split[main][alpha]; [alpha]alphaextract[alpha]; [main][alpha]vstack" -pix_fmt yuv420p -an -c:v libaom-av1 -cpu-used "$CPU" -crf "$CRF" -pass 2 -movflags +faststart "$OUTPUT"'
  • CRF (0-63): Lower values are higher quality, larger filesize.
  • CPU (0-8): Weirdly, lower values use more CPU, which improves quality, but encodes much slower. Usually not got lower than 3.

Encoding HEVC

For Safari on other devices, they need a less-efficient HEVC.

INPUT="in.mov" OUTPUT="hevc.mp4" CRF=30 PRESET="veryslow" bash -c 'ffmpeg -y -i "$INPUT" -filter_complex "[0:v]format=pix_fmts=yuva444p[main]; [main]split[main][alpha]; [alpha]alphaextract[alpha]; [main][alpha]vstack" -pix_fmt yuv420p -an -c:v libx265 -preset "$PRESET" -crf "$CRF" -tag:v hvc1 -movflags +faststart "$OUTPUT"'
  • CRF (0-63): Lower values are higher quality, larger filesize.
  • PRESET (medium, slow, slower, veryslow): The slower you go, the better the output.

TODO

Features

  • [ ] Support object-position
  • [x] Anti-aliasing
  • [ ] Video poster
  • [ ] Accessibility

Known issues

  • [ ] First frame render sometimes is blank, find a better way to handle this
  • [ ] If autoPlay is enabled, since resize canvas is debounced (100ms), first 100ms video render will be skipped

Credits

License

MIT