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
FrameDatafor 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.datapoints to internal buffer, valid only until nextread()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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file avioflow-0.2.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: avioflow-0.2.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67641bbb7862f512ae5af5c2dec0639fba2bcd75a2ee42e56e0892ee09ad7b80
|
|
| MD5 |
1c97a25a450a6829083e4e16532c8485
|
|
| BLAKE2b-256 |
2372dbf8aefe14ea38388659c8484cd267cfd408db913ad3e3209c730ef9d7c8
|
File details
Details for the file avioflow-0.2.0-cp313-cp313-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: avioflow-0.2.0-cp313-cp313-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.13, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1813e4e7e3244e0c11c05496df9212f43deee23cb448c146ac19a828a1a613fd
|
|
| MD5 |
3f698664e3ec48325ab4a9119e360b11
|
|
| BLAKE2b-256 |
e7333c56e707808c4c306f4fab9495f81b20ac33314290dd59b8fa73dc384014
|
File details
Details for the file avioflow-0.2.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: avioflow-0.2.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c2418d7e58b0ec891c7c494ee257603e0456eb3f0fdec16bce2c33ea1dd5c9c
|
|
| MD5 |
44f1d73e7626aa3622186e9ac14b620e
|
|
| BLAKE2b-256 |
24f8f944058630aa0916e6f9a3cada4bad8ce68a0b3c97cfae4b6351fb201acf
|
File details
Details for the file avioflow-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: avioflow-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.12, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a4fdb25f0a8fb6291dfd79a69d52dc65a59f1e566241d7a37669c8e4ec7d6fc
|
|
| MD5 |
d84c81b39edd506c0d926ad05dba75b2
|
|
| BLAKE2b-256 |
5279d4fc966026802dfce6d46dcc555fb28e08e312a22567e7fbd682f597ff85
|
File details
Details for the file avioflow-0.2.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: avioflow-0.2.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a96c0be110f3ceb5f7b2aaa7f4ec3479b92b1af53a4d95bbb31210569a23bbea
|
|
| MD5 |
9f3a1f1f1040e3b89067e726cebf124f
|
|
| BLAKE2b-256 |
555fd94b96ac7859f7e376e3be72cd54aebdda0e7db32075be7bf95a81ac6949
|
File details
Details for the file avioflow-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: avioflow-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.11, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a1c3a344ffbaa398bfe03ebd83501df50cfe94d31afd46b3bbf33f95970a2a3
|
|
| MD5 |
ad32735636009669d177bc2aff4aeedd
|
|
| BLAKE2b-256 |
dfd12e28511a90a229600f6911ba4cc7ba249d3386ba7f477c3e30120e677d2d
|
File details
Details for the file avioflow-0.2.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: avioflow-0.2.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d246074c53e2ff27fd08de889b895dcbc82b5a9d5a34795284a00dffc52b59e
|
|
| MD5 |
a2baecf814003658de58f8ef3fd84f47
|
|
| BLAKE2b-256 |
49877b48e5dc1a8dd79813e1c1631ad6f9eec17d8088d143d97e1678e867bfaa
|
File details
Details for the file avioflow-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: avioflow-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.10, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6133a4ef37243c4dbb18ba92a7dfa3c7e9764239a1957589a57a9b3026f427e9
|
|
| MD5 |
f6867400ce161b52c663a35385385a72
|
|
| BLAKE2b-256 |
c1ffe06bf3b14d57aff5aeb241ba20c11ab7eb659c89b41cdf3b1d1f3a28ccdf
|
File details
Details for the file avioflow-0.2.0-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: avioflow-0.2.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6320cc3c48159f0b751f1f628cf9c10b574eb5b72a96c8d4eaf26e1442f53c52
|
|
| MD5 |
27128adc9635a007459c619be93d9a45
|
|
| BLAKE2b-256 |
ca14fc30598afe1c4341cae0baee12e7f5171be7417370d842c4c6a4889377aa
|
File details
Details for the file avioflow-0.2.0-cp39-cp39-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: avioflow-0.2.0-cp39-cp39-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.9, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4b3f6cb085f70e9df297798189a335d0c53d9bd06662308c8a6596c01566627
|
|
| MD5 |
b111b3e35db7a101dd6342f0aaeb6338
|
|
| BLAKE2b-256 |
381c4d1018d07eba6c5ef556b49c8a94ad1e403b6180682a816fbfe301ab6652
|
File details
Details for the file avioflow-0.2.0-cp38-cp38-win_amd64.whl.
File metadata
- Download URL: avioflow-0.2.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f30b564fc861d1918150b0e02413ea1dc56890a8bc22a0b44fb0ad869d0a1f9
|
|
| MD5 |
40738e25e9893138b5fc0cd74d29979d
|
|
| BLAKE2b-256 |
2d8dc4f9fd09fa74bc7bb8bdb0cb12fa3ecbb887b6861f9ec45de0cc09a568a0
|
File details
Details for the file avioflow-0.2.0-cp38-cp38-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: avioflow-0.2.0-cp38-cp38-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.8, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59eab9b07b7f430cba8948e6333fd0fccf0c4989a03984bd405f18beafdf77ea
|
|
| MD5 |
d4c60b397947d8a9de75cb167ccf1d53
|
|
| BLAKE2b-256 |
753f30005f1a588718fcd50e2769e61f869c18c36c8741869727062a0912f20b
|