diff --git a/src/lib.rs b/src/lib.rs index f4fb98c..8091b57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; @@ -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); diff --git a/src/main.rs b/src/main.rs index 2827b30..c7cf4b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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") {