Skip to main content

High-performance audio decoding with FFmpeg and C++

Project description

AvioFlow

AvioFlow is a high-performance and easy-to-use streaming audio decoding library.

Features

  • Audio format: mp3, opus, flac, ogg, wav, m4a, acc. Anything.
  • Flexible Input: Files, URLs, memory buffers, and real-time streams
  • Hardware Capture: WASAPI loopback (system audio) and DirectShow (microphones)
  • Resampling: Built-in sample rate conversion
  • Zero-copy API: Direct buffer access via FrameData for maximum performance
  • Cross-platform: Windows, Linux, macOS

Supported language

C++
python pybind11 pip install avioflow
JavaScript node-add-api npm install avioflow
wasm
vsix

Installation

Python

pip install avioflow

C++ (CMake)

find_package(avioflow REQUIRED)
target_link_libraries(your_target avioflow::avioflow)

C++ API

Core Classes

AudioDecoder

Main class for audio decoding.

#include "avioflow-cxx-api.h"
using namespace avioflow;

// Constructor options
AudioStreamOptions options;
options.output_sample_rate = 16000;    // Target sample rate
options.input_format = "s16le";        // For streaming: source format
options.input_sample_rate = 48000;     // For streaming: source rate
options.input_channels = 2;            // For streaming: source channels

AudioDecoder decoder(options);

Methods

Method Description
open(source) Open file path, URL, or device
push(data, size) Push raw bytes for streaming decode
read() Decode next frame, returns FrameData. (Formerly decode_next)
get_samples() Decode all currently available samples. (Formerly get_samples)
get_metadata() Get audio metadata
is_finished() Check if EOF reached

FrameData

Zero-copy frame data structure returned by read().

struct FrameData {
    float** data;        // Planar channel pointers: data[channel][sample]
    int num_channels;    // Number of channels
    int num_samples;     // Samples per channel

    operator bool();     // True if valid data
};

⚠️ Warning: FrameData.data points to internal buffer, valid only until next read() call.

Examples

File Decoding (Offline)

AudioDecoder decoder({.output_sample_rate = 16000});
decoder.open("audio.mp3");

auto samples = decoder.get_samples();  // vector<vector<float>>
std::cout << "Channels: " << samples.size() << std::endl;
std::cout << "Samples: " << samples[0].size() << std::endl;

Frame-by-Frame Decoding

AudioDecoder decoder;
decoder.open("audio.mp3");

while (auto frame = decoder.read()) {
    // frame.data[channel][sample]
    for (int c = 0; c < frame.num_channels; c++) {
        process(frame.data[c], frame.num_samples);
    }
}

Streaming Decode (Push-based)

AudioStreamOptions opts;
opts.input_format = "s16le";
opts.input_sample_rate = 48000;
opts.input_channels = 2;

AudioDecoder decoder(opts);
decoder.push(raw_bytes, size);  // Auto-initializes on first call

auto samples = decoder.get_samples(); // Decode all buffered data
// Or frame-by-frame:
while (auto frame = decoder.read()) {
    // Process decoded audio...
}

Python API

AudioDecoder

import avioflow

# Constructor with keyword arguments
decoder = avioflow.AudioDecoder(
    output_sample_rate=16000,    # Optional: target sample rate
    input_format="s16le",        # For streaming: source format
    input_sample_rate=48000,     # For streaming: source rate
    input_channels=2             # For streaming: source channels
)

Methods

Method Returns Description
load(source) Metadata Load file, URL, pathlib.Path, or bytes-like input
decoder(data) ndarray Push bytes-like data and decode (streaming)
read() ndarray Decode next frame
get_samples() ndarray Decode all available samples
is_finished() bool Check if EOF

Metadata

# Quick metadata inspection without full decoding
meta = avioflow.info("audio.mp3")
print(f"Duration: {meta.duration}s")
print(f"Sample Rate: {meta.sample_rate}Hz")
print(f"Codec: {meta.codec}")

# Encoded audio bytes also work
with open("audio.mp3", "rb") as f:
    meta = avioflow.info(f.read())

Examples

File Decoding

decoder = avioflow.AudioDecoder(output_sample_rate=16000)
meta = decoder.load("speech.wav")
samples = decoder.get_samples()      # numpy array (channels, samples)
print(f"Shape: {samples.shape}")     # e.g., (1, 160000)

Streaming Decode

decoder = avioflow.AudioDecoder(
    input_format="s16le",
    input_sample_rate=48000,
    input_channels=2
)

while True:
    data = socket.recv(4096)
    samples = decoder(data)  # Push & get samples in one call
    if samples.size > 0:
        process_audio(samples)

