パッケージ、リポジトリ、アプリカテゴリを検索

GitHub リポジトリAlberto-Monteiro/video_thumbnail

video_thumbnail

このプラグインは、動画ファイルまたはURLからサムネイルを生成します。メモリ内の画像を返すか、ファイルに書き込みます。画像形式、解像度、品質を制御するための豊富なオプションを提供しています。iOSおよびAndroidをサポートしています。

video_thumbnail のプロジェクト画像
スター
15
フォーク
42
最終プッシュ(UTC)
2024/11/15
プロジェクト状態
公開中

元の README

以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。

get_video_thumbnail

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.

pub ver license

video-file video-url

Methods

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 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.

Usage

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,
);

Limitations on the Web platform

Flutter Thumbnail on the Web platform has some limitations that might surprise developers more familiar with mobile/desktop targets.

In no particular order:

CORS headers

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.

HTTP range headers

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.

Notes

Fork or pull requests are always welcome. Currently it seems have a little performance issue while generating WebP thumbnail by using libwebp under iOS.

Alberto Monteiro GitHub avatar
GitHub 作者

Alberto Monteiro ↗

I am a developer who loves projects in Java (Spring), Flutter, Angular, and Arduino. Every day is a day to learn 😊.

Rocks T.I.Brasília, Federal District, Brazil公式サイト ↗
言語DartJavaObjective-CRubyHTMLSwift

このリポジトリが公開するパッケージ

使用している依存関係

依存関係一覧 7 件

  • flutter{"sdk":"flutter"}
  • flutter_web_plugins{"sdk":"flutter"}
  • web^1.1.0
  • plugin_platform_interface^2.1.8
  • cross_file^0.3.4+2
  • flutter_test開発用{"sdk":"flutter"}
  • flutter_lints開発用>=4.0.0 <6.0.0

プロジェクトに合うリポジトリを選ぶには?

用途で絞り込み、開発状況を比較し、採用前に元のリポジトリで要件を確認しましょう。

  1. 名前・作者・説明で検索し、技術トピックで絞り込みます。
  2. スター、フォーク、最近のプッシュを比較します。スターは関心の目安であり、品質の保証ではありません。
  3. 利用前に GitHub で README、ライセンス、Issues を確認します。

情報源と管理

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