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

test-engine-live-tools

v1.0.1

Published

NodeJS tools to live stream an MPEG-TS using MPEG-DASH

Downloads

13

Readme

test-engine-live-tools

Small tools and scripts for the EBU test engine platform. These allow for DASH-ing and encoding a live stream.

Installation

The easiest way to install is to use the npm package. This will give you the latest released version and install all dependencies (except ffmpeg and MP4Box, you need to provide these yourself):

# npm install test-engine-live-tools

If you wish to use a different version from the Git repository you have to clone the code and install the dependencies using npm. Also, be sure to provide your own MP4Box and ffmpeg binaries, they are not included.

# git clone https://github.com/ebu/test-engine-live-tools.git
# cd test-engine-live-tools
# npm install

Usage

In general, the tool operates by looping an MPEG-2 Transport Stream and providing that to ffmpeg using the segment muxer. The generated segments are picked up and packaged/fragmented using MP4Box. After all segments for the desired representations are available they are DASH-ed by MP4Box using the --dash-ctx option. This generates the MPD for the live stream and keeps it updated.

A command-line utility is included which allows you to easily stream from the command-line. Usage:

# bin/live-stream [-c config_file] input_file

The config_file is optional and allows you to create custom settings for your live stream without having to change anything in the sources. The input_file is mandatory and it is required that this is currently muxed as a MPEG-2 Transport Stream for easy looping of the source material. The contents of the file can be either MPEG-2 video/audio or H264/AAC, or most likely anything else that ffmpeg can extract from a MPEG-2 TS container.

Using different sources

Instead of using a looped MPEG-2 TS file directly, it is also possible to read from other input sources. By specifying an input source using a URL with a protocol, this will be directly passed to ffmpeg to read from that source. This way you can for example ingest video using UDP transport. Example usage:

# bin/live-stream udp://192.168.0.10:1234

In theory any transport protocol supported by your version of ffmpeg is allowed.

Configuration

The default configuration generates one video representation and one audio representation. See lib/config.js for details. All parameter configuration is listed as an array of arguments which NodeJS understands. Custom configuration can be created by creating a valid JSON file containing an object that overrides values of the default configuration. The complete default configuration is:

{
  segmentDir: '/tmp/dash_segment_input_dir',
  outputDir: '/tmp/dash_output_dir',
  mp4box: 'MP4Box',
  ffmpeg: 'ffmpeg',
  encoding: {
    commandPrefix: [ '-re', '-i', '-', '-threads', '0', '-y' ],
    representations: {
      audio: [
        '-map', '0:1', '-vn', '-acodec', 'aac', '-strict', '-2', '-ar', '48000', '-ac', '2',
        '-f', 'segment', '-segment_time', '4', '-segment_format', 'mpegts'
      ],
      video: [
        '-map', '0:0', '-vcodec', 'libx264', '-vprofile', 'baseline', '-preset', 'veryfast',
        '-s', '640x360', '-vb', '512k', '-bufsize', '1024k', '-maxrate', '512k',
        '-level', '31', '-keyint_min', '25', '-g', '25', '-sc_threshold', '0', '-an',
        '-bsf', 'h264_mp4toannexb', '-flags', '-global_header',
        '-f', 'segment', '-segment_time', '4', '-segment_format', 'mpegts'
      ]
    }
  },
  packaging: {
    mp4box_opts: [
      '-dash-ctx', '/tmp/dash_output_dir/dash-live.txt', '-dash', '4000', '-rap', '-ast-offset', '12',
      '-no-frags-default', '-bs-switching', 'no', '-min-buffer', '4000', '-url-template', '-time-shift',
      '1800', '-mpd-title', 'MPEG-DASH live stream', '-mpd-info-url', 'http://ebu.io/', '-segment-name',
      'live_$RepresentationID$_', '-out', '/tmp/dash_output_dir/live', '-dynamic', '-subsegs-per-sidx', '-1'
    ]
  }
}

You can use this as a basis for your own configuration. Both the ffmpeg command and MP4Box commands are generated using this configuration. You can add extra representations by overriding the encoding object.

Please not that some options are required to be able to create a valid live stream. For example: it is required that we read from stdin using ffmpeg, so -i - is required. Also it is preferred to read realtime, so -re is also needed.

The full ffmpeg command is generated by concatenating encoding.commandPrefix with the configurations in encoding.represenations. Output files will be automatically added and you should not specify those yourself.

More example configuration will be added add a later stage.

Caveats / pitfalls

Live streaming using MPEG-DASH is not always easy. To make sure that you are compatible with most DASH clients take extra care to make sure you're always generating closed GOPs, fixed segment durations and constant bit rates and that timing over segments is continuous and identical across representations. The default configuration should do just that, but be sure to keep this in mind.

Requirements

  • NodeJS 0.10.x / npm
  • ffmpeg binary compiled to taste (recommended: 2.3 or higher)
  • MP4Box binary compiled to taste (recommended: r5400 or newer)

License

Available under the BSD 3-clause license.