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.4-cp313-cp313-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.13Windows x86-64

avioflow-0.2.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.12Windows x86-64

avioflow-0.2.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11Windows x86-64

avioflow-0.2.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.10Windows x86-64

avioflow-0.2.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.9Windows x86-64

avioflow-0.2.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.8Windows x86-64

avioflow-0.2.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: avioflow-0.2.4-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.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3dd980dc04f19eef56fd489b521af62e7952ef9178ae4bacc8c128c630f990e2
MD5 534121eb9a0da8c40b7adcd799d156f7
BLAKE2b-256 acd8691f6b2ce0e9ee1412dab59ecdb8182d2ee8e599a776d905c8ee253f12cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.2.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bcfe8b6d29cc84faf6f7b65e32ccc2288b9b2a79e9e1825ee6e850e743310bda
MD5 9557e7a561588aaabc3a50ad8224cb19
BLAKE2b-256 369d74fbc9386509f8e2a1cbb2d155024e15afee0f2c1ff5a925bbeb135ca218

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.2.4-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.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d4a73d45135a59e46372cc4f2e1ea3e485d6d6ec48399daf03c0de1230bfb681
MD5 b994475ed01e789a1e852dff5403d819
BLAKE2b-256 5132125be26a33a44fa0ab362e475d4c3c75b6dd1a953bffae9b2cf173974c3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.2.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8caaf2e384168f1a7376874a7651a0b42cfac0a6d4ab10b89439971b9ea58056
MD5 7934fc0506fc970f79d8c5864cb4fb50
BLAKE2b-256 411b634895abc5c93ccb573025b8a9d233632585efec0e1580b32b0e45f8988f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.2.4-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.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 167ae664022cf3edc13714b79a88823b2ce0a0035b10e5e2bcf563144026d421
MD5 0859fe47784515515fb970590b635076
BLAKE2b-256 098d3a1ca18765af02cde393326759d46d23d0469a54ef2cb78926f83c85b213

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.2.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 312bde7cae9391c0cb7b02b8861c7abde9eadd1f4302aabb0b0993617f25a406
MD5 e6c4c5b7c741ced7a94205cb84f427b7
BLAKE2b-256 eed0cb459b23f7ec3c894a3956f1817314b2bf8471d651b171307920a8ec1aa1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.2.4-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.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c75f2a8f3bc1f86f84c134b32f8226d79fe55d664a33d314a4e83c402b54d7c0
MD5 6005c76b8d464cdc946772007ab6260e
BLAKE2b-256 45ca4af9bf6260f0f4bf7f24eab616b4bf215b1abbe2d7ab7c28cb565eadfbd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.2.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f584943b7fa7661ed0be934169b5e40c7b675761cf59e1eb83f2c6b842b4b318
MD5 6ed4cc1ff08ed9fb3b0147bae0afd9f4
BLAKE2b-256 c3a467c7c3a50b87f6fbf31a0945bb062499c2492559a65fdf58b0cff5535a11

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.2.4-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.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 7edb05ec11926278b9af938de35e3f591a3b1a3c8628d8544c3e289d8386813b
MD5 b5305a1b7eb07c17e27a3dfa38b9331d
BLAKE2b-256 9105625b68f5254306c62e3b9db2a92df1ca9ffc6fc49301473eb4dc2bd67370

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.2.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2fcc4045b43279dd02cfeb1cbb7f0675b3a3a3a1b8e9a47fb12b533be6dbded7
MD5 07b3456027733d8edb5923dbefec0663
BLAKE2b-256 6586ef5e5a44eef4c476e49a80ec9d1f713d18e13725a592a2ea3b78565aaf8b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.2.4-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.4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 799a2279365ba5574e69a3ce90ab5bc45443633c49c822f7f9aaa2dfad8a3b03
MD5 2508ec38022147416208c9231b9e589a
BLAKE2b-256 08e8100d7300e37d5de79c5eb408a899bd84828bb64b8687a68ac99cf4767719

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.2.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 65d0737ee72d642d307b403bade24140f5abb9da84295e0ba74a2d049bfc1397
MD5 c690a1c8a1b614e32e7eb074779d00f5
BLAKE2b-256 ba855a3e8a9583848845d01d35e4bac472a9d1ca85a7ef7cbdfd57e99851d2a5

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