Skip to main content

High-performance audio decoding with FFmpeg and C++

Project description

AvioFlow

High-performance audio decoding library powered by FFmpeg with C++, Python, and Node.js bindings.

Features

  • Multi-format Support: MP3, WAV, AAC, FLAC, Opus, and all FFmpeg-supported formats
  • Flexible Input: Files, URLs, memory buffers, and real-time streams
  • Hardware Capture: WASAPI loopback (system audio) and DirectShow (microphones)
  • Resampling: Built-in sample rate and channel conversion
  • Zero-copy API: Direct buffer access via FrameData for maximum performance
  • Cross-platform: Windows, Linux, macOS

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.output_num_channels = 1;       // Target channels
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_all_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
    output_num_channels=1,       # Optional: target channels
    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, or pathlib.Path
decoder(bytes) ndarray Push bytes 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}")

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

Uploaded CPython 3.13Windows x86-64

avioflow-0.2.2-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.2-cp312-cp312-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.12Windows x86-64

avioflow-0.2.2-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.2-cp311-cp311-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.11Windows x86-64

avioflow-0.2.2-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.2-cp310-cp310-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.10Windows x86-64

avioflow-0.2.2-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.2-cp39-cp39-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.9Windows x86-64

avioflow-0.2.2-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.2-cp38-cp38-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.8Windows x86-64

avioflow-0.2.2-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.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: avioflow-0.2.2-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.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 94e8bac6de01ff8c2ba8eb259bcea2c77bcc6f053f66814216a92f0aa84792cb
MD5 0d35ef9fca15655be95f199b7eae6960
BLAKE2b-256 59829cfb492945b9191bc2393f89c4b57ccbc5a9e4ab173de48d49a8d2d244b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.2.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a4ef3f3c087e4f2ecf0ffebc728807220e047e581295d05dd39ba484e731a08e
MD5 114e710ef613a0c2c810a361d8580f0c
BLAKE2b-256 a2c57d82bf323c9a74b2573203cb42236fa58800e5903aa93915f39e180bd9d7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.2.2-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.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 bc9f42be00623e319d7e756bce86cb40b89a8cd753a8279ce4f9b26329a5a496
MD5 3c621a6149b70d45cd24ef253041b6c7
BLAKE2b-256 a40c969daaaaa7d1ae761bacb34d0b3979340095326ae171f7483dbba26a1e58

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a3724611b6d9a66b81231ed1d989bb6dbc4db726612c2f95ee3b1609a5e41b3e
MD5 07698087aa8ec4499166fc0e5387586c
BLAKE2b-256 6190b5d5ad12d866301bb1f727a152c54c0e34b0bff013a865dc8cc0967ebee5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.2.2-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.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f090dc5add115cdd3799e14db6434e8b94e7164be4f01e9d558d92a3a23b4b39
MD5 560a59253acfc93490f9ade2f7961d54
BLAKE2b-256 9038762605d0bd818fa46836fcffa6913d6ccbe84a6acf12203f1dd73244ecd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 def35fdcc5b0597068606e63fa12660efa5ab9004efc4c3fd37fe8db17d59923
MD5 113b668fee131b80fd5cba6c4c17a9ae
BLAKE2b-256 a84cb04ff52985f9ad9fc6620add546f53d9dafb319fe4fb94a282d3b1ba89f7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.2.2-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.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7f046766a60194f48fc9c573aade8c0274922f2cac4d3a34a9d74e37550b92b4
MD5 3093205624e42b1f0401959dee9f75cb
BLAKE2b-256 86506734dc9d24b3f11823aaa757cb03a559ae7342ec70edeed85062c913d5f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b9540e12a6155777e0d2baf75752a93e37014eb3c97ba6f9de4e7867376bea44
MD5 2cabdfc8cade282da84e4738d1bba653
BLAKE2b-256 a82c53a3344fa2647ce01660d2cde5b89f0eef573ddbc82c4b989fcdf81cc3b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.2.2-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.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 dbcf3b6ba796a0422e21b9bb0a5cd755c4f519ecfe7ae2fb1504ecb9af3a8f18
MD5 8de31dc8fd2532a2f4f8f2e9a9d2da4b
BLAKE2b-256 2d489016a5cad890df8dd52bf66e34167bc3e86a6887da94b288e37fcf010f8b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c7cb5644cfacedfef7252c59e9e3b1586656c1964916cdda4b306bf2a25090ca
MD5 5e2762cbab6e99a49dfc3e62f24c65a4
BLAKE2b-256 4c258044b83009d3b18a476cf42fa2382188336a4eaf3d52a0375c9f3ff68231

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.2.2-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.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 f1fda68d9c80d985b887306a39ce53826e7e5b8f82a3636e736c6340427ac653
MD5 bde573be489182f72d09c0b075836f9d
BLAKE2b-256 a439fe42b66fc3e9b2a2dc7f036da2046989ba2b8078a43b84b43d9c2c53bb30

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.2.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a7559d580b7dc9f932f2404ab416404581a1bfdd05e1e4d574c2ceac5dd3c6c8
MD5 14024135c67ce75911a7257fb4930f55
BLAKE2b-256 eb80422afe5f449b3a0f406ecaefb3c3c36e194e76a628ad07a60d889a767988

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