Skip to content

Commit 0c1746b

Browse files
committed
feat(avfilter): add opt_set_array method for array option manipulation
1 parent 59991ad commit 0c1746b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/avfilter/avfilter.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,45 @@ impl AVFilterContext {
9494
Ok(())
9595
}
9696

97+
/// Add, replace, or remove elements for an array option.
98+
///
99+
/// This is a safe wrapper around `av_opt_set_array`.
100+
/// - key: option name
101+
/// - start_elem: index of the first array element to modify
102+
/// - vals: None to remove elements, Some(&[T]) to insert/replace elements
103+
/// - val_type: the `AVOptionType` corresponding to T (e.g. AV_OPT_TYPE_INT)
104+
///
105+
/// Note: This wrapper always searches children (AV_OPT_SEARCH_CHILDREN).
106+
#[cfg(feature = "ffmpeg7_1")]
107+
pub fn opt_set_array<T>(
108+
&mut self,
109+
key: &CStr,
110+
start_elem: u32,
111+
vals: Option<&[T]>,
112+
val_type: ffi::AVOptionType,
113+
) -> Result<()> {
114+
let (nb_elems, val_ptr) = match vals {
115+
Some(slice) => (
116+
slice.len() as u32,
117+
slice.as_ptr() as *const std::os::raw::c_void,
118+
),
119+
None => (0u32, std::ptr::null()),
120+
};
121+
unsafe {
122+
ffi::av_opt_set_array(
123+
self.as_mut_ptr().cast(),
124+
key.as_ptr(),
125+
ffi::AV_OPT_SEARCH_CHILDREN as i32,
126+
start_elem,
127+
nb_elems,
128+
val_type,
129+
val_ptr,
130+
)
131+
}
132+
.upgrade()?;
133+
Ok(())
134+
}
135+
97136
/// Add a frame to the buffer source.
98137
pub fn buffersrc_add_frame(
99138
&mut self,

0 commit comments

Comments
 (0)