视频缩略图

此插件可从视频文件或URL生成缩略图。它可以在内存中返回图像或将其写入文件。它提供了丰富的选项来控制图像格式、分辨率和质量。支持iOS和Android。

video_file

video_thumbnail

方法

功能 参数 描述 返回值
thumbnailData String [video], ImageFormat [imageFormat](JPEG/PNG/WEBP), int [maxHeight](0: for the original resolution of the video, or scaled by the source aspect ratio), [maxWidth](0: for the original resolution of the video, or scaled by the source aspect ratio), int[timeMs]generates the thumbnail from the frame around the specified millisecond, int[quality](0-100)|generates thumbnail from[video]|[Future]`
thumbnailFile String [video], String [thumbnailPath](folder or full path where to store the thumbnail file, null to save to same folder as the video file), ImageFormat [imageFormat](JPEG/PNG/WEBP), int [maxHeight](0: for the original resolution of the video, or scaled by the source aspect ratio), int [maxWidth](0: for the original resolution of the video, or scaled by the source aspect ratio), int [timeMs] generates the thumbnail from the frame around the specified millisecond, int [quality](0-100) creates a file of the thumbnail from the [video] [Future<String>]

警告

Giving both the maxHeight and maxWidth has different result on Android platform, it actually scales the thumbnail to the specified maxHeight and maxWidth.
To generate the thumbnail from a network resource, the video must be properly URL encoded.

用法

安装
add video_thumbnail as a dependency in your pubspec.yaml file.

dependencies:
  video_thumbnail: ^0.3.1

导入

import 'package:video_thumbnail/video_thumbnail.dart';

在内存中从视频文件生成缩略图

final uint8list = await VideoThumbnail.thumbnailData(
  video: videofile.path,
  imageFormat: ImageFormat.JPEG,
  maxWidth: 128, // specify the width of the thumbnail, let the height auto-scaled to keep the source aspect ratio
  quality: 25,
);

从视频URL生成缩略图文件

final fileName = await VideoThumbnail.thumbnailFile(
  video: "https://github.flutterdart.cn/assets-for-api-docs/assets/videos/butterfly.mp4",
  thumbnailPath: (await getTemporaryDirectory()).path,
  imageFormat: ImageFormat.WEBP,
  maxHeight: 64, // specify the height of the thumbnail, let the width auto-scaled to keep the source aspect ratio
  quality: 75,
);

注意事项

欢迎Fork或Pull Requests。目前使用libwebp通过iOS生成WebP缩略图似乎存在一些性能问题。

GitHub

https://github.com/justsoft/video_thumbnail