fdk-aac
Rust bindings for libfdk-aac.
Building
$ git submodule update --init
$ cargo build
License
-
This crate: MIT
-
libfdk-aac: Bespoke license. Based on BSD, free, no patent grant
Rust bindings to libfdk-aac
License: MIT License
Rust bindings for libfdk-aac.
$ git submodule update --init
$ cargo build
This crate: MIT
libfdk-aac: Bespoke license. Based on BSD, free, no patent grant
I'm trying to integrate this with rodio, but I'm getting an error saying The input buffer ran out of bits
. I'd love to know what I'm doing wrong here. Thanks, appreciate any help!
This is my code:
let file = File::open("/some/path/file.m4a")
.or(Err("Error opening file"))?;
let buf = BufReader::new(file);
This file is where BufReader::new
is defined, which is where the error happens (Feel free to ignore the other stuff).
use std::io::{Read, Seek};
use std::time::Duration;
use rodio::Source;
use fdk_aac::dec::{Decoder, Transport};
pub struct AacDecoder<R>
where
R: Read + Seek,
{
reader: R,
decoder: Decoder,
current_frame_offset: i32,
current_frame_data: Vec<i16>,
}
impl<R> AacDecoder<R>
where
R: Read + Seek,
{
pub fn new(mut reader: R) -> Result<AacDecoder<R>, R> {
let mut decoder = Decoder::new(Transport::Adts);
let dfs = decoder.decoded_frame_size();
println!("DFS: {}", dfs);
let mut bufdata_slice = [0; 1024];
match reader.read(&mut bufdata_slice) {
Ok(_) => {},
Err(_) => return Err(reader),
}
match decoder.fill(&mut bufdata_slice) {
Ok(_) => {},
Err(_) => return Err(reader),
}
let mut data_vec: Vec<i16> = vec![];
let mut data_slice = &mut data_vec[..];
match decoder.decode_frame(&mut data_slice) {
Ok(_) => {},
Err(err) => {
println!("DecoderError: {}", err);
return Err(reader)
},
}
Ok(AacDecoder {
reader: reader,
decoder: decoder,
current_frame_offset: 0,
current_frame_data: data_slice.to_vec(),
})
}
pub fn into_inner(self) -> R {
self.reader
}
}
impl<R> Source for AacDecoder<R>
where
R: Read + Seek,
{
fn current_frame_len(&self) -> Option<usize> {
let frame_size: usize = self.decoder.decoded_frame_size();
Some(frame_size)
}
fn channels(&self) -> u16 {
let num_channels: i32 = self.decoder.stream_info().numChannels;
num_channels as _
}
fn sample_rate(&self) -> u32 {
let sample_rate: i32 = self.decoder.stream_info().sampleRate;
sample_rate as _
}
fn total_duration(&self) -> Option<Duration> {
None
}
}
impl<R> Iterator for AacDecoder<R>
where
R: Read + Seek,
{
type Item = i16;
fn next(&mut self) -> Option<i16> {
if self.current_frame_offset == self.current_frame_data.len() as i32 {
// let mut data_vec: Vec<i16> = vec![];
// let data_slice = &mut data_vec[..];
let mut data_slice = [0; 1024];
// let data: &mut [i16];
let result = self.decoder.decode_frame(&mut data_slice);
match result {
Ok(_) => {
self.current_frame_data = data_slice.to_vec();
self.current_frame_offset = 0;
},
Err(_) => return None,
}
}
let value = self.current_frame_data[self.current_frame_offset as usize];
self.current_frame_offset += 1;
return Some(value)
}
}
I am currently encountering a problem while trying to compile my Rust project on Windows using the MinGW64 GCC environment. The error arises from this crate, which is a dependency of the minimp4.rs
crate that I use.
The error message is: failed to run custom build command for 'fdk-aac-sys v0.4.0'
, more information about the compilation error can be found here darkskygit/minimp4.rs#4.
My project also includes other crates that require the GCC compiler, so I can't switch entirely to MSVC for the project compilation.
Any help would be greatly appreciated. Thank you in advance!
Hello, I would like to use your code to implement PCM to AAC format conversion on macOS, but I've encountered an issue. I keep getting the message "The encoding process was interrupted by an unexpected error." I'm not very familiar with fdkaac, and I hope to get your assistance. Thank you very much!
48000_1_s16le.pcm was produced by ffmpeg -y -i 1.mp3 -acodec pcm_s16le -f s16le -ac 1 -ar 48000 48000_1_s16le.pcm
48000_1_s16le.pcm.zip
let encoder = Encoder::new(EncoderParams {
bit_rate: BitRate::VbrLow,
sample_rate: 48000,
transport: Transport::Adts,
channels: ChannelMode::Mono,
}).unwrap();
let result = encoder.info().unwrap();
let mut file = File::open("/Users/leo/Downloads/48000_1_s16le.pcm").expect("failed to open media");
let mut input: Vec<i16> = Vec::new();
while let Ok(sample) = file.read_i16::<LittleEndian>() {
input.push(sample);
}
let mut output = Vec::new();
encoder.encode(&input, &mut output).unwrap();
Hi, i am trying to find a webassembly compatible aac crate, is it possible to make this one compatible ?
I'm new to the static linking world of rust and have little idea how i would do that.
The following error happens when I use aac encoder in tokio thread:
within `[async block@protocol/webrtc/src/whip.rs:131:22: 237:10]`, the trait `Send` is not implemented for `*mut fdk_aac_sys::AACENCODER`
Add the following two lines in enc.rs can fix the problem:
unsafe impl Send for Encoder {}
unsafe impl Sync for Encoder {}
I'm not sure if this is appropriate.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.