first-last-frame
A Dart package to easily extract the first and last frames from video files. This utility provides a simple and efficient way to obtain representative images from video content.
Installation
To use this package, add first_last_frame as a dependency in your pubspec.yaml file:
yaml
dependencies:
first_last_frame: ^1.0.0 # Replace with the latest version
Then, run dart pub get to install the package.
Usage
Here are some examples of how to use the first_last_frame package:
1. Extracting frames from a local video file: dart import 'package:first_last_frame/first_last_frame.dart'; import 'dart:io';
void main() async { final videoPath = '/path/to/your/video.mp4'; // Replace with your video file path final outputDirectory = '/path/to/output'; // Replace with your desired output directory
try { final frames = await FirstLastFrame.extractFrames(videoPath, outputDirectory);
if (frames.isNotEmpty) {
print('First frame saved to: ${frames[0].path}');
print('Last frame saved to: ${frames[1].path}');
} else {
print('Failed to extract frames.');
}
} catch (e) { print('Error: $e'); } }
2. Specifying custom filenames for the extracted frames: dart import 'package:first_last_frame/first_last_frame.dart'; import 'dart:io';
void main() async { final videoPath = '/path/to/your/video.mp4'; final outputDirectory = '/path/to/output';
try { final frames = await FirstLastFrame.extractFrames( videoPath, outputDirectory, firstFrameFilename: 'custom_first_frame.jpg', lastFrameFilename: 'custom_last_frame.png', );
if (frames.isNotEmpty) {
print('First frame saved to: ${frames[0].path}');
print('Last frame saved to: ${frames[1].path}');
} else {
print('Failed to extract frames.');
}
} catch (e) { print('Error: $e'); } }
3. Handling potential errors: dart import 'package:first_last_frame/first_last_frame.dart'; import 'dart:io';
void main() async { final videoPath = '/path/to/your/video.mp4'; final outputDirectory = '/path/to/output';
try { final frames = await FirstLastFrame.extractFrames(videoPath, outputDirectory);
// Process the extracted frames
} on FirstLastFrameException catch (e) { print('FirstLastFrameException: ${e.message}'); } catch (e) { print('An unexpected error occurred: $e'); } }
4. Asynchronously processing multiple videos: dart import 'package:first_last_frame/first_last_frame.dart'; import 'dart:io';
void main() async {
final videoPaths =
'/path/to/video1.mp4',
'/path/to/video2.mp4',
'/path/to/video3.mp4',
;
final outputDirectory = '/path/to/output';
await Future.wait(videoPaths.map((videoPath) async { try { final frames = await FirstLastFrame.extractFrames(videoPath, outputDirectory); if (frames.isNotEmpty) { print('Frames extracted for $videoPath'); } } catch (e) { print('Error extracting frames for $videoPath: $e'); } }));
print('Finished processing all videos.'); }
Features
- Easy Frame Extraction: Extracts the first and last frames from a video file with a single function call.
- Customizable Filenames: Allows you to specify custom filenames for the extracted frames.
- Error Handling: Provides specific exceptions for common errors during frame extraction.
- Asynchronous Operation: Uses asynchronous operations to avoid blocking the main thread.
- Platform Agnostic: Designed to work on various platforms supported by Dart.
License
MIT License
This package is part of the first-last-frame ecosystem. For advanced features and enterprise-grade tools, visit: https://supermaker.ai/video/first-last-frame/