一个 Flutter 插件,可在 Android、iOS、macOS 和 Windows 上使用原生平台 API 生成视频缩略图。它利用系统级功能高效地从视频中提取帧,确保跨平台的高性能和兼容性。该插件专为需要可靠缩略图创建而无需依赖跨平台图像处理库的开发者设计。它可无缝集成到需要视频预览或媒体浏览功能的 Flutter 应用中。
适合场景
在媒体画廊中生成视频预览
为视频播放UI创建缩略图
构建视频上传或编辑界面
启用快速视频元数据提取
支持离线视频内容索引
主要特点
使用原生 API 以实现最佳性能
跨平台支持(Android、iOS、macOS、Windows)
用于帧提取的简单 API
高质量缩略图生成
最小依赖开销
适合对象
媒体应用开发者
视频流媒体应用
内容管理系统
教育或创意工具
具有视频库功能的应用程序
使用建议
在 Android 和 iOS 上需要平台特定的权限
根据视频编解码器或格式,结果可能有所不同
缩略图输出的自定义选项有限
依赖原生SDK的可用性
不适用于实时缩略图生成
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
fc_native_video_thumbnail
A Flutter plugin to create video thumbnails via native APIs.
iOS
Android
macOS
Windows
Linux
Source (Path)
✅
✅
✅
✅
✅
Source (Uri)
✅
✅
✅
-
-
Seeking
✅
⚠️
✅
-
✅
⚠️ Android seeking is only supported when the source file is a Uri.
Linux requires libavformat, libavcodec, libavutil, libswscale (FFmpeg) and libjpeg installed on the system.
Usage
saveThumbnailToFile saves the thumbnail to a file path.
Returns true if thumbnail was successfully created. Or false if thumbnail is not available.
Throws if error happens during thumbnail generation.
saveThumbnailToBytes returns the thumbnail as a byte array.
Returns the thumbnail as bytes if successfully created. Or null if thumbnail is not available.
Throws if error happens during thumbnail generation.
Example:
final plugin = FcNativeVideoThumbnail();
try {
/// Extracts a thumbnail from [srcFile] with the given options and saves it to [destFile].////// [srcFile] source video path or Uri (See [srcFileUri])./// [srcFileUri] If true, [srcFile] is a Uri (Android/iOS/macOS only)./// [destFile] thumbnail save path./// [width] / [height] max dimensions of the thumbnail image./// Windows doesn't support non-square thumbnail images, only [width] is used in Windows, resulting in a [width]x[width] max thumbnail./// [format] only "jpeg" is supported. Defaults to "jpeg"./// [quality] a fallback value for the quality of the thumbnail image (0-100). May be ignored by the platform./// [at] the time position of the thumbnail./// Not supported on Windows, or Android if source file is a path.final generated = await plugin.saveThumbnailToFile(
srcFile: srcFile,
destFile: destFile,
width: 300,
height: 300,
quality: 90);
// `saveThumbnailToBytes` has the same options as `saveThumbnailToFile` except `destFile`.final thumbnailBytes = await plugin.saveThumbnailToBytes(
srcFile: srcFile,
width: 300,
height: 300,
quality: 90);
} catch (err) {
// Handle platform errors.
}