use std::collections::HashMap;
use std::ffi::CStr;
pub(super) unsafe fn extract_metadata(
ctx: *mut ff_sys::AVFormatContext,
) -> HashMap<String, String> {
let mut metadata = HashMap::new();
unsafe {
let dict = (*ctx).metadata;
if dict.is_null() {
return metadata;
}
let mut entry: *const ff_sys::AVDictionaryEntry = std::ptr::null();
let flags = ff_sys::AV_DICT_IGNORE_SUFFIX.cast_signed();
loop {
entry = ff_sys::av_dict_get(dict, c"".as_ptr(), entry, flags);
if entry.is_null() {
break;
}
let key_ptr = (*entry).key;
let value_ptr = (*entry).value;
if key_ptr.is_null() || value_ptr.is_null() {
continue;
}
let key = CStr::from_ptr(key_ptr).to_string_lossy().into_owned();
let value = CStr::from_ptr(value_ptr).to_string_lossy().into_owned();
metadata.insert(key, value);
}
}
metadata
}