一個 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.
}