| Crates.io | access-unit |
| lib.rs | access-unit |
| version | 0.1.2 |
| created_at | 2024-09-08 01:19:34.775599+00 |
| updated_at | 2026-01-04 16:57:40.82304+00 |
| description | Minimal structs and helpers for working with audio and video byte streams |
| homepage | |
| repository | https://github.com/wavey-ai/access-unit |
| max_upload_size | |
| id | 1367714 |
| size | 43,483 |
A Rust library for handling audio codec frames, with support for AAC and FLAC formats. The library provides utilities for frame detection, parsing, and manipulation, with a focus on broadcast and streaming applications.
use audio_codec_handler::detect_audio;
let data: &[u8] = // your audio data
let audio_type = detect_audio(data);
match audio_type {
AudioType::AAC => println!("AAC audio detected"),
AudioType::FLAC => println!("FLAC audio detected"),
AudioType::MP3 => println!("MP3 audio detected"),
AudioType::Unknown => println!("Unknown audio format"),
_ => println!("Other format")
}
use audio_codec_handler::mp4;
let data: &[u8] = // MP4 data
if mp4::is_mp4(data) {
if let Some(audio_type) = mp4::detect_audio_track(data) {
println!("Audio track codec: {:?}", audio_type);
}
}
use audio_codec_handler::aac;
// Check if data is valid AAC
if aac::is_aac(data) {
// Extract AAC frame data
let aac_data = aac::extract_aac_data(&bytes_data);
// Ensure proper ADTS header
let processed_data = aac::ensure_adts_header(
bytes_data,
channels,
sample_rate
);
}
use audio_codec_handler::flac;
// Parse FLAC frame header
let frame_info = flac::decode_frame_header(data)?;
// Split FLAC stream into frames
let frames = flac::split_flac_frames(data);
// Extract single FLAC frame
let frame = flac::extract_flac_frame(data);
// Create STREAMINFO metadata block
let streaminfo = flac::create_streaminfo(&frame_info);
use audio_codec_handler::mp3;
if let Some((offset, header)) = mp3::find_frame(data) {
println!("Found MP3 frame at offset {} with length {}", offset, header.frame_length);
}
use audio_codec_handler::AccessUnit;
let unit = AccessUnit {
key: true,
pts: 0,
dts: 0,
data: data_bytes,
avc: false,
id: 1234
};
|--- Sync Word (12 bits) ---|
|--- ID (1 bit) ---|
|--- Layer (2 bits) ---|
|--- Protection Absent (1 bit) ---|
|--- Profile (2 bits) ---|
|--- Sampling Frequency Index (4 bits) ---|
|--- Private Bit (1 bit) ---|
|--- Channel Configuration (3 bits) ---|
|--- Original/Copy (1 bit) ---|
|--- Home (1 bit) ---|
|--- Sync Code (15 bits) ---|
|--- Reserved (1 bit) ---|
|--- Block Size (4 bits) ---|
|--- Sample Rate (4 bits) ---|
|--- Channel Assignment (4 bits) ---|
|--- Sample Size (3 bits) ---|
|--- Reserved (1 bit) ---|
MIT