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(
|
let mut aframe = frame::Audio::new(
|
||||||
format::Sample::I16(format::sample::Type::Packed),
|
format::Sample::I16(format::sample::Type::Packed),
|
||||||
self.audio_buf.len(),
|
self.audio_buf.len(),
|
||||||
ChannelLayout::STEREO
|
ChannelLayout::STEREO
|
||||||
);
|
);
|
||||||
aframe.set_channels(2);
|
if aframe.planes() > 0 {
|
||||||
aframe.set_rate(44100);
|
aframe.set_channels(2);
|
||||||
aframe.set_pts(Some(frame));
|
aframe.set_rate(44100);
|
||||||
let aplane: &mut [(i16, i16)] = aframe.plane_mut(0);
|
aframe.set_pts(Some(frame));
|
||||||
eprintln!("Audio buffer length {} -> {}", self.audio_buf.len(), aplane.len());
|
let aplane: &mut [(i16, i16)] = aframe.plane_mut(0);
|
||||||
aplane.copy_from_slice(self.audio_buf.as_ref());
|
eprintln!("Audio buffer length {} -> {}", self.audio_buf.len(), aplane.len());
|
||||||
//eprintln!("src: {:?}, dest: {:?}", self.audio_buf, aplane);
|
aplane.copy_from_slice(self.audio_buf.as_ref());
|
||||||
self.audio_buf.clear();
|
//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());
|
eprintln!("🎞 queue frame pts {:?}", aframe.pts());
|
||||||
self.audio_filter.get("in").unwrap().source().add(&aframe).unwrap();
|
self.audio_filter.get("in").unwrap().source().add(&aframe).unwrap();
|
||||||
|
|
||||||
let mut filtered_aframe = frame::Audio::empty();
|
let mut filtered_aframe = frame::Audio::empty();
|
||||||
loop {
|
loop {
|
||||||
match self.audio_filter.get("out").unwrap().sink().frame(&mut filtered_aframe) {
|
match self.audio_filter.get("out").unwrap().sink().frame(&mut filtered_aframe) {
|
||||||
Ok(..) => {
|
Ok(..) => {
|
||||||
eprintln!("🔊 Got filtered audio frame {:?} pts {:?}", filtered_aframe, filtered_aframe.pts());
|
eprintln!("🔊 Got filtered audio frame {:?} pts {:?}", filtered_aframe, filtered_aframe.pts());
|
||||||
if self.audio_filter.get("in").unwrap().source().failed_requests() > 0 {
|
if self.audio_filter.get("in").unwrap().source().failed_requests() > 0 {
|
||||||
println!("🎥 failed to put filter input frame");
|
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