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

@mediafish/flv

v0.2.2

Published

A library to read/write FLV file format

Downloads

72

Readme

Build Status Coverage Status Dependency Status Development Dependency Status Known Vulnerabilities npm Downloads XO code style

flv

A library to read/write Flash Video file format (only supports AAC/AVC)

Install

NPM

Usage

Example of reading FLV file

const {readFile, print} = require('@mediafish/flv');

const buf = fs.readFileSync('test.flv');
const [offset, flv] = readFile(buf, offset);
print(flv);
/*
FLVFile {
  FLVHeader: {
    version: 1,
    hasAudio: true,
    hasVideo: true
  },
  body: [
    FLVTag: {
      timestamp: 0,
      AVC: {
        frameType: 'keyframe',
        codec: 'AVC',
        packetType: 'NALU',
        data: <Buffer length=1024 >
      }
    },
    FLVTag: {
      timestamp: 0,
      AAC: {
        format: 'AAC',
        sampleRate: '44kHz',
        size: '16Bit',
        isStereo: true,
        packetType: 'raw',
        data: <Buffer length=1024 >
      }
    },
    ...
  ]
}
*/

Example of reading Video and Audio

const {readVideo, readAudio, print} = require('@mediafish/flv');

const [offset, video] = readVideo(buf1, offset);
print(video);
/*
AVC: {
  frameType: 'keyframe',
  codec: 'AVC',
  packetType: 'NALU',
  data: <Buffer length=1024 >
}
*/

const [offset, audio] = readAudio(buf2, offset);
print(audio);
/*
AAC: {
  format: 'AAC',
  sampleRate: '44kHz',
  size: '16Bit',
  isStereo: true,
  packetType: 'raw',
  data: <Buffer length=1024 >
}
*/

Example of writing FLV

const {writeData, type: {Video, AVC, Audio, AAC, FLVFile, FLVHeader, FLVTag}} = require('@mediafish/flv');

const video = new AVC({
  frameType: Video.FrameType.keyframe,
  codec: Video.Codec.AVC,
  packetType: AVC.PacketType.NALU,
  compositionTimeOffset: 0,
  data: buf1
});


const audio = new AAC({
  format: Audio.SoundFormat.AAC,
  sampleRate: Audio.SampleRate._44kHz,
  size: Audio.SampleLength._16Bit,
  isStereo: true,
  packetType: AAC.PacketType.Raw,
  data: buf2
});

const header = new FLVHeader({version: 1, hasAudio: true, hasVideo: true});

const tags = [
  new FLVTag({type: FLVTag.TagType.audio, timestamp: 0, data: audio}),
  new FLVTag({type: FLVTag.TagType.video, timestamp: 0, data: video})
];

const flv = new FLVFile(header, tags);

// First, pass null instead of a buffer to detect how many bytes are needed
const byteLength = writeData(flv, null, 0);
// And then alloc a buff
const buffer = Buffer.alloc(byteLength);
// Finally, write the data actually to the buffer
writeData(flv, buffer, 0);

Example of writing Video and Audio

const {writeData, type: {Video, AVC, Audio, AAC}} = require('@mediafish/flv');

const video = new AVC({
  frameType: Video.FrameType.keyframe,
  codec: Video.Codec.AVC,
  packetType: AVC.PacketType.NALU,
  compositionTimeOffset: 0,
  data: buf1
});


const audio = new AAC({
  format: Audio.SoundFormat.AAC,
  sampleRate: Audio.SampleRate._44kHz,
  size: Audio.SampleLength._16Bit,
  isStereo: true,
  packetType: AAC.PacketType.Raw,
  data: buf2
});

// First, pass null instead of a buffer to detect how many bytes are needed
const videoLength = writeData(video, null, 0);
const audioLength = writeData(audio, null, 0);
// And then alloc a buff
const buffer = Buffer.alloc(videoLength + audioLength);
// Finally, write the data actually to the buffer
let offset = 0;
offset = writeData(video, buffer, offset);
offset = writeData(audio, buffer, offset);

API

readFile(buffer, offset)

Read FLV file from the buffer

params

| Name | Type | Required | Default | Description | | -------- | ------- | -------- | ------- | ------------- | | buffer | Buffer or Uint8Array | Yes | N/A | The buffer from which the data is read | | offset | number | Yes | N/A | An integer to specify the position within the buffer |

