| Crates.io | first_last_frame |
| lib.rs | first_last_frame |
| version | 67.0.31 |
| created_at | 2026-01-07 08:31:24.142395+00 |
| updated_at | 2026-01-07 08:31:24.142395+00 |
| description | High-quality integration for https://supermaker.ai/video/first-last-frame/ |
| homepage | https://supermaker.ai/video/first-last-frame/ |
| repository | https://github.com/qy-upup/first-last-frame |
| max_upload_size | |
| id | 2027787 |
| size | 11,269 |
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.
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
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
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
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
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
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(())
}
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/