#mp3 #decoder #mpeg #media

minimp3_fixed

Rust对minimp3库的绑定。已应用安全补丁

3个版本

0.5.4 2023年7月25日
0.5.3 2023年7月25日
0.5.2 2023年7月25日

#336 in 多媒体

Download history 1367/week @ 2024-03-13 1569/week @ 2024-03-20 1788/week @ 2024-03-27 1566/week @ 2024-04-03 1628/week @ 2024-04-10 1908/week @ 2024-04-17 1343/week @ 2024-04-24 1879/week @ 2024-05-01 1325/week @ 2024-05-08 1639/week @ 2024-05-15 1957/week @ 2024-05-22 1973/week @ 2024-05-29 1652/week @ 2024-06-05 1493/week @ 2024-06-12 1219/week @ 2024-06-19 1488/week @ 2024-06-26

6,154 每月下载次数
用于 9 个包 (2 直接)

MIT 许可证

12KB
141

minimp3 Rust绑定

minimp3的一个固定非降级版本,应用了关键的安全补丁

使用示例

# 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),
        }
    }
}

异步I/O

解码器可以通过async_tokio功能标志与Tokio一起使用。

# 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),
        }
    }
}

依赖关系

~0.6–2.6MB
~49K SLoC