return value

An array containing the following pair of values

| Index | Type | Description | | ----- | ------ | ------------ | | [0] | number | An integer to indicate the position from which the next data should be read | | [1] | FLVFile | The read data (See Data format) |

readVideo(buffer, offset, length)

Read video data from the buffer

params

| Name | Type | Required | Default | Description | | -------- | ------- | -------- | ------- | ------------- | | buffer | Buffer or Uint8Array | Yes | N/A | The buffer from which the data is read | | offset | number | Yes | N/A | An integer to specify the position within the buffer | | length | number | Yes | N/A | An integer to specify how many bytes to read |

return value

An array containing the following pair of values

| Index | Type | Description | | ----- | ------ | ------------ | | [0] | number | An integer to indicate the position from which the next data should be read | | [1] | AVC | The read data (See Data format) |

readAudio(buffer, offset)

Read audio data from the buffer

params

| Name | Type | Required | Default | Description | | -------- | ------- | -------- | ------- | ------------- | | buffer | Buffer or Uint8Array | Yes | N/A | The buffer from which the data is read | | offset | number | Yes | N/A | An integer to specify the position within the buffer | | length | number | Yes | N/A | An integer to specify how many bytes to read |

return value

An array containing the following pair of values

| Index | Type | Description | | ----- | ------ | ------------ | | [0] | number | An integer to indicate the position from which the next data should be read | | [1] | AAC | The read data (See Data format) |

writeData(data, buffer, offset)

Write data to the buffer

params

| Name | Type | Required | Default | Description | | -------- | ------- | -------- | ------- | ------------- | | data | AVC/AAC/FLVHeader/FLVTag/FLVFile | Yes | N/A | The data to be written to the buffer | | buffer | Buffer | No | null | The buffer to which the data is written. If null, only the necessary buffer size is calculated | | offset | number | Yes | N/A | An integer to specify the position within the buffer |

return value

An integer to indicate the position from which the next data should be read

setOptions(obj)

Updates the option values

params

| Name | Type | Required | Default | Description | | ------- | ------ | -------- | ------- | ------------- | | obj | Object | Yes | {} | An object holding option values which will be used to overwrite the internal option values. |

supported options

| Name | Type | Default | Description | | ---------- | ------- | ------- | ------------- | | strictMode | boolean | false | If true, the function throws an error when the method invocations failed. If false, the function just logs the error and continues to run.|

getOptions()

Retrieves the current option values

return value

A cloned object containing the current option values

Data format

This section describes the structure of the data that can be read / written using readFile/readAudio/readVideo

FLVFile

| Property | Type | Description | | -------- | ----------- | ------------- | | header | FLVHeader | An instance of FLVHeader | | body | [FLVTag] | An array of FLVTag |

FLVHeader

| Property | Type | Description | | ---------- | ------- | ------------- | | version | number | FLV version | | hasAudio | boolean | Audio tags are present | | hasVideo | boolean | Video tags are present |

FLVTag

| Property | Type | Description | | ----------- | --------------------- | ------------- | | type | enum FLVTag.TagType | Type of this tag | | timestamp | number | Time in milliseconds at which the data in this tag applies | | data | Audio or Video | An instance of Audio / Video |

Audio

| Property | Type | Description | | ------------ | ------------------------- | ------------- | | format | enum Audio.SoundFormat | Type of this tag. Only AAC is supported. | | sampleRate | enum Audio.SampleRate | sample rate | | size | enum Audio.SampleLength | bits per sample | | isStereo | boolean | mono / stereo | | data | Buffer or Uint8Array | Format specific data. |

AAC extends Audio

| Property | Type | Description | | ------------ | --------------------- | --------------- | | packetType | enum AAC.PacketType | AAC packet type |

Video

| Property | Type | Description | | ----------- | ------------------------ | ------------- | | frameType | enum Video.FrameType | Type of the frame included in this tag | | codec | enum Video.Codec | Type of codec used to compress the frame. Only AVC is supported. | | data | Buffer or Uint8Array | Codec specific data. |

AVC extends Video

| Property | Type | Description | | ----------------------- | --------------------- | --------------- | | packetType | enum AVC.PacketType | AVC packet type | | compositionTimeOffset | number | Composition time offset |