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

node-flv

v0.9.11

Published

https://www.npmjs.com/package/node-flv

Downloads

50

Readme

node-flv

https://www.npmjs.com/package/node-flv

Overview

The purpose of this package is to give you an ability to parse FLV stream on the fly and get highly structured and strongly typed FLV container data that can be modified and built back into a buffer. Covered with tests.

API

const fileReadStream = fs.createReadStream('file.flv');

const flvStream = new FlvStreamParser();

flvStream.on('flv-header', (flvHeader: FlvHeader) => {
  // this will most certainly fire first
  // it's a header of the flv stream

  flvHeader.build();
});

flvStream.on('flv-packet', (flvPacket: FlvPacket) => {
  // this is an flv packet itself
  // packets can be of three types: audio, video, metadata
  // any property of the packet that is not read only can be changed and that will be reflected in the result of the build packet function

  flvPacket.build();
});

// separate events for each packet type for your convenience

flvStream.on('flv-packet-audio', (flvPacket: FlvPacketAudio) => {});

flvStream.on('flv-packet-video', (flvPacket: FlvPacketVideo) => {});

flvStream.on('flv-packet-metadata', (flvPacket: FlvPacketMetadata) => {});

flvStream.on('flv-packet-unknown', (flvPacket: FlvPacket) => {});

fileReadStream.pipe(flvStream);

FLV Structure and Flow

FLV is a very structured datatype. It's a container that can hold various video and audio codecs. As an example, it can contain vp6, avc video codecs and mp3, aac audio codecs.

Flow

FLV stream starts with an flv header followed by separate flv packets. Most of the time first flv packet is a metadata packet that contains information about the stream. It's payload is a hash-map of data.

Metadata Example

{ duration: 10.067,
  width: 1280,
  height: 720,
  videodatarate: 1000,
  framerate: 30,
  videocodecid: 7,
  audiodatarate: 125,
  audiosamplerate: 48000,
  audiosamplesize: 16,
  stereo: true,
  audiocodecid: 10,
  date: '2019-10-05T16:11:08+03:00',
  encoder: 'Lavf57.83.100',
  filesize: 496576 }

Usually followed by a first video and audio packet. These first video and audio packets are important. They should have timestampLower of 0, clients (video-players, codec decoders) use these packets in order to initialize the whole stream. So, for example, for video packets these must be key-frame packets, otherwise players wont be able to initialize the render properly. Rest of the sequence after these first packets can vary dramatically. What is expected, of course, is that these next packets have correct values for both timestamp values timestampLower and timestampUpper.

Structure

FlvHeader

{ signature: 'FLV',
  version: 1,
  flags: 5,
  headerSize: 9 }

headerSize - byte length of the header, usually 9, reserved for backwards compatibility once the version changes

FlvPacket

Contains flv packet header and a payload.

{ header: FlvPacketHeader,
  payload: Buffer }

FlvPacketHeader

{ packetTypeId: 18,
  payloadSize: 327,
  timestampLower: 0,
  timestampUpper: 0,
  streamId: 0 }

packetTypeId - audio, video, metadata, etc

payloadSize - payload length of the current packet in bytes

timestampLower - timestamp relative to the first packet in milliseconds

timestampUpper - timestamp extension in milliseconds

streamId - always 0

Official FLV specification guide

  • https://www.adobe.com/content/dam/acom/en/devnet/flv/video_file_format_spec_v10.pdf

Usage Examples

  • https://github.com/rebelvg/flv-server

  • https://github.com/rebelvg/flv-parser-ffmpeg-streamer