#mp3 #decoder #mpeg #media

minimp3_fixed

Rust bindings for the minimp3 library. With Security patch applied

3 releases

0.5.4 Jul 25, 2023
0.5.3 Jul 25, 2023
0.5.2 Jul 25, 2023

#335 in Multimedia

Download history 1463/week @ 2024-07-02 1522/week @ 2024-07-09 1480/week @ 2024-07-16 1226/week @ 2024-07-23 1120/week @ 2024-07-30 1414/week @ 2024-08-06 1084/week @ 2024-08-13 1101/week @ 2024-08-20 1216/week @ 2024-08-27 1451/week @ 2024-09-03 974/week @ 2024-09-10 1846/week @ 2024-09-17 2075/week @ 2024-09-24 2214/week @ 2024-10-01 1888/week @ 2024-10-08 1294/week @ 2024-10-15

8,060 downloads per month
Used in 11 crates (4 directly)

MIT license

12KB
141 lines

minimp3 Rust bindings

A fixed non depercated version of minimp3 that applies a vital security patch

Usage example

# Cargo.toml

[dependencies]
minimp3_fixed = "0.5.3"
use minimp3::{Decoder, Frame, Error};

use std::fs::File;

fn main() {
    let mut decoder = Decoder::new(File::open("audio_file.mp3").unwrap());

    loop {
        match decoder.next_frame() {
            Ok(Frame { data, sample_rate, channels, .. }) => {
                println!("Decoded {} samples", data.len() / channels)
            },
            Err(Error::Eof) => break,
            Err(e) => panic!("{:?}", e),
        }
    }
}

Async I/O

The decoder can be used with Tokio via the async_tokio feature flag.

# Cargo.toml

[dependencies]
minimp3 = { version = "0.4", features = ["async_tokio"] }

# tokio runtime
tokio = {version = "0.2", features = ["full"] }
use minimp3::{Decoder, Frame, Error};

use tokio::fs::File;

#[tokio::main]
async fn main() {
    let file = File::open("minimp3-sys/minimp3/vectors/M2L3_bitrate_24_all.bit").await.unwrap();
    let mut decoder = Decoder::new(file);

    loop {
        match decoder.next_frame_future().await {
            Ok(Frame {
                   data,
                   sample_rate,
                   channels,
                   ..
               }) => println!("Decoded {} samples", data.len() / channels),
            Err(Error::Eof) => break,
            Err(e) => panic!("{:?}", e),
        }
    }
}

Dependencies

~0.6–7MB
~48K SLoC