From 70fae591d3bb1a5187fb07dc9e03c4e88a8095fc Mon Sep 17 00:00:00 2001 From: tilpner Date: Fri, 21 Apr 2023 14:36:35 +0200 Subject: [PATCH] feat(format/stream): expose frame-rate guessing --- src/format/stream/stream.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/format/stream/stream.rs b/src/format/stream/stream.rs index c9369ae..b298c24 100644 --- a/src/format/stream/stream.rs +++ b/src/format/stream/stream.rs @@ -1,3 +1,5 @@ +use std::ptr; + use libc::c_int; use super::Disposition; @@ -96,6 +98,23 @@ impl<'a> Stream<'a> { unsafe { Rational::from((*self.as_ptr()).avg_frame_rate) } } + pub fn guess_frame_rate(&self) -> Option { + unsafe { + let r = Rational::from(av_guess_frame_rate( + self.context.as_ptr() as *mut _, + self.as_ptr() as *mut _, + ptr::null_mut(), + )); + + if r == Rational(0, 1) { + None + } + else { + Some(r) + } + } + } + pub fn metadata(&self) -> DictionaryRef<'_> { unsafe { DictionaryRef::wrap((*self.as_ptr()).metadata) } }