get_thumbnail_video
로컬 비디오 파일 또는 비디오 URL에서 썸네일을 생성하기 위한 플러터 플러그인입니다.
이 플러그인은 동영상 파일 또는 URL에서 썸네일을 생성합니다. 메모리에 이미지를 반환하거나 파일에 기록합니다. 이미지 형식, 해상도 및 품질을 제어할 수 있는 다양한 옵션을 제공합니다. iOS 및 Android를 지원합니다.
{"sdk":"flutter"}{"sdk":"flutter"}^1.1.0^2.1.8^0.3.4+2{"sdk":"flutter"}>=4.0.0 <6.0.0아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
This project is a modified fork of video_thumbnail, originally created by John Zhong. Modifications and improvements have been made to adapt the project to new needs.
This plugin generates thumbnail from video file or URL. It returns image in memory or writes into a file. It offers rich options to control the image format, resolution and quality. Supports iOS / Android / web.
video-file video-url
| function | parameter | description | return |
|---|---|---|---|
| thumbnailData | String [video], optional Map<String, dynamic> [headers], 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<Uint8List>] |
| thumbnailFile | String [video], optional Map<String, dynamic> [headers], String [thumbnailPath](folder or full path where to store the thumbnail file, null to save to same folder as the video file) this ignored on the web, 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>] |
Warning:
Giving both the
maxHeightandmaxWidthhas different result on Android platform, it actually scales the thumbnail to the specified maxHeight and maxWidth. To generate the thumbnail from a network resource, thevideomust be properly URL encoded.
Installing add get_thumbnail_video as a dependency in your pubspec.yaml file.
dependencies:
get_thumbnail_video: ^0.7.3
import
import 'package:get_thumbnail_video/video_thumbnail.dart';
Generate a thumbnail in memory from video file
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,
);
Generate a thumbnail file from video URL
XFile thumbnailFile = await VideoThumbnail.thumbnailFile(
video: "https://flutter.github.io/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,
);
final image = kIsWeb ? Image.network(thumbnailFile.path) : Image.file(File(thumbnailFile.path));
Generate a thumbnail file from video Assets declared in pubspec.yaml
final byteData = await rootBundle.load("assets/my_video.mp4");
Directory tempDir = await getTemporaryDirectory();
File tempVideo = File("${tempDir.path}/assets/my_video.mp4")
..createSync(recursive: true)
..writeAsBytesSync(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
final fileName = await VideoThumbnail.thumbnailFile(
video: tempVideo.path,
thumbnailPath: (await getTemporaryDirectory()).path,
imageFormat: ImageFormat.PNG,
quality: 100,
);
Flutter Thumbnail on the Web platform has some limitations that might surprise developers more familiar with mobile/desktop targets.
In no particular order:
This plugin requires the server hosting the video to include appropriate CORS headers in the
response. Specifically, the
server must include the Access-Control-Allow-Origin and Access-Control-Allow-Methods headers in
the response to the
request.
For more information, please refer to
the Mozilla Developer Network documentation.
This plugin requires the server hosting the video to support HTTP range headers. If the server does not support range requests, the plugin may generate a thumbnail from the first frame of the video instead of the desired frame. For more information, please refer to the Mozilla Developer Network documentation.
Fork or pull requests are always welcome. Currently it seems have a little performance issue while generating WebP thumbnail by using libwebp under iOS.