Skip to content

Commit

Permalink
_
Browse files Browse the repository at this point in the history
  • Loading branch information
hanguk0726 committed Mar 26, 2023
1 parent fe0ad6b commit 3f454d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ fn write_mp4_with_audio(
let pcm_size: u64 = pcm.len().try_into().unwrap();

let mut sample: u64 = 0;
let mut total_samples: u64 = pcm_size / 2;
let mut total_samples: u64 = pcm_size ;
let mut ts: u64 = 0;
let mut ats: u64 = 0;

Expand Down Expand Up @@ -223,29 +223,29 @@ fn write_mp4_with_audio(
input_buffer[..bytes_to_read as usize].copy_from_slice(pcm_buf);
pcm_ptr = unsafe { pcm_ptr.add(bytes_read.try_into().unwrap()) };

if total_samples < in_args_num_in_samples as u64 {
total_samples = pcm_size / 2;
}
// if total_samples < in_args_num_in_samples as u64 {
// total_samples = pcm_size ;
// }

// Encode audio data using AAC encoder
match encoder.encode(&input_buffer[..bytes_to_read as usize], &mut output_buffer) {
Ok(encoding_info) => {
// Write encoded audio data to output buffer
let buf = &output_buffer[..encoding_info.output_size];
sample += 1024;
// total_samples -= bytes_to_read;
ats = sample * 90000 / sample_rate as u64;
unsafe {
MP4E_put_sample(
mux,
audio_track_id,
buf.as_ptr() as *mut c_void,
encoding_info.output_size.try_into().unwrap(),
(length * 90000 / sample_rate as u64).try_into().unwrap(),
(1024 * 90000 / sample_rate as usize).try_into().unwrap(),
MP4E_SAMPLE_RANDOM_ACCESS.try_into().unwrap(),
)
};

sample += in_args_num_in_samples;
total_samples -= bytes_to_read;
ats = sample * 90000 / sample_rate as u64;
}
Err(e) => {
println!("encode error:{}", e);
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ fn main() {
let mut mp4muxer = Mp4Muxer::new(&mut buffer);
if let Ok(h264) = read_file("input.264") {
let pcm = read_file("input.pcm").unwrap();
mp4muxer.init_audio(128000, 8000, 2);
mp4muxer.init_video(1280, 720, false, "h264 stream");
// mp4muxer.write_video_with_fps(&h264, 28);
mp4muxer.init_audio(128000,8000, 1);
mp4muxer.write_video_with_audio(&h264, 30, &pcm);
}
// if let Ok(h265) = read_file("1.265") {
Expand Down

0 comments on commit 3f454d7

Please sign in to comment.