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 ofSamplerwith the provided parameters.
§Notes
- The
sampling_numberparameter is optional and will default to a calculated value if not provided.
Fields§
§video_path: PathBuf§output_path: PathBuf§duration: u64§sampling_number: usizeImplementations§
Source§impl Sampler
impl Sampler
Sourcepub fn new(
video_path: String,
output_path: Option<String>,
duration: u64,
sampling_number: usize,
) -> Result<Self>
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>: ReturnsOkif the Sampler was created successfully,Errif there was an issue creating the output directory.
§Notes
- The output directory will be created if it does not already exist.
- If
output_pathis not provided, a default output path will be generated.
Source§impl Sampler
impl Sampler
Sourcepub fn sample_images(&self, running: Arc<AtomicBool>) -> Result<()>
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
runningis false, the function exits early. - If
durationis 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§
Auto Trait Implementations§
impl Freeze for Sampler
impl RefUnwindSafe for Sampler
impl Send for Sampler
impl Sync for Sampler
impl Unpin for Sampler
impl UnwindSafe for Sampler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more