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
decode_next() Decode next frame, returns FrameData
get_all_samples() Decode all and return vector<vector<float>>
get_metadata() Get audio metadata
is_finished() Check if EOF reached

FrameData

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

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 decode_next() call.

Examples

File Decoding (Offline)

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

auto samples = decoder.get_all_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.decode_next()) {
    // 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

while (auto frame = decoder.decode_next()) {
    // Process decoded audio...
}

WASAPI Loopback Capture

AudioDecoder decoder;
decoder.open("wasapi_loopback");

while (auto frame = decoder.decode_next()) {
    // Capture system audio in real-time
}

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)
get_all_samples() ndarray Decode entire source
is_finished() bool Check if EOF

Metadata

meta = decoder.load("audio.mp3")
print(f"Duration: {meta.duration}s")
print(f"Sample Rate: {meta.sample_rate}Hz")
print(f"Channels: {meta.num_channels}")
print(f"Codec: {meta.codec}")
print(f"Container: {meta.container}")
print(f"Bit Rate: {meta.bit_rate}bps")

Examples

File Decoding

decoder = avioflow.AudioDecoder(output_sample_rate=16000)
meta = decoder.load("speech.wav")
samples = decoder.get_all_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)  # Call decoder directly
    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}")
    # dev.is_output: True for output/loopback devices

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 ❌ Not supported
Architectures x64 ✅ Linux, Windows

⚠️ Electron Not Supported: Due to V8 ABI compatibility issues, the native addon crashes in Electron environments (including VS Code extensions). For Electron apps, we recommend using an external FFmpeg process instead.

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.
decodeNext() Float32Array[] | null Decode next frame. Returns array of channel data.
getAllSamples() Float32Array[] Decode all remaining 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.getAllSamples(); 
process(allSamples);

Streaming Decode (Real-time)

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

socket.on('data', (chunk) => {
    decoder.push(chunk);
    let frame;
    // Extract all available frames from the pushed chunk
    while ((frame = decoder.decodeNext()) !== null) {
        processAudio(frame); // frame is Float32Array[]
    }
});

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)

Windows

.\build.ps1

Linux

cmake -B build -DENABLE_PYTHON=ON
cmake --build build --config Release

Node.js Prebuild

npm run prebuild

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

Uploaded CPython 3.13Windows x86-64

avioflow-0.1.14-cp313-cp313-manylinux_2_28_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

avioflow-0.1.14-cp312-cp312-win_amd64.whl (12.8 MB view details)

Uploaded CPython 3.12Windows x86-64

avioflow-0.1.14-cp312-cp312-manylinux_2_28_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

avioflow-0.1.14-cp311-cp311-win_amd64.whl (12.8 MB view details)

Uploaded CPython 3.11Windows x86-64

avioflow-0.1.14-cp311-cp311-manylinux_2_28_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

avioflow-0.1.14-cp310-cp310-win_amd64.whl (12.8 MB view details)

Uploaded CPython 3.10Windows x86-64

avioflow-0.1.14-cp310-cp310-manylinux_2_28_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

avioflow-0.1.14-cp39-cp39-win_amd64.whl (12.8 MB view details)

Uploaded CPython 3.9Windows x86-64

avioflow-0.1.14-cp39-cp39-manylinux_2_28_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

avioflow-0.1.14-cp38-cp38-win_amd64.whl (12.8 MB view details)

Uploaded CPython 3.8Windows x86-64

avioflow-0.1.14-cp38-cp38-manylinux_2_28_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.28+ x86-64

File details

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

File metadata

  • Download URL: avioflow-0.1.14-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 12.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.1.14-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 26ffa08ce217b7ac4203ef680bceaff2d4f93829bd33e4302c46e2ddf16a3847
MD5 8b36b078bb6d3660ff9b36f06a8faea0
BLAKE2b-256 b40071e497aaab2c61ebc63990f858f287303bc36761119e536997dfc208c917

See more details on using hashes here.

File details

