#![allow(unsafe_code)]
use std::path::{Path, PathBuf};
use std::time::Duration;
use crate::DecodeError;
pub struct KeyframeEnumerator {
input: PathBuf,
stream_index: Option<usize>,
}
impl KeyframeEnumerator {
pub fn new(input: impl AsRef<Path>) -> Self {
Self {
input: input.as_ref().to_path_buf(),
stream_index: None,
}
}
#[must_use]
pub fn stream_index(self, idx: usize) -> Self {
Self {
stream_index: Some(idx),
..self
}
}
pub fn run(self) -> Result<Vec<Duration>, DecodeError> {
if !self.input.exists() {
return Err(DecodeError::AnalysisFailed {
reason: format!("file not found: {}", self.input.display()),
});
}
unsafe { super::analysis_inner::enumerate_keyframes_unsafe(&self.input, self.stream_index) }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn keyframe_enumerator_missing_file_should_return_analysis_failed() {
let result = KeyframeEnumerator::new("does_not_exist_99999.mp4").run();
assert!(
matches!(result, Err(DecodeError::AnalysisFailed { .. })),
"expected AnalysisFailed for missing file, got {result:?}"
);
}
}