diff --git a/src/filter_graph.rs b/src/filter_graph.rs index f27df7d..71f6770 100644 --- a/src/filter_graph.rs +++ b/src/filter_graph.rs @@ -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::*; @@ -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)? }; @@ -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()); diff --git a/src/order/decoder_format.rs b/src/order/decoder_format.rs index e6b8fbf..c8011be 100644 --- a/src/order/decoder_format.rs +++ b/src/order/decoder_format.rs @@ -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; @@ -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 { @@ -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 { @@ -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 => { diff --git a/src/video_decoder.rs b/src/video_decoder.rs index 5f62d23..ac1d748 100644 --- a/src/video_decoder.rs +++ b/src/video_decoder.rs @@ -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(