1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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::*;
#[cfg(not(feature = "ffmpeg_5_0"))]
use Error;
#[cfg(not(feature = "ffmpeg_5_0"))]
pub fn register_all() {
unsafe {
avfilter_register_all();
}
}
#[cfg(not(feature = "ffmpeg_5_0"))]
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() {
#[cfg(not(feature = "ffmpeg_5_0"))]
register_all();
assert_eq!(
find("overlay")
.unwrap()
.inputs()
.unwrap()
.map(|input| input.name().unwrap().to_string())
.collect::<Vec<_>>(),
vec!("main", "overlay")
);
}
}