搜索分类、插件与代码仓

插件详情v3.1.4

video_compress

Flutter 的轻量级视频处理库。从 Dart 代码中压缩视频、移除音频并获取视频缩略图。

AndroidiOSmacOS
近 30 天下载
22.4万
喜欢数
748
Pub 分数
140

安装插件

flutter pub add video_compress

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个轻量级的 Flutter 包,用于视频处理,使开发者能够直接从 Dart 代码中压缩视频、移除音频轨道并生成缩略图。专为 Android、iOS 和 macOS 上的高效多媒体处理而设计,无需原生平台代码即可简化常见的视频处理任务。非常适合需要设备端视频优化和预览生成的应用。

适合场景

  • 压缩大视频文件以节省存储空间
  • 从视频中移除音频
  • 从视频文件生成缩略图
  • 优化视频以上传
  • 实时处理视频
  • 通过压缩媒体减少应用大小

主要特点

  • 视频压缩支持
  • 音频移除功能
  • 缩略图提取
  • 跨平台兼容性
  • 简单的 Dart API
  • 轻便且快速

适合对象

  • 媒体密集型应用
  • 视频分享平台
  • 内容创作工具
  • 带有视频上传的移动应用
  • 需要离线视频处理的应用
  • 寻求最小原生代码的开发者

使用建议

  • 需要原生平台权限
  • 可能会影响低端设备的性能
  • 仅限基本视频操作
  • 依赖于底层原生库
  • 不适合复杂的视频编辑
  • 文件大小的减少取决于源质量

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

video_compress

Compress videos, remove audio, manipulate thumbnails, and make your video compatible with all platforms through this lightweight and efficient library. 100% native code was used, we do not use FFMPEG as it is very slow, bloated and the GNU license is an obstacle for commercial applications. In addition, google chrome uses VP8/VP9, safari uses h264, and most of the time, it is necessary to encode the video in two formats, but not with this library. All video files are encoded in an MP4 container with AAC audio that allows 100% compatibility with safari, mozila, chrome, android and iOS.

Works on ANDROID, IOS and desktop (just MacOS for now).

Table of Contents

Lets Get Started

1. Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  video_compress: ^3.1.0
2. Install it

You can install packages from the command line:

with pub:

$  pub get
3. Import it

Now in your Dart code, you can use:

import 'package:video_compress/video_compress.dart';

How to use

Imports
import 'package:video_compress/video_compress.dart';
    

Video compression

MediaInfo mediaInfo = await VideoCompress.compressVideo(
  path,
  quality: VideoQuality.DefaultQuality, 
  deleteOrigin: false, // It's false by default
);

Check compress state

VideoCompress.isCompressing

Get memory thumbnail from VideoPath

final uint8list = await VideoCompress.getByteThumbnail(
  videopath,
  quality: 50, // default(100)
  position: -1 // default(-1)
);

Get File thumbnail from VideoPath

final thumbnailFile = await VideoCompress.getFileThumbnail(
  videopath,
  quality: 50, // default(100)
  position: -1 // default(-1)
);

Get media information

final info = await VideoCompress.getMediaInfo(videopath);

delete all cache files

  • Delete all files generated by this will delete all files located at 'video_compress', you shoule ought to know what are you doing.
await VideoCompress.deleteAllCache()

Listen the compression progress

class _Compress extends State<Compress> {

  Subscription _subscription;

  @override
  void initState() {
    super.initState();
    _subscription =
        VideoCompress.compressProgress$.subscribe((progress) {
      debugPrint('progress: $progress');
    });
  }

  @override
  void dispose() {
    super.dispose();
    _subscription.unsubscribe();
  }
}
TODO
  • Add the trim video function
  • Add cancel function to Android

Methods

Functions Parameters Description Returns
getByteThumbnail String path[video path], int quality(1-100)[thumbnail quality], int position[Get a thumbnail from video position] get thumbnail from video path Future<Uint8List>
getFileThumbnail String path[video path], int quality(1-100)[thumbnail quality], int position[Get a thumbnail from video position] get thumbnail file from video path Future<File>
getMediaInfo String path[video path] get media information from video path Future<MediaInfo>
compressVideo String path[video path], VideoQuality quality[compressed video quality], bool deleteOrigin[delete the origin video], int startTime[compression video start time], int duration[compression video duration from start time], bool includeAudio[is include audio in compressed video], int frameRate[compressed video frame rate] compression video at origin video path Future<MediaInfo>
cancelCompression none cancel compressing Future<void>
deleteAllCache none Delete all files generated by 'video_compress' will delete all files located at 'video_compress' Future<bool>

Subscriptions

Subscriptions Description Stream
compressProgress$ Subscribe the compression progress steam double progress

Contribute

Contributions are always welcome!

acknowledgment

Inspired by the flutter_ffmpeg library. https://github.com/rurico/flutter_video_compress

所属分类

源码仓库

使用此插件的项目