mp3lame-encoder

Crates.iomp3lame-encoder
lib.rsmp3lame-encoder
version
sourcesrc
created_at2022-12-10 04:19:46.464602
updated_at2024-12-04 12:03:39.554046
descriptionHigh level bindings to mp3lame encoder
homepage
repositoryhttps://github.com/DoumanAsh/mp3lame-encoder
max_upload_size
id733727
Cargo.toml error:TOML parse error at line 23, column 1 | 23 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Douman (DoumanAsh)

documentation

README

mp3lame-encoder

Rust Crates.io Documentation

High level wrapper over mp3lame-sys

Example

use mp3lame_encoder::{Builder, Id3Tag, DualPcm, FlushNoGap};

let mut mp3_encoder = Builder::new().expect("Create LAME builder");
mp3_encoder.set_num_channels(2).expect("set channels");
mp3_encoder.set_sample_rate(44_100).expect("set sample rate");
mp3_encoder.set_brate(mp3lame_encoder::Bitrate::Kbps192).expect("set brate");
mp3_encoder.set_quality(mp3lame_encoder::Quality::Best).expect("set quality");
mp3_encoder.set_id3_tag(Id3Tag {
    title: b"My title",
    artist: &[],
    album: b"My album",
    year: b"Current year",
    comment: b"Just my comment",
});
let mut mp3_encoder = mp3_encoder.build().expect("To initialize LAME encoder");

//use actual PCM data
let input = DualPcm {
    left: &[0u16, 0],
    right: &[0u16, 0],
};

let mut mp3_out_buffer = Vec::new();
mp3_out_buffer.reserve(mp3lame_encoder::max_required_buffer_size(input.left.len()));
let encoded_size = mp3_encoder.encode(input, mp3_out_buffer.spare_capacity_mut()).expect("To encode");
unsafe {
    mp3_out_buffer.set_len(mp3_out_buffer.len().wrapping_add(encoded_size));
}

let encoded_size = mp3_encoder.flush::<FlushNoGap>(mp3_out_buffer.spare_capacity_mut()).expect("to flush");
unsafe {
    mp3_out_buffer.set_len(mp3_out_buffer.len().wrapping_add(encoded_size));
}
//At this point your mp3_out_buffer should have full MP3 data, ready to be written on file system or whatever

License

LAME library is under LGPL License. Hence this crate is licensed under the same shitty license

Commit count: 28

cargo fmt