Skip to main content

ThumbnailHandle

Struct ThumbnailHandle 

Source
pub struct ThumbnailHandle;
Expand description

Thumbnail generation utilities.

All methods are stateless functions that accept a MediaFile reference.

§Example

use std::time::Duration;

use unbundle::{MediaFile, ThumbnailHandle, ThumbnailOptions, UnbundleError};

let mut unbundler = MediaFile::open("input.mp4")?;

// Single thumbnail at 10 seconds, max 640px on longest edge
let thumb = ThumbnailHandle::at_timestamp(
    &mut unbundler,
    Duration::from_secs(10),
    640,
)?;
thumb.save("thumb.jpg")?;

// Contact-sheet grid
let config = ThumbnailOptions::new(4, 4);
let grid = ThumbnailHandle::grid(&mut unbundler, &config)?;
grid.save("grid.png")?;

Implementations§

Source§

impl ThumbnailHandle

Source

pub fn at_timestamp( unbundler: &mut MediaFile, timestamp: Duration, max_dimension: u32, ) -> Result<DynamicImage, UnbundleError>

Extract a single thumbnail at a timestamp, scaled to fit within max_dimension on its longest edge.

Preserves the video’s aspect ratio. For example, a 1920×1080 frame with max_dimension = 640 produces a 640×360 thumbnail.

§Errors

Returns UnbundleError::NoVideoStream if the file has no video, UnbundleError::InvalidTimestamp if the timestamp exceeds the duration, or decoding errors.

Source

pub fn at_frame( unbundler: &mut MediaFile, frame_number: u64, max_dimension: u32, ) -> Result<DynamicImage, UnbundleError>

Extract a single thumbnail at a frame number, scaled to fit within max_dimension on its longest edge.

§Errors

Same as at_timestamp.

Source

pub fn grid( unbundler: &mut MediaFile, config: &ThumbnailOptions, ) -> Result<DynamicImage, UnbundleError>

Generate a thumbnail contact-sheet grid.

Extracts columns × rows frames at evenly-spaced intervals across the video, scales them to the configured thumbnail width (preserving aspect ratio), and composites them into a single image.

§Errors

Returns UnbundleError::NoVideoStream if the file has no video, or decoding / image errors.

§Example
use unbundle::{MediaFile, ThumbnailHandle, ThumbnailOptions, UnbundleError};

let mut unbundler = MediaFile::open("input.mp4")?;
let config = ThumbnailOptions::new(4, 4).with_thumbnail_width(240);
let grid = ThumbnailHandle::grid(&mut unbundler, &config)?;
grid.save("contact_sheet.png")?;
Source

pub fn grid_with_options( unbundler: &mut MediaFile, config: &ThumbnailOptions, extraction_config: &ExtractOptions, ) -> Result<DynamicImage, UnbundleError>

Generate a thumbnail grid with progress/cancellation support.

Like grid but accepts an ExtractOptions for progress callbacks and cancellation.

Source

pub fn smart( unbundler: &mut MediaFile, sample_count: u32, max_dimension: u32, ) -> Result<DynamicImage, UnbundleError>

Extract a “smart” thumbnail that avoids black or near-uniform frames.

Samples sample_count frames evenly across the video and picks the one with the highest pixel variance (most visual detail). The chosen frame is then scaled to fit within max_dimension.

This is useful for generating representative thumbnails without relying on a fixed timestamp that might land on a fade-to-black or title card.

§Errors

Returns UnbundleError::NoVideoStream if the file has no video, or decoding errors.

§Example
use unbundle::{MediaFile, ThumbnailHandle, UnbundleError};

let mut unbundler = MediaFile::open("input.mp4")?;
let thumb = ThumbnailHandle::smart(&mut unbundler, 20, 640)?;
thumb.save("smart_thumb.jpg")?;
Source

pub fn smart_with_options( unbundler: &mut MediaFile, sample_count: u32, max_dimension: u32, extraction_config: &ExtractOptions, ) -> Result<DynamicImage, UnbundleError>

Extract a smart thumbnail with progress/cancellation support.

Like smart but accepts an ExtractOptions for progress callbacks and cancellation.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.