Files
ffmpeg-the-third/src/filter/mod.rs
Zhiming Wang 1d0d42d81a filter: test_paditer: register_all before testing the overlay filter
avfilter_register_all required on FFmpeg <4 before avfilter_get_by_name can
find the builtin filters.
2020-07-26 12:42:57 +08:00

80 lines
1.6 KiB
Rust

pub mod flag;
pub use self::flag::Flags;
pub mod pad;
pub use self::pad::Pad;
pub mod filter;
pub use self::filter::Filter;
pub mod context;
pub use self::context::{Context, Sink, Source};
pub mod graph;
pub use self::graph::Graph;
use std::ffi::{CStr, CString};
use std::str::from_utf8_unchecked;
use ffi::*;
use Error;
pub fn register_all() {
unsafe {
avfilter_register_all();
}
}
pub fn register(filter: &Filter) -> Result<(), Error> {
unsafe {
match avfilter_register(filter.as_ptr() as *mut _) {
0 => Ok(()),
_ => Err(Error::InvalidData),
}
}
}
pub fn version() -> u32 {
unsafe { avfilter_version() }
}
pub fn configuration() -> &'static str {
unsafe { from_utf8_unchecked(CStr::from_ptr(avfilter_configuration()).to_bytes()) }
}
pub fn license() -> &'static str {
unsafe { from_utf8_unchecked(CStr::from_ptr(avfilter_license()).to_bytes()) }
}
pub fn find(name: &str) -> Option<Filter> {
unsafe {
let name = CString::new(name).unwrap();
let ptr = avfilter_get_by_name(name.as_ptr());
if ptr.is_null() {
None
} else {
Some(Filter::wrap(ptr as *mut _))
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_paditer() {
register_all();
assert_eq!(
find("overlay")
.unwrap()
.inputs()
.unwrap()
.map(|input| input.name().unwrap().to_string())
.collect::<Vec<_>>(),
vec!("main", "overlay")
);
}
}