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

Node.js

npm 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

ESM Import

import avioflow from 'avioflow';

AudioDecoder

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

Methods

Method Returns Description
load(source) Metadata Load file or URL
push(buffer) void Push raw bytes for streaming
decodeNext() Float32Array[] or null Decode next frame
getMetadata() Metadata Get audio metadata
isFinished() boolean Check if EOF

Examples

File Decoding

const decoder = new avioflow.AudioDecoder({ outputSampleRate: 16000 });
const meta = decoder.load("audio.mp3");
console.log(`Duration: ${meta.duration}s, Channels: ${meta.numChannels}`);

while (!decoder.isFinished()) {
    const frame = decoder.decodeNext();
    if (frame) {
        // frame is array of Float32Array (one per channel)
        console.log(`Decoded ${frame[0].length} samples`);
    }
}

Streaming Decode

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

socket.on('data', (chunk) => {
    decoder.push(chunk);
    let frame;
    while ((frame = decoder.decodeNext()) !== null) {
        processAudio(frame);
    }
});

Device Discovery

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

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

Input Format Reference

Format Description Use Case
s16le 16-bit signed PCM, little-endian Raw audio, WebRTC
s16be 16-bit signed PCM, big-endian Network streams
f32le 32-bit float PCM, little-endian High-quality audio
aac AAC with ADTS headers Streaming AAC
mp3 MP3 frames Streaming MP3
opus Opus packets WebRTC, VoIP
wav WAV container File-based audio

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

Uploaded CPython 3.13Windows x86-64

avioflow-0.1.7-cp313-cp313-manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.12Windows x86-64

avioflow-0.1.7-cp312-cp312-manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.11Windows x86-64

avioflow-0.1.7-cp311-cp311-manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.10Windows x86-64

avioflow-0.1.7-cp310-cp310-manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.9Windows x86-64

avioflow-0.1.7-cp39-cp39-manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.8Windows x86-64

avioflow-0.1.7-cp38-cp38-manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.28+ x86-64

File details

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

File metadata

  • Download URL: avioflow-0.1.7-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.7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 64cae8dca5cc5848ddba9f461b1dc886a61e79aa0ddf5482050fe9a12eebeefc
MD5 1f8613bf661b42872763b38b4edc1db0
BLAKE2b-256 319a63dddd5c4687954bf3b8e70d6df76c96444e48aae8c6a8627285f3ea0e9a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.1.7-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8226f394860608ecddb5574e29fa4cbd0eb7a3f1f8123ab4998b8627ac497f85
MD5 596cd9f7962f000f135ba8ba8df59b76
BLAKE2b-256 bae3e69b8b23a1f5bc7b1fa7d5a313bf101668d56ecdd935d5d63f9bb4a45fd5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.1.7-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.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 614733a0ecf40fae1bcf2235055b53ae59aabb831ff6c6abfa49c46940bd169d
MD5 008ecaecdb306855ec984cd933ef50e6
BLAKE2b-256 6ef066cddaef46fccff8ffdc6b275849bd773c289bafdf2eaab83163b597de5f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.1.7-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 47ebb6d6f54d018ca1900bbd7bba0fb8a298f5cccf88fcfe4ce8f658f1707a96
MD5 a74bc71cadbfcd25e55a75d2a79b8d99
BLAKE2b-256 3095cd7321ef99d64668fba7078fd28a2c7ba9aab800421fb154dbe455fdf433

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.1.7-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.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 65a544761c906d670047c228e2477ed2c2a15f26d5e508ebcaebb2c5bc9808d0
MD5 aba1b6bb620ab7c9a407e397fe99a490
BLAKE2b-256 bcb0b6a394cb3c35e9426d5497918208f01fc3c0a74334b03279e104f5c26b8f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.1.7-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 af075d2a36030be8d91f2e927a716a9f96c69321ce6f9f6d0eaa9a7dada28aa1
MD5 ba00ea150fb80de301f2a70baae37175
BLAKE2b-256 d9d32f5ad0b6eb7c223979a462faa9a71fb7bb18467586dd9c6f2bf48952be72

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.1.7-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.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 039d9c9dfd1b2c2727babf0e04e262cbe5a9613fbdd3c3c369060d8dd0c9e779
MD5 6d566eb7feb7d3e3dbab3c27de316ecc
BLAKE2b-256 88001f9f62d0c0d135046cd4405b573fe0f6a492e0e2680c07249bc0a0f3b539

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.1.7-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5c8efe98d5bcd8729300ad887710019c7ac4712e0ab4a67b8c49e4e2d78b0d46
MD5 be47fe89a2bdcb3ea49640cc09621ee0
BLAKE2b-256 fb65b75e507dfba6bd70a2bb18b1fd7bb4ae433b4250afe6aed8c31191282d3f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.1.7-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.7-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 67bb52d693084fedab9eba062c8604187063efe076e781761164eb3c672ab735
MD5 12b2c33912590cef9991dda75b487731
BLAKE2b-256 b740e72df76f25d6e8d9d8f4de91be5afea016021e1c9de18c60b0740b70d626

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.1.7-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 48a2fd024737dead94be31fe57cb225e0eea1c459b6483f4f4a2f4070056f54b
MD5 821be3a4f4eba2074d80d8a49a32612d
BLAKE2b-256 1550a628f5c65086ccf05bebc9443b3e498feba4ba0a871d5ce79c4b26d0d427

See more details on using hashes here.

File details

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

File metadata

  • Download URL: avioflow-0.1.7-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.7-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 5f2a930cd4aaaab11cf3cce0da0447f1f097baac5303d9c8d29aac429eb8c457
MD5 50a311cab365cfd956393ae1388f4b5f
BLAKE2b-256 60491e9104b5542fc010de85e97f7d970db09c07cc78ac1fb5af4a56b4e69698

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for avioflow-0.1.7-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dbbcbebbf13d8011b68b11cac7eb800b5fbb36f6c52a715a0f939fc99f6c16e4
MD5 bbc57f061c20e436a2520fd17128c739
BLAKE2b-256 39d571e4eeffa00515b8c54b42ecf0a0df9a4f685d17dbd9e39d3bef9c6d9756

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