Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix audio frames decoding #48

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions src/filter_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,6 @@ impl FilterGraph {
in_audio_frames: &[Frame],
in_video_frames: &[Frame],
) -> Result<(Vec<Frame>, Vec<Frame>), String> {
if in_audio_frames.len() != self.audio_inputs.len() {
return Err(format!(
"unable to process graph, mistmatch input frames ({}) with graph inputs ({})",
in_audio_frames.len(),
self.audio_inputs.len()
));
}
if in_video_frames.len() != self.video_inputs.len() {
return Err(format!(
"unable to process graph, mistmatch input frames ({}) with graph inputs ({})",
Expand All @@ -255,13 +248,13 @@ impl FilterGraph {

let mut output_audio_frames = vec![];
let mut output_video_frames = vec![];

unsafe {
for (index, frame) in in_audio_frames.iter().enumerate() {
check_result!(av_buffersrc_add_frame(
self.audio_inputs[index].context,
frame.frame
));
for frame in in_audio_frames {
for input in &self.audio_inputs {
if input.get_label() == frame.name.clone().unwrap() {
check_result!(av_buffersrc_add_frame(input.context, frame.frame));
}
}
}
for (index, frame) in in_video_frames.iter().enumerate() {
check_result!(av_buffersrc_add_frame(
Expand All @@ -271,18 +264,21 @@ impl FilterGraph {
}

for (index, output_filter) in self.audio_outputs.iter().enumerate() {
let output_frame = av_frame_alloc();
let result = av_buffersink_get_frame(output_filter.context, output_frame);
if result == AVERROR(EAGAIN) || result == AVERROR_EOF {
break;
} else {
check_result!(result);
let mut result = 0;
while result == 0 {
let output_frame = av_frame_alloc();
result = av_buffersink_get_frame(output_filter.context, output_frame);
if result == AVERROR(EAGAIN) || result == AVERROR_EOF {
break;
} else {
check_result!(result);
}
output_audio_frames.push(Frame {
name: Some(output_filter.get_label()),
frame: output_frame,
index,
});
}
output_audio_frames.push(Frame {
name: Some(output_filter.get_label()),
frame: output_frame,
index,
});
}

for (index, output_filter) in self.video_outputs.iter().enumerate() {
Expand Down
7 changes: 3 additions & 4 deletions src/order/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::filter_graph::FilterGraph;
use std::collections::HashMap;

mod decoder_format;
Expand All @@ -15,6 +14,7 @@ mod output_result;
pub mod parameters;
pub mod stream;

use crate::filter_graph::FilterGraph;
use crate::frame::Frame;
use crate::order::decoder_format::DecoderFormat;
use crate::order::encoder_format::EncoderFormat;
Expand All @@ -26,6 +26,7 @@ use crate::order::output::Output;
use crate::order::output_kind::OutputKind;
pub use crate::order::output_result::OutputResult;
pub use crate::order::parameters::*;
use crate::order::stream::Stream;

use crate::packet::Packet;
use std::ptr::null_mut;
Expand Down Expand Up @@ -85,9 +86,7 @@ impl Order {
break;
}

if audio_frames.len() == self.filter_graph.audio_inputs.len()
&& video_frames.len() == self.filter_graph.video_inputs.len()
{
if video_frames.len() == self.filter_graph.video_inputs.len() {
let (output_audio_frames, output_video_frames) =
if audio_frames.is_empty() && video_frames.is_empty() {
(audio_frames, video_frames)
Expand Down
Loading