Device Discovery

devices = avioflow.DeviceManager.list_audio_devices()
for dev in devices:
    print(f"{dev.name}: {dev.description}")

Logging

avioflow.set_log_level("debug")  # quiet, error, warning, info, debug, trace

Node.js API

Compatibility

Runtime Version Support
Node.js 16, 18, 20, 22+ ✅ Native (N-API)
Electron All versions ✅ Supported (requires rebuild)
Architectures x64 ✅ Linux, Windows

Installation

npm install avioflow

ESM Import

import avioflow from 'avioflow';

Module-level Functions

Function Returns Description
load(path, options?) {metadata, samples} Convenience: Opens, decodes all samples, and returns both in one call.
listAudioDevices() DeviceInfo[] List available system audio devices.
setLogLevel(level) void Set FFmpeg log level ("quiet", "info", "debug", etc.).

AudioDecoder

// Constructor with options object
const decoder = new avioflow.AudioDecoder({
    outputSampleRate: 16000,    // Optional: target sample rate
    outputNumChannels: 1,       // Optional: target channels
    inputFormat: 's16le',       // For streaming: source format
    inputSampleRate: 48000,     // For streaming: source rate
    inputChannels: 2            // For streaming: source channels
});

Methods

Method Returns Description
load(source) Metadata Load file, URL, or device name. Returns metadata.
push(buffer) void Push raw encoded bytes for streaming.
read() Float32Array[] | null Decode next frame. Returns array of channel data.
getSamples() Float32Array[] Decode all available samples at once.
isFinished() boolean Check if end of stream reached.

Examples

Quick File Loading (Recommended)

// Opens file, resamples to 16kHz mono, and decodes everything
const { metadata, samples } = avioflow.load("audio.mp3", {
    outputSampleRate: 16000,
    outputNumChannels: 1
});

console.log(`Duration: ${metadata.duration}s`);
console.log(`Channels: ${samples.length}, Samples: ${samples[0].length}`);

Batch Decoding with Decoder Instance

const decoder = new avioflow.AudioDecoder({ outputSampleRate: 44100 });
const meta = decoder.load("audio.wav");

// Decodes the entire file into memory
const allSamples = decoder.getSamples();
process(allSamples);

Streaming Decode (Real-time)

const decoder = new avioflow.AudioDecoder({
    inputFormat: 's16le',
    inputSampleRate: 48000,
    inputChannels: 2
});

socket.on('data', (chunk) => {
    decoder.push(chunk);

    // Get all samples decoded from this chunk
    const samples = decoder.getSamples();
    if (samples.length > 0) {
        processAudio(samples);
    }
});

Device Discovery

const devices = avioflow.listAudioDevices();
devices.forEach(dev => {
    console.log(`${dev.isOutput ? 'Output' : 'Input'}: ${dev.name} (${dev.description})`);
});

Build from Source

Prerequisites

  • CMake 3.20+
  • Visual Studio 2022+ (Windows) or GCC 11+ (Linux)
  • Python 3.8+ with pybind11 (for Python bindings)
  • Node.js 16+ (for Node.js bindings)

C++ & Python Build

./build.sh

This will build the C++ library, Python bindings, and package a Python wheel.

Node.js Build

./build-nodejs.sh

This will build the Node.js bindings using cmake-js and run compatibility tests.


Supported Formats

AvioFlow supports a wide range of audio formats, codecs, and devices through FFmpeg.

For a complete and detailed list of supported decoders, encoders, and input formats, please refer to the Supported Formats Reference.


License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

avioflow-0.2.3-cp313-cp313-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.13Windows x86-64

avioflow-0.2.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

avioflow-0.2.3-cp312-cp312-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.12Windows x86-64

avioflow-0.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

avioflow-0.2.3-cp311-cp311-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.11Windows x86-64

avioflow-0.2.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

avioflow-0.2.3-cp310-cp310-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.10Windows x86-64

avioflow-0.2.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

avioflow-0.2.3-cp39-cp39-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.9Windows x86-64

avioflow-0.2.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

avioflow-0.2.3-cp38-cp38-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.8Windows x86-64

avioflow-0.2.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file avioflow-0.2.3-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: avioflow-0.2.3-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for avioflow-0.2.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 088fe05564afa0141198d717d023c1ebb274fc53ce215e9fccf538a79cf6f1d6
MD5 49002ec0ae38e09828d55bb7e6a47a92
BLAKE2b-256 6b18219435e979f6400f89e811b300acb51a25cb66361e7b38883c3a032ddecf

See more details on using hashes here.