Details for the file avioflow-0.1.14-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for avioflow-0.1.14-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4f86e01b32012d1680c9e911465a861826691a9a25b9b7d021b5deb054221f5b
MD5 a2e747168c635ffebb4d3ff032124025
BLAKE2b-256 78c150e12184b1e548f1989bd469f5786dab2c9e2d62c6d06785249dfea75b95

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.1.14-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 12.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.1.14-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 547bfa32aeb49fc02c6471aa90afe1c0cd42e46680b8d3cc798e5c9e8ddafda7
MD5 9376c2ae0fc1b643b45bbcd07f103040
BLAKE2b-256 b19b531acb4a5052a38bfc59ebff2740fcc1c4d780d2d017e2d7e53381b1e20c

See more details on using hashes here.

File details

Details for the file avioflow-0.1.14-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for avioflow-0.1.14-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 08204445783bcb29296ef378f1014a199ffa23c178e2555b85d4de39a5794f85
MD5 950eef4101eb3fe5872f089cff64926e
BLAKE2b-256 44d801940a6527316a17d139507fad1b8ae20272d6457a12bf681018da5f5497

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.1.14-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 12.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.1.14-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3bf642c211b79e3ca7dc44866a40da60b438c00c115eff305d305dd8b8606d23
MD5 c8571c609afebf8bff32dfb19813ef9e
BLAKE2b-256 a9d45a0bf9f1f3a5135df6d1f35ab8f62098d3db6782c128285058eb29da811d

See more details on using hashes here.

File details

Details for the file avioflow-0.1.14-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for avioflow-0.1.14-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4af66c77665ba0ef0cd72d00a9e0ccd3214b8d4958a899bc3242e4faeceb0e7b
MD5 c4e1d7567f643b2a2e0304556f5808e3
BLAKE2b-256 dfa2d446bb23f4c34d69388a2ed8baefa0e1e750b5a4f0d3ac9e28116bb7a42a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.1.14-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 12.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.1.14-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 cd1efe75504ecce5adbdb4a54dae4ca9eb0f616ccbf0b7c112a3fef19f622a1a
MD5 87457de121785343b94148be41dd9cd4
BLAKE2b-256 195e3b65f6c95a88fc67fee8c871c0a469b204eb98c761176f4d808f657e6d76

See more details on using hashes here.

File details

Details for the file avioflow-0.1.14-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for avioflow-0.1.14-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6589ef9261023edb20d67c6ba2343efa286d94cc9a75123631a3b44495791449
MD5 166ad2dea2e78d89130effb31a58dcb1
BLAKE2b-256 3c2404c303e749066e70f08f0e78002b7846cafc3285379cbcfcbc2a40141be5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.1.14-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 12.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.1.14-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 fbc3c9a20df20eb3fc3181db6dbdd311d38db7997ecdb5343895640936b636f3
MD5 53bbd0fdb6478a4ab8a1247f0b52625c
BLAKE2b-256 aa51b2282dd85c23ad9224c3d274929ef7ba74605cfe0267f961c9134b6968a6

See more details on using hashes here.

File details

Details for the file avioflow-0.1.14-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for avioflow-0.1.14-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1e321243b32a89ba88d2856076b4f90cc470626f1f1f3a4f43f014b82e5b7281
MD5 c63ee5a23ca111e1c205400f6561be14
BLAKE2b-256 fda35b1254f528678cf9e3c34809b076f01e35f399694eb55c55681c7fddd940

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.1.14-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 12.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.1.14-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a533e93a6c351ba12e710e29763148e787082966c81e0b31dcabe1faea6e5a84
MD5 1872dded2c98695e0c07467a12c4c556
BLAKE2b-256 71bd9c7ebd50fce8198c1f42496361613d399f121646193fd06134c85e2869a1

See more details on using hashes here.

File details

Details for the file avioflow-0.1.14-cp38-cp38-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for avioflow-0.1.14-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ab82f8c3ef1dc30b32b160f78284da4c0ce7ac5ef83007ebe55b60cec011410c
MD5 97ea384486d606c912aebd43e091916d
BLAKE2b-256 09babedcc4737f87dd64c6170a3c417e1c61939ab7eb6982711112bc7158d3a2

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