use std::time::Duration;
mod decode;
mod encode;
mod extract;
mod probe;
mod select;
mod tooling;
pub use extract::extract;
pub use probe::{Probe, probe};
pub use tooling::{Tooling, tooling};
#[derive(Clone, Debug, PartialEq)]
pub struct Options {
pub sample_fps: f32,
pub max_width: u32,
pub hash_threshold: u32,
pub max_frames: usize,
pub min_hold_ms: u64,
pub jpeg_quality: u8,
pub timeout: Duration,
pub max_duration_ms: Option<u64>,
}
impl Default for Options {
fn default() -> Self {
Self {
sample_fps: 4.0,
max_width: 640,
hash_threshold: 4,
max_frames: 24,
min_hold_ms: 250,
jpeg_quality: 80,
timeout: Duration::from_secs(60),
max_duration_ms: Some(600_000),
}
}
}
#[derive(Clone, PartialEq, Eq)]
pub struct Frame {
pub index: usize,
pub ts_ms: u64,
pub held_ms: u64,
pub width: u32,
pub height: u32,
pub media_type: &'static str,
pub bytes: Vec<u8>,
pub distance_from_previous: u32,
}
impl std::fmt::Debug for Frame {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Frame")
.field("index", &self.index)
.field("ts_ms", &self.ts_ms)
.field("held_ms", &self.held_ms)
.field("width", &self.width)
.field("height", &self.height)
.field("media_type", &self.media_type)
.field("byte_size", &self.bytes.len())
.field("distance_from_previous", &self.distance_from_previous)
.finish()
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct Strip {
pub probe: Probe,
pub frames: Vec<Frame>,
pub sampled: usize,
pub dropped_as_duplicate: usize,
pub dropped_by_cap: usize,
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("video tooling unavailable: {0}")]
ToolingUnavailable(String),
#[error("undecodable video: {0}")]
Undecodable(String),
#[error("video is {duration_ms} ms long, above the {max_ms} ms limit")]
TooLong {
duration_ms: u64,
max_ms: u64,
},
#[error("video decode exceeded {0:?}")]
Timeout(Duration),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("invalid options: {0}")]
Options(String),
}