video_snapshot_generator 0.0.1
video_snapshot_generator: ^0.0.1 copied to clipboard
Generate video thumbnails with custom dimensions and quality settings for Flutter applications.
video_snapshot_generator #
A Flutter package for generating video snapshots and thumbnails with custom dimensions and quality settings. This package provides a simple and efficient way to generate thumbnails from video files in Flutter applications.
Features #
- ๐ฌ Extract frames from video files at specific time positions
- ๐ Customizable frame dimensions (width and height)
- ๐จ Quality control settings (1-100)
- โฐ Extract frames at specific time positions
- ๐ผ๏ธ Multiple output formats (JPEG, PNG, WebP)
- ๐ฑ Cross-platform support (Android, iOS)
- ๐ Automatic permission handling
- โก Efficient frame extraction
- ๐งช Comprehensive error handling
- ๐ Extract multiple frames at different time positions
- ๐ Custom output path support
- ๐ฏ Precise time-based extraction
Getting Started #
Installation #
Add this dependency to your pubspec.yaml file:
dependencies:
video_snapshot_generator: ^0.0.1
Then run:
flutter pub get
Platform Setup #
Android
Add the following permissions to your android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
For Android 13+ (API level 33+), you may also need:
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
iOS
No additional setup required for iOS.
Web
No additional setup required for web.
Desktop
No additional setup required for desktop platforms.
Usage #
Basic Usage #
import 'package:video_snapshot_generator/video_snapshot_generator.dart';
// Generate a thumbnail with default settings
final result = await VideoSnapshotGenerator.generateThumbnail(
videoPath: '/path/to/video.mp4',
);
print('Frame saved at: ${result.path}');
print('Dimensions: ${result.width}x${result.height}');
print('File size: ${result.dataSize} bytes');
Advanced Usage #
import 'package:video_snapshot_generator/video_snapshot_generator.dart';
// Generate a thumbnail with custom settings
final result = await VideoSnapshotGenerator.generateThumbnail(
videoPath: '/path/to/video.mp4',
options: ThumbnailOptions(
width: 640,
height: 480,
quality: 90,
timeMs: 5000, // Generate at 5 seconds
format: ThumbnailFormat.png,
),
);
// Extract multiple frames at different time positions
final results = await VideoSnapshotGenerator.generateMultipleThumbnails(
videoPath: '/path/to/video.mp4',
timePositions: [0, 5000, 10000, 15000], // 0s, 5s, 10s, 15s
options: ThumbnailOptions(
width: 320,
height: 240,
quality: 75,
),
);
ThumbnailOptions #
The ThumbnailOptions class allows you to customize the frame extraction:
| Parameter | Type | Default | Description |
|---|---|---|---|
width |
int |
320 | Width of the frame in pixels |
height |
int |
240 | Height of the frame in pixels |
quality |
int |
75 | Quality of the frame from 1-100 |
timeMs |
int |
0 | Time position in milliseconds to extract from |
path |
String? |
null |
Custom output path (uses temporary directory if not specified) |
format |
ThumbnailFormat |
ThumbnailFormat.jpeg |
Output format |
ThumbnailResult #
The ThumbnailResult class contains information about the extracted frame:
| Property | Type | Description |
|---|---|---|
path |
String |
File path where the frame was saved |
width |
int |
Actual width of the extracted frame |
height |
int |
Actual height of the extracted frame |
dataSize |
int |
Size of the frame file in bytes |
format |
String? |
Format of the extracted frame |
ThumbnailFormat #
Supported output formats:
ThumbnailFormat.jpeg- JPEG format (default)ThumbnailFormat.png- PNG formatThumbnailFormat.webP- WebP format
Error Handling #
The package throws ThumbnailException when frame extraction fails:
try {
final result = await VideoSnapshotGenerator.generateThumbnail(
videoPath: '/path/to/video.mp4',
);
} on ThumbnailException catch (e) {
print('Frame extraction failed: ${e.message}');
} catch (e) {
print('Unexpected error: $e');
}
Common Error Scenarios #
- File not found: The specified video file doesn't exist
- Permission denied: Storage permissions are not granted
- Invalid parameters: Width, height, quality, or time values are out of range
- Unsupported format: The video format is not supported
- Insufficient storage: Not enough storage space for the frame
Platform Support #
| Platform | Support | Notes |
|---|---|---|
| Android | โ Full | Requires storage permissions |
| iOS | โ Full | No additional setup required |
| Web | โ Full | Limited by browser capabilities |
| Windows | โ Full | No additional setup required |
| macOS | โ Full | No additional setup required |
| Linux | โ Full | No additional setup required |
Performance Considerations #
- Memory usage: Large video files may consume significant memory during processing
- Processing time: Frame extraction time depends on video size and complexity
- Storage: Extracted frames are stored temporarily by default
- Quality vs. Size: Higher quality settings result in larger file sizes
Best Practices #
- Request permissions early: Request storage permissions before attempting to extract frames
- Handle errors gracefully: Always wrap frame extraction in try-catch blocks
- Use appropriate dimensions: Choose dimensions that balance quality and performance
- Clean up files: Remove temporary frames when they're no longer needed
- Validate input: Ensure video paths exist and parameters are within valid ranges
Example #
Check out the example/ directory for a complete Flutter application demonstrating how to use this package. The example app includes:
- Video file selection
- Customizable frame extraction options
- Real-time preview
- Multiple frame extraction
- Error handling
- Modern Material 3 UI
Testing #
The package includes comprehensive test coverage:
# Run unit tests
flutter test
# Run integration tests
flutter test test/integration_test.dart
# Generate test coverage report
flutter test --coverage
Contributing #
Contributions are welcome! Please feel free to submit a Pull Request. Before contributing, please ensure:
- All tests pass
- Code follows the project's style guidelines
- New features include appropriate tests
- Documentation is updated
Development Setup #
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License #
This project is licensed under the MIT License - see the LICENSE file for details.
Dependencies #
This package depends on:
video_thumbnail: Core video frame extraction functionalitypath_provider: File system path managementpermission_handler: Cross-platform permission handling
Support #
If you encounter any issues or have questions, please:
- Check the documentation
- Search existing issues
- Create a new issue with detailed information
Changelog #
See CHANGELOG.md for a detailed list of changes and version history.
Roadmap #
Future versions may include:
- Video metadata extraction
- Batch processing capabilities
- Custom frame shapes
- Advanced filtering options
- Performance optimizations
- Additional output formats
Acknowledgments #
- video_thumbnail package for core functionality
- path_provider for file system access
- permission_handler for permission management
- Flutter team for the excellent framework