Skip to content

Commit

Permalink
revert using stream to add video input to graph and set codec_context…
Browse files Browse the repository at this point in the history
… timebase in new VideoDecoder
  • Loading branch information
Romanelaf committed Feb 8, 2024
1 parent e1e66ab commit 917f461
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/filter_graph.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
audio_decoder::AudioDecoder, filter::Filter, frame::Frame, order::*, stream::Stream, tools,
audio_decoder::AudioDecoder, filter::Filter, frame::Frame, order::*, tools,
video_decoder::VideoDecoder,
};
use ffmpeg_sys_next::*;
Expand Down Expand Up @@ -51,7 +51,6 @@ impl FilterGraph {
&mut self,
label: &str,
video_decoder: &VideoDecoder,
video_stream: Stream,
) -> Result<(), String> {
let buffer = unsafe { Filter::new_with_label(self.graph, "buffer", label)? };

Expand All @@ -61,7 +60,12 @@ impl FilterGraph {
let height = ParameterValue::Int64(i64::from(video_decoder.get_height()));
height.set("height", buffer.context as *mut c_void)?;

let time_base = ParameterValue::Rational(video_stream.get_time_base());
let mut tbc = video_decoder.get_time_base();
if tbc.num == 0 {
tbc.num = 1;
tbc.den = 25;
}
let time_base = ParameterValue::Rational(tbc);
time_base.set("time_base", buffer.context as *mut c_void)?;

let pixel_aspect = ParameterValue::Rational(video_decoder.get_aspect_ratio());
Expand Down
8 changes: 2 additions & 6 deletions src/order/decoder_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::audio_decoder::AudioDecoder;
use crate::filter_graph::FilterGraph;
use crate::format_context::FormatContext;
use crate::order::input::Input;
use crate::stream::Stream;
use crate::subtitle_decoder::SubtitleDecoder;
use crate::tools;
use crate::video_decoder::VideoDecoder;
Expand Down Expand Up @@ -32,7 +31,6 @@ impl DecoderFormat {
let subtitle_decoders = vec![];
let mut video_decoders = vec![];
let mut context = FormatContext::new(path)?;
context.open_input()?;
context.set_frames_addresses(frames);

let identifier = if let Some(ref identifier) = label {
Expand All @@ -43,8 +41,7 @@ impl DecoderFormat {

let video_decoder =
VideoDecoder::new_with_codec(identifier.clone(), codec, *width, *height, 0)?;
let video_stream = Stream::new(context.get_stream(0))?;
graph.add_input_from_video_decoder(&identifier, &video_decoder, video_stream)?;
graph.add_input_from_video_decoder(&identifier, &video_decoder)?;
video_decoders.push(video_decoder);

Ok(DecoderFormat {
Expand Down Expand Up @@ -72,8 +69,7 @@ impl DecoderFormat {
AVMediaType::AVMEDIA_TYPE_VIDEO => {
let video_decoder =
VideoDecoder::new(identifier.clone(), &context, stream.index as isize)?;
let video_stream = Stream::new(context.get_stream(stream.index as isize))?;
graph.add_input_from_video_decoder(&identifier, &video_decoder, video_stream)?;
graph.add_input_from_video_decoder(&identifier, &video_decoder)?;
video_decoders.push(video_decoder);
}
AVMediaType::AVMEDIA_TYPE_AUDIO => {
Expand Down
2 changes: 2 additions & 0 deletions src/video_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ impl VideoDecoder {
unsafe {
let codec = avcodec_find_decoder(format.get_codec_id(stream_index));
let mut codec_context = avcodec_alloc_context3(codec);
(*codec_context).time_base =
(**(*format.format_context).streams.offset(stream_index)).time_base;

check_result!(
avcodec_parameters_to_context(
Expand Down

0 comments on commit 917f461

Please sign in to comment.