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 configure and build the C++ library and Python bindings.

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.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

avioflow-0.2.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

avioflow-0.2.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

avioflow-0.2.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

avioflow-0.2.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

avioflow-0.2.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

avioflow-0.2.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

avioflow-0.2.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

avioflow-0.2.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

avioflow-0.2.6-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

avioflow-0.2.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

avioflow-0.2.6-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.5 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

File details

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

File metadata

File hashes

Hashes for avioflow-0.2.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6bec7cb4a89bb8c2d146c0fe7e64825c013ea9da92bfef8eeb9a3aa9273171f0
MD5 9b05867defd8b1bef3a4ebc98914d8b3
BLAKE2b-256 4e481b44f9694fd295ae21a19c71e30b572598b416b1d0c49cc58328d8f919fb

See more details on using hashes here.

File details

Details for the file avioflow-0.2.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for avioflow-0.2.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c670b035fae110678c286d091f3b97dc607e45826284ab73f5b3fb0f448b7b73
MD5 00ee9007e84b2bb3e9bca2d91aeb1176
BLAKE2b-256 69a748fa47ac7fa4e5a4fd3cb8b5c3ee21edffdf4a51f6a96926d50dc5c196eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.2.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9e591cb4b8daa55a18e0b7512d3c2194110793ba6d68cfb65dfcc3f181a1d3b8
MD5 3bf957830495d4c5147cddcc9b0b8163
BLAKE2b-256 7c8d9355b0dc4211a84d4563d0f0cbb3602bf7469ba696f12cce763215885a3f

See more details on using hashes here.

File details

Details for the file avioflow-0.2.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for avioflow-0.2.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e915af1e6a57841ee8728d1b1b20817f3fc8fd1254d371311e9c1458033635f1
MD5 61a6648444b88cf4655a36d8fe2f9c75
BLAKE2b-256 e7d672dd5c6b1ff3cf020ae5b8076f39076bea00bebdee033b7ccf464a52f48d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.2.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 59554dd4f44809e75ae0bc27e0ea428eed2c0e09f003fa66dac2606db63dc8c8
MD5 e5d852d1567b35e2dde3ac38268bb153
BLAKE2b-256 41b37c986350acc44f7e5ed7f74e39af809a845dded03db58ed0ac800c935c12

See more details on using hashes here.

File details

Details for the file avioflow-0.2.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for avioflow-0.2.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5c76e518ed33d63a7a2523749dc46d707b5c4c980897dd0a7384b1d398ac987e
MD5 eaa47232d8ba7c092df3c49cc3b7847e
BLAKE2b-256 54753d678a92996c0955cf979baa66e475f8385760372e59e6d971db86b7e7e6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.2.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 15657bbaf3b46031e5d6a7b76dc0b82b54946bcec8f1cbe954955615f258bea6
MD5 0d73fe03fb2c3e838a7416ae8ecafcb1
BLAKE2b-256 947677ef2d0ec795aef33c2de676aca6f20b6a5aab99dfb367a5efd55e0d0c51

See more details on using hashes here.

File details

Details for the file avioflow-0.2.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for avioflow-0.2.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9ced71d0d6382b14c05d2a2ea7160db92596eeb5c3c55d106e8f89dd6c9e31d3
MD5 6349d58d019cb365b60c00abc3162920
BLAKE2b-256 d08e41a7d9f5080e8645334058b56400f3fa482ec2e80c21a849ee3f4bbb6212

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.2.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1a7352848e3fa6ec54fb555b2df6c790ece196419298d8ff2e96523d051b3ea9
MD5 3f1189d4b0c0221a3bab206843549117
BLAKE2b-256 b1a5b3fdebefc58d511a094a5905a8e22cac003eb90ea34eb297a3b17704ae43

See more details on using hashes here.

File details

Details for the file avioflow-0.2.6-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for avioflow-0.2.6-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0fd167ce0c28e490120558b1331ed4d586e3ea161a0413c0aed3b24dae58277e
MD5 294be3d5251004096b91a8d53bc6d8d8
BLAKE2b-256 314040c9cd745c5c6a565ed2001ac743512ba061cbf8e4dc8eec7c0d1969405b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.2.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 647a5eb596716a6a78294aee4351bc993b24da95d4586e71979ce87321709daa
MD5 91b295bced642b903770765b68eb2a5c
BLAKE2b-256 8f5e266d33c9d2709c5ad86938c441c26ec94cb5a7d0ee7d669b28d3fa6efb49

See more details on using hashes here.

File details

Details for the file avioflow-0.2.6-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for avioflow-0.2.6-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 dc8e9a0120a3896fb40eb11a7597ee097594c2ccb924ff2f90baf8527729aaee
MD5 5a6fd3ce0c9bc2d1bcad7e9e02bfd5ad
BLAKE2b-256 29d8caaaac60ca1f5d8dc6973bc01fb8b6d9e1a9241baef9d6f7c6ba91b89109

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