| Crates.io | oggmux |
| lib.rs | oggmux |
| version | 0.1.1 |
| created_at | 2025-04-15 20:25:16.176837+00 |
| updated_at | 2025-04-20 14:14:52.764058+00 |
| description | A remuxing kit for combined Ogg Vorbis streams |
| homepage | |
| repository | https://github.com/dspearson/oggmux |
| max_upload_size | |
| id | 1635211 |
| size | 182,044 |
A Rust library for muxing Ogg streams with clean silence gaps, suitable for streaming applications like Icecast.
use oggmux::{OggMux, BufferConfig, VorbisConfig, VorbisBitrateMode};
use bytes::Bytes;
use tokio::time::sleep;
use std::time::Duration;
#[tokio::main]
async fn main() {
// Create a new OggMux with custom configuration
let mux = OggMux::new()
.with_buffer_config(BufferConfig {
buffered_seconds: 10.0,
max_chunk_size: 4096,
})
.with_vorbis_config(VorbisConfig {
sample_rate: 44100,
bitrate: VorbisBitrateMode::CBR(320),
});
// Spawn the muxer and get the channels
let (input_tx, mut output_rx) = mux.spawn();
// Feed some data (e.g., from a file or network stream)
let ogg_data = Bytes::from_static(&[/* Ogg data here */]);
let _ = input_tx.send(ogg_data).await;
// Read the processed output (e.g., send to Icecast)
while let Some(output) = output_rx.recv().await {
// Send output to your streaming destination
println!("Got {} bytes of muxed output", output.len());
}
}
BufferConfig {
buffered_seconds: 10.0, // Target amount of audio to keep buffered
max_chunk_size: 65536, // Maximum chunk size to process at once
}
You can configure the vorbis stream in two ways:
VorbisConfig {
sample_rate: 44100, // Sample rate in Hz
bitrate: VorbisBitrateMode::CBR(320), // 320 kbps constant bitrate
}
VorbisConfig {
sample_rate: 44100, // Sample rate in Hz
bitrate: VorbisBitrateMode::VBRQuality(6), // Quality level 6 VBR
}
OggMux maintains a continuous flow of Ogg data by:
This approach is ideal for applications where a continuous stream must be maintained despite irregular input data, such as live streaming or internet radio.