mirror of
https://github.com/encounter/rust-ffmpeg-zmwangx.git
synced 2026-07-10 21:18:40 -07:00
Context time_base / frame_rate adjustments
- Moves `time_base` from `Decoder` and `set_time_base` from `Encoder` to the base `Context` to unify the API for both types. - Adds `packet_time_base` and `set_packet_time_base` to `Decoder`. - Moves `set_frame_rate` from `Encoder` to `Context` and adds a `frame_rate` getter.
This commit is contained in:
+26
-1
@@ -8,7 +8,7 @@ use super::{threading, Compliance, Debug, Flags, Id, Parameters};
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
use media;
|
||||
use {Codec, Error};
|
||||
use {Codec, Error, Rational};
|
||||
|
||||
pub struct Context {
|
||||
ptr: *mut AVCodecContext,
|
||||
@@ -138,6 +138,31 @@ impl Context {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn time_base(&self) -> Rational {
|
||||
unsafe { Rational::from((*self.as_ptr()).time_base) }
|
||||
}
|
||||
|
||||
pub fn set_time_base<R: Into<Rational>>(&mut self, value: R) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).time_base = value.into().into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn frame_rate(&self) -> Rational {
|
||||
unsafe { Rational::from((*self.as_ptr()).framerate) }
|
||||
}
|
||||
|
||||
pub fn set_frame_rate<R: Into<Rational>>(&mut self, value: Option<R>) {
|
||||
unsafe {
|
||||
if let Some(value) = value {
|
||||
(*self.as_mut_ptr()).framerate = value.into().into();
|
||||
} else {
|
||||
(*self.as_mut_ptr()).framerate.num = 0;
|
||||
(*self.as_mut_ptr()).framerate.den = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Context {
|
||||
|
||||
@@ -107,8 +107,14 @@ impl Decoder {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn time_base(&self) -> Rational {
|
||||
unsafe { Rational::from((*self.as_ptr()).time_base) }
|
||||
pub fn packet_time_base(&self) -> Rational {
|
||||
unsafe { Rational::from((*self.as_ptr()).pkt_timebase) }
|
||||
}
|
||||
|
||||
pub fn set_packet_time_base<R: Into<Rational>>(&mut self, value: R) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).pkt_timebase = value.into().into();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -116,23 +116,6 @@ impl Encoder {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_time_base<R: Into<Rational>>(&mut self, value: R) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).time_base = value.into().into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_frame_rate<R: Into<Rational>>(&mut self, value: Option<R>) {
|
||||
unsafe {
|
||||
if let Some(value) = value {
|
||||
(*self.as_mut_ptr()).framerate = value.into().into();
|
||||
} else {
|
||||
(*self.as_mut_ptr()).framerate.num = 0;
|
||||
(*self.as_mut_ptr()).framerate.den = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Encoder {
|
||||
|
||||
Reference in New Issue
Block a user