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

stream-linker

v1.3.1

Published

StreamLinker: Effortlessly integrate continuous live streaming with dynamic file appending for uninterrupted broadcasts.

Downloads

29

Readme

Read this in other languages: English | Tiếng Việt

StreamLinker

StreamLinker is a library that allows you to connect and livestream video data from an input source to an RTMP path. This library utilizes ffmpeg, bullmq and hls-maker technologies for video processing.

Installation

npm install stream-linker

Notes

  • Make sure you have ffmpeg and necessary libraries installed before using this library.
  • Make sure you have Redis installed and running on your system, as StreamLinker uses BullMQ, a Redis-based queue library. You can refer to BullMQ's documentation for advanced Redis configurations.

Usage

const { StreamLinker, StreamLinkerConfig } = require('stream-linker');

const options: StreamLinkerConfig = {
    rtmpOuputPath: 'rtmp://example.com/live/streamkey',
    startInputFilePath: '/path/to/your/source/file',
    // ... other options as needed
};

const linker = new StreamLinker(options);

// Start livestreaming video
linker.start();

Tutorial Video

Tutorial Video

API

Class: StreamLinker

Constructor

new StreamLinker(options: StreamLinkerConfig);

Creates a new instance of StreamLinker.

Method: start

linker.start(): Promise<void>

Initiates the video livestream. This method will begin the video conversion process and stream it to the provided RTMP path.

Method: append

StreamLinker.append(sourceFilePath: string, rtmpOuputPath: string, redisConfig?: ConnectionConfig): Promise<void>

Appends video to the live stream. This method allows you to add additional segments to the ongoing stream.

Method: insert

StreamLinker.insert(sourceFilePath: string, rtmpOuputPath: string, redisConfig?: ConnectionConfig): Promise<void>

Insert video to the live stream. This method allows you to insert additional segments to the ongoing stream.

Method: stop

StreamLinker.stop(rtmpOuputPath: string, redisConfig?: ConnectionConfig): Promise<boolean>

Stops the livestream for the specified RTMP output path.

Configuration

Interface: StreamLinkerConfig

interface StreamLinkerConfig {
    rtmpOuputPath: string; 
    standbyInputFilePath?: string;
    startInputFilePath: string;
    isAppendDefault?: boolean;
    workerConnection?: ConnectionConfig,
    queueConnection?: ConnectionConfig,
    ffmpegHLSOptions?: ffmpegOptions,
    ffmpegStreamOptions?: ffmpegOptions
}
  • rtmpOuputPath (string): Destination RTMP stream.

  • startInputFilePath (string): Path to the source video file.

  • standbyInputFilePath (optional, string): Path to a backup video file. Activated if the source video ends. If not provided, the source video is looped.

  • isAppendDefault (optional, boolean): Default is true. If it is false stream will be stopped when video source ends (no loop)

  • workerConnection (optional, ConnectionConfig): Redis connection for the worker.

  • queueConnection (optional, ConnectionConfig): Redis connection for the queue.

  • ffmpegHLSOptions (optional) Ffmpeg options for conversion input video to HLS

  • ffmpegStreamOptions (optional) Ffmpeg options for live streaming

Configuration for StreamLinker. Includes necessary information for initializing and configuring the livestream.

Example

const { StreamLinker, StreamLinkerConfig } = require('stream-linker');

const redisConfig = {
    host: '127.0.0.1', 
    port: 6379,
    username: 'default',
    password: 'passWord',
    db: 0
}

const options: StreamLinkerConfig = {
    rtmpOuputPath: 'rtmp://example.com/live/streamkey',
    startInputFilePath: '/path/to/source/video.mp4',
    standbyInputFilePath: '/path/to/standby/video.mp4', // Optional
    workerConnection: redisConfig, // Optional
    queueConnection: redisConfig, // Optional
    ffmpegStreamOptions: {
        input: [
            '-re', 
            '-live_start_index', '50'
        ], 
        output: [
            '-c', 'copy', 
            '-preset', 'veryfast', 
            '-f', 'flv', 
            '-flvflags', 'no_duration_filesize'
        ]
    }, // Optional
    ffmpegHLSOptions: { 
        input: ['...'], 
        output: ['...']
    }, // Optional
    
};

const linker = new StreamLinker(options);

// Start livestreaming video
linker.start();

// Append additional video to the live stream 
// redisConfig param is optional
StreamLinker.append('/path/to/another/source/file', 'rtmp://example.com/live/streamkey', redisConfig);

// Insert additional video to the live stream
// redisConfig param is optional
StreamLinker.insert('/path/to/another/source/file', 'rtmp://example.com/live/streamkey', redisConfig);

// Stop the livestream
// redisConfig param is optional
StreamLinker.stop('rtmp://example.com/live/streamkey', redisConfig);

// Events tracking
stream.on('startStream', function (ffmpegCommand) {
    console.log("onStartStream", ffmpegCommand)
});

stream.on('progressStream', function (totalFrames, progressFrames) {
    console.log("onProgressStream", totalFrames, progressFrames);
});

stream.on('endStream', function (streamOutput) {
    console.log("onEndStream", streamOutput);
});

stream.on('errorStream', function (err, stdout, stderr) {
    console.log("err", err, "stdout", stdout, "stderr", stderr);
});

stream.on('completed', function (value) {
    console.log("onCompleted", value);
});

Command Line Interface (CLI)

StreamLinker provides a CLI for seamless streaming. Below are the available commands and their usage:

Installation

Install StreamLinker globally using npm:

npm install -g stream-linker

Start Command

You can use -h or --help to see the available options.

stream-linker -h

Launch your stream with StreamLinker:

stream-linker start -i <inputPath> -o <outputUrl> [-s <standbyPath>]
  • -i, --input <inputPath>: Path to the input video file. Must be specified.
  • -o, --output <outputUrl>: RTMP output URL for live streaming. Must be specified.
  • -s, --standby <standbyPath> (optional): Path to the standby video for no signal.
  • ... use stream-linker start -h to see the available options.

Example:

stream-linker start -i /path/to/input/video.mp4 -o rtmp://example.com/live/streamkey -s /path/to/standby/video.mp4

Append Command

Append a video to your live stream:

stream-linker append -i <inputPath> -o <outputUrl>
  • -i, --input <inputPath>: Path to the input video file. Must be specified.
  • -o, --output <outputUrl>: RTMP output URL for live streaming. Must be specified.
  • ... use stream-linker append -h to see the available options.

Example:

stream-linker append -i /path/to/another/video.mp4 -o rtmp://example.com/live/streamkey

Insert Command

Insert a video to your live stream:

stream-linker insert -i <inputPath> -o <outputUrl>
  • -i, --input <inputPath>: Path to the input video file. Must be specified.
  • -o, --output <outputUrl>: RTMP output URL for live streaming. Must be specified.
  • ... use stream-linker insert -h to see the available options.

Example:

stream-linker insert -i /path/to/another/video.mp4 -o rtmp://example.com/live/streamkey

Stop Command

Stop a livestream for a specific output URL:

stream-linker stop <outputUrl>
  • <outputUrl>: RTMP output URL for live streaming. Must be specified.
  • ... use stream-linker stop -h to see the available options.

Example:

stream-linker stop rtmp://example.com/live/streamkey

Note:

  • Make sure you have installed StreamLinker globally using npm install -g stream-linker before using the CLI.
  • Ensure that both the input and standby video files exist at the specified paths.

Support

Contact the author: [email protected]

License

This library is released under the MIT License.