first_last_frame

Crates.iofirst_last_frame
lib.rsfirst_last_frame
version67.0.31
created_at2026-01-07 08:31:24.142395+00
updated_at2026-01-07 08:31:24.142395+00
descriptionHigh-quality integration for https://supermaker.ai/video/first-last-frame/
homepagehttps://supermaker.ai/video/first-last-frame/
repositoryhttps://github.com/qy-upup/first-last-frame
max_upload_size
id2027787
size11,269
(qy-upup)

documentation

README

first-last-frame

A Rust crate to efficiently extract the first and last frames from video files. This utility provides a simple and reliable way to obtain representative images from video content.

Installation

Add the following to your Cargo.toml file under the [dependencies] section: toml first-last-frame = "0.1.0" # Replace with the actual version number

Usage Examples

Here are several examples demonstrating how to use the first-last-frame crate:

1. Extracting Frames and Saving as PNG:

This example demonstrates extracting the first and last frames from a video file and saving them as PNG images. rust use first_last_frame::{extract_first_and_last_frame, ImageFormat};

fn main() -> Result<(), Box> { let video_path = "path/to/your/video.mp4"; let output_dir = "output";

extract_first_and_last_frame(video_path, output_dir, ImageFormat::Png)?;

println!("First and last frames extracted and saved to: {}", output_dir);
Ok(())

}

2. Specifying a Different Image Format (JPEG):

This example shows how to extract the frames and save them in JPEG format. rust use first_last_frame::{extract_first_and_last_frame, ImageFormat};

fn main() -> Result<(), Box> { let video_path = "path/to/your/video.mp4"; let output_dir = "output";

extract_first_and_last_frame(video_path, output_dir, ImageFormat::Jpeg)?;

println!("First and last frames extracted and saved to: {}", output_dir);
Ok(())

}

3. Handling Errors Gracefully:

This example demonstrates how to handle potential errors during the frame extraction process. rust use first_last_frame::{extract_first_and_last_frame, ImageFormat};

fn main() { let video_path = "path/to/your/video.mp4"; let output_dir = "output";

match extract_first_and_last_frame(video_path, output_dir, ImageFormat::Png) {
    Ok(_) => println!("First and last frames extracted successfully."),
    Err(e) => eprintln!("Error extracting frames: {}", e),
}

}

4. Extracting Frames to a Specific Directory:

This example shows how to specify a specific directory for the extracted frames. rust use first_last_frame::{extract_first_and_last_frame, ImageFormat}; use std::path::Path;

fn main() -> Result<(), Box> { let video_path = "path/to/your/video.mp4"; let output_dir = Path::new("custom_output_directory");

extract_first_and_last_frame(video_path, output_dir.to_str().unwrap(), ImageFormat::Png)?;

println!("First and last frames extracted and saved to: {}", output_dir.display());
Ok(())

}

5. Using with Multiple Videos:

This example demonstrates batch processing multiple videos. rust use first_last_frame::{extract_first_and_last_frame, ImageFormat};

fn main() -> Result<(), Box> { let video_paths = vec!["path/to/video1.mp4", "path/to/video2.mp4"]; let output_dir = "output";

for video_path in video_paths {
    println!("Processing: {}", video_path);
    match extract_first_and_last_frame(video_path, output_dir, ImageFormat::Png) {
        Ok(_) => println!("Successfully processed: {}", video_path),
        Err(e) => eprintln!("Error processing {}: {}", video_path, e),
    }
}

Ok(())

}

Feature Summary

  • Simple API: Easy-to-use function for extracting first and last frames.
  • Multiple Image Formats: Supports saving frames as PNG or JPEG.
  • Error Handling: Provides robust error handling for various scenarios.
  • Cross-Platform: Compatible with multiple operating systems supported by Rust.
  • Efficient: Optimized for performance to quickly extract frames from videos.

License

MIT License

This crate is part of the first-last-frame ecosystem. For advanced features and enterprise-grade tools, visit: https://supermaker.ai/video/first-last-frame/

Commit count: 0

cargo fmt