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

avi.js

v1.0.0

Published

Parse AVI files with Node.js

Downloads

4

Readme

avi.js

Parse AVI files, modify frames and write new AVI files.

Install

npm install avi.js

Usage

import AVIReader from './index.js';

const aviReader = new AVIReader('./video.avi');

const data = aviReader.read();

Example

const aviReader = new AVIReader('./video.avi');

const data = aviReader.read();

// create `Frames` object from parsed file
const Frames = AVIReader.getFrames(data);

// obtain all keyframes from `Frames` object
const keyframes = Frames.getKeyframes();

// duplicate every 5 keyframes
for (let i = 1; i < keyframes.length; i += 5) {
  keyframes[i].duplicate();
  // or: keyframes[i].delete()
}

// or randomise all frames...
// frames.getFrames().sort(() => 0.5 - Math.random());

// replace the frames in the loaded file with new ones
aviReader.replaceFrames(frames);

// write modified video to file
aviReader.write('./glitch.avi');

AVIReader

const aviReader = new AVIReader('./video.avi');

aviReader.read();
aviReader.write(path);
aviReader.replaceFrames(frames);

// static
AVIReader.getFrames(parsed);

read()

returns: an object containing the parsed AVI file.

Obtains the file buffer and starts parsing it.

write(path: string)

  • path: string denoting the file path to write the AVI to.

Writes the loaded and potentially modified AVI to the given file.

replaceFrames(frames: Frames)

  • frames: replaces the frames inside the loaded AVI file with the given frames. Expects a Frames object.

AVIReader.getFrames(parsed: object)

  • parsed: obtains a Frames object from the parsed AVI file. Expects the structure returned from read()

Parsed object

The read() function returns an object containing the parsed data.

An AVI file is made up of two primary structures:

  • list: a list object can hold more lists, or chunks
  • chunk: a chunk object holds data, such as headers, frame data, etc

This library denotes a list with the following object:

{
  list: string, // usually just 'LIST'
  listSize: number, // size of list in bytes
  listType: string, // name of list
  data: object, // list data
}

Details:

  • list: property is usually LIST, but the main file itself is represented as a list where the list property is RIFF.
  • listType: property describes the data in the list, e.g. strh would denote the stream headers.
  • data: property holds all the parsed data for the list elements. Usually chunks or more lists. Each element inside this object will be chnk{n} or list{n} where n denotes the index of the item in the list.

This library denotes a chunk with the following object:

{
  chID: string, // chunk id
  ckSize: number, // size of chunk in bytes
  ckData: object, // list data
}

Details:

  • ckID: property can be used for frame data to denote where it is an audio frame, or video frame, etc.
  • ckData: property holds either a raw buffer (e.g. frame data) or parsed chunk data (an object).

An example of the structure returned from read():

{
  list: 'RIFF',
  listSize: 26622146,
  listType: 'AVI ',
  data: {
    list0: {
      list: 'LIST',
      listSize: 8906,
      listType: 'hdrl',
      data: [Object]
    },
    list1: {
      list: 'LIST',
      listSize: 26,
      listType: 'INFO',
      data: [Object]
    },
    chnk2: {
      ckID: 'JUNK',
      ckSize: 1016,
      ckData: <Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... 966 more bytes>
    },
    list3: {
      list: 'LIST',
      listSize: 26419802,
      listType: 'movi',
      data: [Object]
    },
    chnk4: {
      ckID: 'idx1',
      ckSize: 192352,
      ckData: [Object]
    }
  }
}

Frames

const aviReader = new AVIReader('./video.avi');
const data = aviReader.read();
const Frames = AVIReader.getFrames(data);

Frames.getFrames();
Frames.getKeyframes();

getFrames()

Returns a list of all frames.

getKeyframes()

Returns a list of only keyframes.

Frame

const Frames = AVIReader.getFrames(data);

const frames = Frames.getFrames();
const first = frames[0];

first.duplicate();
first.delete();

duplicate()

Duplicates the frame in place.

delete()

Deletes the frame.

Frame object

The Frames object holds an array of frames, each one is of the following structure:

{
  id: string, // frame id
  size: number, // frame data size
  data: Buffer, // frame data
  flags: object, // frame flags
  _id: string, // ignore: internal library id
  delete: function, // call to delete frame
  duplicate: function, // call to duplicate frame
}

An example of a frame:

{
  id: '01wb',
  size: 384,
  data: <Buffer ff fb 94 ... 381 more bytes>,
  flags: {
    AVIIF_LIST: 0,
    AVIIF_TWOCC: 0,
    AVIIF_KEYFRAME: 0,
    AVIIF_FIRSTPART: 0,
    AVIIF_LASTPART: 0,
    AVIIF_MIDPART: 0,
    AVIIF_NOTIME: 256,
    AVIIF_COMPUSE: 0
  },
  _id: '0_01wb_384',
  delete: [Function: delete],
  duplicate: [Function: duplicate]
}

Sources

MSDN - AVI RIFF File Reference

hackaday.io - AVI File Format

jmcgowan.com - OpenDML AVI File Format Extensions