Don't try to write an audio frame if there aren't any planes
This commit is contained in:
parent
3beb1a8519
commit
3cad3b1e29
|
@ -308,43 +308,44 @@ static bool ffmpeg_init_config(struct ff_config_param *params,
|
|||
}
|
||||
}
|
||||
|
||||
// Assumption: if there is a video frame, there is an audio frame.
|
||||
let mut aframe = frame::Audio::new(
|
||||
format::Sample::I16(format::sample::Type::Packed),
|
||||
self.audio_buf.len(),
|
||||
ChannelLayout::STEREO
|
||||
);
|
||||
aframe.set_channels(2);
|
||||
aframe.set_rate(44100);
|
||||
aframe.set_pts(Some(frame));
|
||||
let aplane: &mut [(i16, i16)] = aframe.plane_mut(0);
|
||||
eprintln!("Audio buffer length {} -> {}", self.audio_buf.len(), aplane.len());
|
||||
aplane.copy_from_slice(self.audio_buf.as_ref());
|
||||
//eprintln!("src: {:?}, dest: {:?}", self.audio_buf, aplane);
|
||||
self.audio_buf.clear();
|
||||
if aframe.planes() > 0 {
|
||||
aframe.set_channels(2);
|
||||
aframe.set_rate(44100);
|
||||
aframe.set_pts(Some(frame));
|
||||
let aplane: &mut [(i16, i16)] = aframe.plane_mut(0);
|
||||
eprintln!("Audio buffer length {} -> {}", self.audio_buf.len(), aplane.len());
|
||||
aplane.copy_from_slice(self.audio_buf.as_ref());
|
||||
//eprintln!("src: {:?}, dest: {:?}", self.audio_buf, aplane);
|
||||
self.audio_buf.clear();
|
||||
|
||||
eprintln!("frame audio: {:?}", aframe);
|
||||
eprintln!("frame audio: {:?}", aframe);
|
||||
|
||||
eprintln!("🎞 queue frame pts {:?}", aframe.pts());
|
||||
self.audio_filter.get("in").unwrap().source().add(&aframe).unwrap();
|
||||
eprintln!("🎞 queue frame pts {:?}", aframe.pts());
|
||||
self.audio_filter.get("in").unwrap().source().add(&aframe).unwrap();
|
||||
|
||||
let mut filtered_aframe = frame::Audio::empty();
|
||||
loop {
|
||||
match self.audio_filter.get("out").unwrap().sink().frame(&mut filtered_aframe) {
|
||||
Ok(..) => {
|
||||
eprintln!("🔊 Got filtered audio frame {:?} pts {:?}", filtered_aframe, filtered_aframe.pts());
|
||||
if self.audio_filter.get("in").unwrap().source().failed_requests() > 0 {
|
||||
println!("🎥 failed to put filter input frame");
|
||||
let mut filtered_aframe = frame::Audio::empty();
|
||||
loop {
|
||||
match self.audio_filter.get("out").unwrap().sink().frame(&mut filtered_aframe) {
|
||||
Ok(..) => {
|
||||
eprintln!("🔊 Got filtered audio frame {:?} pts {:?}", filtered_aframe, filtered_aframe.pts());
|
||||
if self.audio_filter.get("in").unwrap().source().failed_requests() > 0 {
|
||||
println!("🎥 failed to put filter input frame");
|
||||
}
|
||||
//let faplane: &[f32] = filtered_aframe.plane(0);
|
||||
//filtered_aframe.set_pts(Some(frame));
|
||||
|
||||
self.audio_encoder.send_frame(&filtered_aframe).unwrap();
|
||||
self.receive_and_write_packets(EncoderToWriteFrom::Audio);
|
||||
},
|
||||
Err(e) => {
|
||||
eprintln!("Error getting filtered audio frame: {:?}", e);
|
||||
break;
|
||||
}
|
||||
//let faplane: &[f32] = filtered_aframe.plane(0);
|
||||
//filtered_aframe.set_pts(Some(frame));
|
||||
|
||||
self.audio_encoder.send_frame(&filtered_aframe).unwrap();
|
||||
self.receive_and_write_packets(EncoderToWriteFrom::Audio);
|
||||
},
|
||||
Err(e) => {
|
||||
eprintln!("Error getting filtered audio frame: {:?}", e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue