pub struct MtmdVideo { /* private fields */ }Expand description
An open video stream, decoded frame-by-frame via ffmpeg.
The notion of “video” exists only at the helper level — it is decoded into a sequence of image frames and timestamp text markers which are then fed through the normal multimodal pipeline.
Requires a build with video support (see MtmdContext::supports_video)
and ffmpeg/ffprobe available at runtime.
§Example
use std::path::Path;
use llama_cpp_4::mtmd::{MtmdVideo, MtmdVideoParams, MtmdVideoItem};
let mut video = MtmdVideo::from_file(mtmd_ctx, Path::new("clip.mp4"),
&MtmdVideoParams::default())?;
while let Some(item) = video.read_next()? {
match item {
MtmdVideoItem::Frame(bitmap) => { /* tokenize the frame */ }
MtmdVideoItem::Text(ts) => { /* insert the timestamp marker */ }
}
}Implementations§
Source§impl MtmdVideo
impl MtmdVideo
Sourcepub fn from_file(
ctx: &MtmdContext,
path: impl AsRef<Path>,
params: &MtmdVideoParams,
) -> Result<Self>
pub fn from_file( ctx: &MtmdContext, path: impl AsRef<Path>, params: &MtmdVideoParams, ) -> Result<Self>
Open a video file for frame-by-frame decoding.
§Errors
Returns MtmdError::VideoInitFailed if the stream cannot be opened
(no video support compiled in, ffprobe not found, file unreadable,
…), or MtmdError::InvalidPath / MtmdError::PathNotUtf8 for a bad
path.
Sourcepub fn from_buf(
ctx: &MtmdContext,
buf: &[u8],
params: &MtmdVideoParams,
) -> Result<Self>
pub fn from_buf( ctx: &MtmdContext, buf: &[u8], params: &MtmdVideoParams, ) -> Result<Self>
Open a video from an in-memory buffer. The buffer is copied internally, so it need not outlive this call.
§Errors
Returns MtmdError::VideoInitFailed if the stream cannot be opened.
Sourcepub fn info(&self) -> MtmdVideoInfo
pub fn info(&self) -> MtmdVideoInfo
Return metadata (resolution, effective fps, estimated frame count) for this stream.
Sourcepub fn read_next(&mut self) -> Result<Option<MtmdVideoItem>>
pub fn read_next(&mut self) -> Result<Option<MtmdVideoItem>>
Read the next item from the stream.
Returns Ok(Some(item)) for each frame or timestamp marker, and
Ok(None) once the end of the stream is reached.
§Errors
Returns MtmdError::VideoReadError on a decode error.