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

simple-text-overlay

v1.0.5

Published

Add text overlays (with audio) to a video file. It allows you to specify multiple overlays with configurable parameters such as text content, display duration, position, font settings, background style, and optional animations. You can also specify an aud

Downloads

35

Readme

simple-text-overlay

Demos (click to view on Youtube)

https://youtu.be/oFHYaB9n5bk?si=6bqOO1RNWYpVwEx4

https://www.youtube.com/watch?v=lkshQctBXG4

Installation

npm install simple-text-overlay

Prerequisites

ffmpeg

This package uses fluent-ffmpeg as a dependency to add the overlays on the video. You will need ffmpeg installed on your machine.

See fluent-ffmpeg package for prerequisites and installing ffmpeg.

Usage

This example shows a simple overlay with the default config. For all config options refer to the documentation.

import { addOverlay, Overlay } from 'simple-text-overlay';

const overlays: Overlay[] = [
  { start: 0, text: 'Hello' },
  { start: 1, text: 'World!' },
  { start: 2, text: 'Each' },
  { start: 3, text: 'second' },
  { start: 4, text: 'is' },
  { start: 5, text: 'a' },
  { start: 6, text: 'new' },
  { start: 7, text: 'caption.' },
];

// optional config
const config = {};

addOverlay('src.mp4', overlays, 'output.mp4', config);

For more examples see the examples folder.

Documentation

Overview

The addOverlay function adds text overlays to a video file. It allows you to specify multiple overlays with configurable parameters such as text content, display duration, position, font settings, background style, and optional animations. You can also specify an audio file to be added with the overlay.

Function Signature

export const addOverlay = async (
  src: string,
  overlays: Overlay[],
  output: string,
  config?: OverlayConfig
): Promise<void>;

Parameters

  • src (string): The source video file path.
  • overlays (Overlay[]): An array of Overlay objects specifying the text overlays to be added.
  • output (string): The output file path where the video with overlays will be saved.
  • config (OverlayConfig, optional): Additional configuration options for the overlays.

Types

Overlay

An overlay object defines a text overlay that will be displayed on the video.

export type Overlay = {
  text: string; // The text content of the overlay.
  start: number; // The start time (in seconds) when the overlay should appear.
  end?: number; // The end time (in seconds) when the overlay should disappear. If undefined, will default to the next overlay's start or the duration of the clip
};

OverlayConfig

The complete configuration options for the overlays.

export type OverlayConfig = {
  audioPath?: string; // Optional path of an audio file to add to the video with the text overlay.
  fontConfig?: FontConfig; // Optional configuration of the font used for the overlay.
  backgroundConfig?: BackgroundConfig; // Optional configuration of the background of the overlay.
  animationConfig?: AnimationConfig; // Optional configuration of the animation of the overlay.
  overlayAlign?: OverlayAlignOptions; // Optional position of the overlay on the video.
  overlayMargin?: number; // Optional margin of the overlay in pixels.
};

FontConfig

Configuration options for the font used in the overlays.

export type FontConfig = {
  name?: string; // The name of the font (e.g., Arial).
  size?: number; // The font size in pixels.
  color?: string; // The font color (e.g., white).
  lineHeight?: number; // The line height of the text.
  weight?: 'normal' | 'bold' | 'bolder' | 'lighter' | number; // The font weight.
};

BackgroundConfig

Configuration options for the background of the overlays.

export type BackgroundConfig = {
  color: string; // The background color (e.g., black).
  padding: number; // The padding around the text in pixels.
  borderRadius?: number; // The border radius of the background in pixels (optional).
};

AnimationConfig

Configuration options for the animation effects of the overlays.

export type AnimationConfig = {
  duration: number; // The duration of the animation effect in seconds.
};

Example Usage

import { addOverlay, Overlay, OverlayConfig } from 'simple-text-overlay';

const overlays: Overlay[] = [
  {
    text: 'Hello, World!',
    start: 0,
  },
  {
    text: 'This is another caption.',
    start: 5,
  },
];

const outputFilePath = './output/video-with-overlays.mp4';

const config: OverlayConfig = {
  fontConfig: {
    name: 'Arial',
    size: 24,
    color: 'white',
  },
  backgroundConfig: {
    color: 'black',
    padding: 10,
  },
  animationConfig: {
    duration: 2,
  },
  overlayAlign: 'bottomRight',
  overlayMargin: 20,
};

await addOverlay('input/video.mp4', overlays, outputFilePath, config);

This function allows you to customize how text overlays are displayed on a video, including font style, background, animation, and position, providing flexibility in creating dynamic video content.