darkskygit / minimp4.rs

A minimp4 Rust binding, h264/h265 stream muxer
https://crates.io/crates/minimp4
Mozilla Public License 2.0
20 stars 6 forks source link

support mux more audio formats #5

Open gogojames opened 11 months ago

gogojames commented 11 months ago

` let audio_data=Vec::from(include_bytes!("goodaf.mp3") as &[u8]); let pcm = vec!(0);

mp4muxer.init_audio(32, 24000, 1);

mp4muxer.write_video_with_audio(&audio_data, 60, &pcm);

`

darkskygit commented 11 months ago

At present, only pcm is supported to be encapsulated into mp4, and the internal implementation will encode pcm into aac: https://github.com/darkskygit/minimp4.rs/blob/34271320d8809a40f839592efa226cc7795b91b2/packages/minimp4/src/writer.rs#L119-L122

gogojames commented 11 months ago

How to set codec:MP3(MPEG audio layer 3)

darkskygit commented 11 months ago

There is no parsing of mp3 in the current implementation.

In mp4, the audio data is stored according to simple (frame), so you need to parse and disassemble the mp3 into a series of frames, and then set it to the corresponding mdat in order.

The following code is to set each frame of aac to the corresponding position:

https://github.com/darkskygit/minimp4.rs/blob/34271320d8809a40f839592efa226cc7795b91b2/packages/minimp4/src/writer.rs#L136-L143

gogojames commented 11 months ago

Oh, there is a harsh sound when playing, what should I do?

darkskygit commented 11 months ago

are you using pcm? current pcm to aac implemention may not fully correctly

so previously, i was considering refactoring the encoding feature and splitting it into a separate package, but i haven't had time to refactor it recently.

gogojames commented 11 months ago

Is it difficult to do?

darkskygit commented 11 months ago

just because i don't have free time recently