Sampler

Struct Sampler 

Source
pub struct Sampler {
    pub video_path: PathBuf,
    pub output_path: PathBuf,
    pub duration: u64,
    pub sampling_number: usize,
}
Expand description

A collection of arguments for video sampling operations.

This struct holds the necessary parameters for processing video content, including video file path, duration in milliseconds, and optional sampling configuration.

§Parameters

  • video_path: Path to the video file to process.
  • duration: Duration of the video content in milliseconds.
  • sampling_number: Optional number of samples to collect.

§Returns

  • Self: A new instance of Sampler with the provided parameters.

§Notes

  • The sampling_number parameter is optional and will default to a calculated value if not provided.

Fields§

§video_path: PathBuf§output_path: PathBuf§duration: u64§sampling_number: usize

Implementations§

Source§

impl Sampler

Source

pub fn new( video_path: String, output_path: Option<String>, duration: u64, sampling_number: usize, ) -> Result<Self>

Creates a new Sampler instance for video processing.

This function initializes a Sampler with the specified parameters and sets up the output directory.

§Parameters
  • video_path: The path to the video file to process.
  • output_path: An optional path for the output directory; if not provided, a default will be used.
  • duration: The duration of the video in seconds.
  • sampling_number: The number of samples to take from the video.
§Returns
  • Result<Self>: Returns Ok if the Sampler was created successfully, Err if there was an issue creating the output directory.
§Notes
  • The output directory will be created if it does not already exist.
  • If output_path is not provided, a default output path will be generated.
Source§

impl Sampler

Source

pub fn sample_images(&self, running: Arc<AtomicBool>) -> Result<()>

Processes video frames for sampling based on specified criteria.

This function handles the extraction of frames from a video file, either as a single frame or multiple evenly spaced frames.

§Parameters
  • running: A flag indicating whether the process should continue.
  • video_path: Path to the video file to process.
  • duration: Total duration of the video.
  • output_path: Directory where the output images will be saved.
  • sampling_number: Number of frames to extract (1 for single, >1 for multiple).
§Returns
  • Result<()>: Indicates success or failure of the operation.
§Notes
  • If running is false, the function exits early.
  • If duration is 0, returns an error as it’s an invalid value.
  • Based on sampling_number, the function will either extract a single frame or multiple frames.

Trait Implementations§

Source§

impl Debug for Sampler

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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, 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.