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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@silyze/async-audio-ffmpeg

v1.0.0

Published

ffmpeg wrapper for @silyze/async-audio-stream

Readme

Async Audio FFmpeg

Async Audio FFmpeg is a thin, zero‑dependency wrapper around FFmpeg that plugs straight into @silyze/async-audio-stream.
It lets you encode and decode audio on‑the‑fly using FFmpeg’s pipes, fully async/await‑friendly and abort‑signal aware.


Install

npm install @silyze/async-audio-ffmpeg

Prerequisite: FFmpeg must be available in your $PATH (≥ 5.x recommended).


Quick start

import createAudioFormat from "@silyze/async-audio-ffmpeg";

// Define an Opus‑in‑WebM format:
export const OpusFormat = createAudioFormat("webm-opus", () => [
  "-c:a",
  "libopus",
  "-b:a",
  "24k",
  "-f",
  "webm",
]);

// Use it:
const format = new OpusFormat(8000); // PCM sample‑rate → 8 kHz

console.log(format.name); // "webm-opus"
console.log(format.pcmSampleRate); // 8000

API

createAudioFormat(name, flags, extraFlags?) ⇒ AudioFormat subclass

| Parameter | Type | Description | | ------------ | ------------------------------------------------------- | ------------------------------------------------------------------------------- | | name | string | Human‑readable format name. | | flags | (sampleRate: number) → string[] | Function that returns the output flags for FFmpeg (e.g. codec & container). | | extraFlags | string[] (optional) default: low‑latency preset | Extra global flags appended to every FFmpeg call. |

createAudioFormat returns a dynamic subclass of AudioFormat (@silyze/async-audio-stream) implementing:

/** Decode from <name> → PCM */
decode(input: AsyncReadStream<Buffer>): AsyncReadStream<Buffer>;

/** Encode from PCM → <name> */
encode(input: AsyncReadStream<Buffer>): AsyncReadStream<Buffer>;

readonly name: string;          // e.g. "webm-opus"
readonly pcmSampleRate: number; // sample‑rate passed to constructor

Internally it shells out to:

ffmpeg <inputFlags> pipe:0 <outputFlags> pipe:1 <extraFlags>

All data flows through stdio (pipe:0, pipe:1), keeping memory usage low and latency minimal.


Cancellation & errors

Both decode() and encode() accept an optional AbortSignal (via the pipe() options).
If the signal is aborted or the FFmpeg process exits, streaming stops cleanly.


Customising FFmpeg

  • Low‑latency preset: The default extraFlags array applies a sensible set of FFmpeg flags (-flush_packets 1, -fflags +flush_packets+nobuffer, …) for live scenarios.
    Supply your own extraFlags if you need different behaviour.

  • Sample‑rate aware flags: The flags(sampleRate) callback receives the PCM sample‑rate so you can adjust bit‑rates, filters, etc., dynamically.

Example – AAC in ADTS with 48 kHz PCM input:

export const AacAdts = createAudioFormat("aac-adts", (sr) => [
  "-c:a",
  "aac",
  "-b:a",
  sr <= 24000 ? "64k" : "128k",
  "-f",
  "adts",
]);

Type definitions

import { AsyncReadStream } from "@mojsoski/async-stream";
import { AudioFormat } from "@silyze/async-audio-stream";

/** Factory */
declare function createAudioFormat(
  name: string,
  flags: (sampleRate: number) => string[],
  extraFlags?: string[]
): {
  new (sampleRate: number): AudioFormat;
};