File details

Details for the file avioflow-0.2.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for avioflow-0.2.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4da4080d29a4095730902fedba0c22410ab32098efc0613defb25c4cadd92ead
MD5 7940c53fa4170d1bcf56776f64f65fa5
BLAKE2b-256 e9eb056bf81ae53f8d58589112a0b37bf987519777cdc0315b7ff6f0e7cc4fec

See more details on using hashes here.

File details

Details for the file avioflow-0.2.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: avioflow-0.2.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for avioflow-0.2.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3e97f21623860a038009203689634e780b15ba9b6aa86cca434b0223a22d6954
MD5 68aeee09c5868a29a8ad48f261349157
BLAKE2b-256 df5aa46d3b4e3564c97a5725b75759f517e9eb5c08717494394d59c5fa2cc1c9

See more details on using hashes here.

File details

Details for the file avioflow-0.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for avioflow-0.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 138c406f05731f8ba3663b1286c58f97743508053a3d5a4572eced854018aad9
MD5 5783c6ca172f11faef9561b73ff93caf
BLAKE2b-256 089140eb4eb76a82a869958fbc3bfe4146530daebf560c5b5bb05b192bf6b603

See more details on using hashes here.

File details

Details for the file avioflow-0.2.3-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: avioflow-0.2.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for avioflow-0.2.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7a134b04b1b9d4f8599df9252b3bb75cb11581d6f7c21bd20265ba8ebab8d0e9
MD5 b7b327b6e9cac5826300afad636511a2
BLAKE2b-256 2e1b07a6b322e71b0f10f9924148115beeec7090078045b3db8f926252bb1e44

See more details on using hashes here.

File details

Details for the file avioflow-0.2.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for avioflow-0.2.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a61e8aab45cd0175bcdd71a22006706e14983832a5ae46cd9e06b998994089d7
MD5 4b2a7686234cf9d119488e6222045ea6
BLAKE2b-256 7832a952d534838af40815d0f095ec57ad5a71ce8a77a0124622c14f2f7ca8ce

See more details on using hashes here.

File details

Details for the file avioflow-0.2.3-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: avioflow-0.2.3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for avioflow-0.2.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 804c994c64c2482e70dbf88c22fcb7058f630b2c02ae7d2600954f6ab43064aa
MD5 b8895ec57d15fe2d0da23c4b36f4137d
BLAKE2b-256 c1d51dc63d92aa991ce4c4eec37332d187a8e60290bf54d07097e3314802cd70

See more details on using hashes here.

File details

Details for the file avioflow-0.2.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for avioflow-0.2.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4488ba4de98cf4783f2dffa2ad6be8d4ed19047a633d499dbd759ee102cbe96e
MD5 a68a365a8d624d07582642499e07fef9
BLAKE2b-256 c4af1039c3816105cfed5068b2999078f270b3ad195bf679345002fa7be4ee84

See more details on using hashes here.

File details

Details for the file avioflow-0.2.3-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: avioflow-0.2.3-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for avioflow-0.2.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 8c21e0c004670439dec36311997e12be6ad1d2229e48458e7d7bb44ef0b38be5
MD5 3d422f4ca2df08918400e45dc84079e4
BLAKE2b-256 2602c1fff5e3bacf9e5936658e16146d5f7f9c01064da407b00ee701b1821500

See more details on using hashes here.

File details

Details for the file avioflow-0.2.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for avioflow-0.2.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1cbfd77b334025f7d81c617adf4c8e049fc59bc55e1cf25a3d152c3faf3a0aa9
MD5 995be56b9b00871f748216ced6481859
BLAKE2b-256 90a2cce39c45646b1d33c2bc10e395860bb70887e89b569264ca7bcfa46695fe

See more details on using hashes here.

File details

Details for the file avioflow-0.2.3-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: avioflow-0.2.3-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for avioflow-0.2.3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a2c6991a34f830cdf28252ce5e679c188dd85fb4a7a83c2aae7687b90abda9f2
MD5 0f83f5bb4a845956e2dcc755a11bc835
BLAKE2b-256 ff4164201ebda260fbc5251546dd7438f67d2c94bbaaaf8da9a8830f2cdc419a

See more details on using hashes here.

File details

Details for the file avioflow-0.2.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for avioflow-0.2.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fc35c9286a1331b9ec90848c932cac993d6d793a0a46ee3fc92cf52adeab1c38
MD5 69c861de0669e13c5484c5a96365b6e8
BLAKE2b-256 336d5067d745237000613b19ed190dbf0263310b12ef6e02e88a8cc3b5429602

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page