搜索插件、代码仓与 APP 分类

插件详情v1.0.1

ffmpeg_helper

适用于 Flutter 的 FFmpeg 命令助手,支持在 Windows 平台上设置。

AndroidiOSmacOSWindowsLinux
近 30 天下载
104
喜欢数
27
Pub 分数
140

安装插件

flutter pub add ffmpeg_helper

插件介绍

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

ffmpeg_helper 是一个 Flutter 包,可简化在 Flutter 应用中使用 FFmpeg 命令的过程,提供易于使用的接口来执行 FFmpeg 操作。它内置了对 Windows 上设置 FFmpeg 的支持,使其可在 Android、iOS、macOS、Windows 和 Linux 等多个平台上使用。该包将复杂的命令行交互抽象为简单的 Dart 方法,使开发者能够以最少的努力完成视频转换、剪辑和合并等多媒体处理任务。非常适合需要在设备上进行媒体操作而无需依赖外部服务器的应用。

适合场景

  • 视频格式转换
  • 从视频中提取音频
  • 视频剪辑和合并
  • 设备端媒体处理
  • 跨平台多媒体应用

主要特点

  • 内置 Windows 设置支持
  • 平台无关的 FFmpeg 集成
  • 用于 FFmpeg 命令的简单 Dart API
  • 支持 Android、iOS、macOS、Windows 和 Linux
  • 轻松配置和执行

适合对象

  • 开发多媒体应用的开发者
  • 需要设备端视频编辑的应用程序
  • 跨平台媒体处理工具
  • 涉及 FFmpeg 的教育或原型项目
  • 希望快速集成FFmpeg的团队

使用建议

  • 目标设备上需要正确安装 FFmpeg
  • 由于包含 FFmpeg 二进制文件,可能会增加应用大小
  • Windows 设置需要额外的配置步骤
  • 除了基本用法外,文档有限
  • 对低端设备的潜在性能影响

原始 README

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

Buy Me A Coffee

ffmpeg_helper

FFmpeg commands helper for flutter with support for setup on windows platform. Create thumbnail and run ffprobe on all platforms except WEB. This uses ffmpeg_kit_flutter_min_gpl package for android/ios/macos Info was taken from ffmpeg_cli and recreated it as that project was stale.

// Initialize in main
  await FFMpegHelper.instance.initialize(); // This is a singleton instance
  // FFMpegHelper ffmpeg = FFMpegHelpe.instance; // use like this
  runApp(const MyApp());
// Command builder
// Use prebuilt args and filters or create custom ones
final FFMpegCommand cliCommand = FFMpegCommand(
  inputs: [
    FFMpegInput.asset(selectedFile!.path),
  ],
  args: [
    const LogLevelArgument(LogLevel.info),
    const OverwriteArgument(),
    const TrimArgument(
      start: Duration(seconds: 0),
      end: Duration(seconds: 10),
    ),
  ],
  filterGraph: FilterGraph(
    chains: [
      FilterChain(
        inputs: [],
        filters: [
          ScaleFilter(
            height: 300,
            width: -2,
          ),
        ],
        outputs: [],
      ),
    ],
  ),
  outputFilepath: path.join(appDocDir.path, "ffmpegtest.mp4"),
);
FFMpegHelperSession session = await ffmpeg.runAsync(
  cliCommand,
  statisticsCallback: (Statistics statistics) {
    print('bitrate: ${statistics.getBitrate()}');
  },
);

Thumbnail creator

// use ffmpeg.getThumbnailFileAsync() to get session
Future<FFMpegHelperSession> getThumbnailFileAsync({
  required String videoPath,
  required Duration fromDuration,
  required String outputPath,
  String? ffmpegPath,
  FilterGraph? filterGraph,
  int qualityPercentage = 100,
  Function(Statistics statistics)? statisticsCallback,
  Function(File? outputFile)? onComplete,
  FFMpegConfigurator? ffMpegConfigurator,
})
// use ffmpeg.getThumbnailFileSync() to get thumbnail file
Future<File?> getThumbnailFileSync({
  required String videoPath,
  required Duration fromDuration,
  required String outputPath,
  String? ffmpegPath,
  FilterGraph? filterGraph,
  int qualityPercentage = 100,
  Function(Statistics statistics)? statisticsCallback,
  Function(File? outputFile)? onComplete,
  FFMpegConfigurator? ffMpegConfigurator,
})

Run FFMpeg and get session so that user can cancel it later.

Future<FFMpegHelperSession> runAsync(
  FFMpegCommand command, {
  Function(Statistics statistics)? statisticsCallback,
  Function(File? outputFile)? onComplete,
  Function(Log)? logCallback,
})

Run FFMpeg as future.

Future<File?> runSync(
  FFMpegCommand command, {
  Function(Statistics statistics)? statisticsCallback,
})

Run ffprobe

Future<MediaInformation?> runProbe(String filePath)

Setup FFMPEG for Linux

sudo apt-get install ffmpeg
OR
sudo snap install ffmpeg
depends on linux distro

Setup FFMPEG for windows

Future<void> downloadFFMpeg() async {
    if (Platform.isWindows) {
      bool success = await ffmpeg.setupFFMpegOnWindows(
        onProgress: (FFMpegProgress progress) {
          downloadProgress.value = progress;
        },
      );
      setState(() {
        ffmpegPresent = success;
      });
    } else if (Platform.isLinux) {
      // show dialog box
      await Dialogs.materialDialog(
          color: Colors.white,
          msg:
              'FFmpeg installation required by user.\nsudo apt-get install ffmpeg\nsudo snap install ffmpeg',
          title: 'Install FFMpeg',
          context: context,
          actions: [
            IconsButton(
              onPressed: () {
                Navigator.of(context).pop();
              },
              text: 'Ok',
              iconData: Icons.done,
              color: Colors.blue,
              textStyle: const TextStyle(color: Colors.white),
              iconColor: Colors.white,
            ),
          ]);
    }
  }
// check setup progress on windows
// On windows if ffmpeg is not present it will download official zip file and extract on doc directory of app.
SizedBox(
  width: 300,
  child: ValueListenableBuilder(
    valueListenable: downloadProgress,
    builder: (BuildContext context, FFMpegProgress value, _) {
      //print(value.downloaded / value.fileSize);
      double? prog;
      if ((value.downloaded != 0) && (value.fileSize != 0)) {
        prog = value.downloaded / value.fileSize;
      } else {
        prog = 0;
      }
      if (value.phase == FFMpegProgressPhase.decompressing) {
        prog = null;
      }
      if (value.phase == FFMpegProgressPhase.inactive) {
        return const SizedBox.shrink();
      }
      return Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Text(value.phase.name),
          const SizedBox(height: 5),
          LinearProgressIndicator(value: prog),
        ],
      );
    },
  ),
),

所属分类

依赖

依赖清单 7 项

源码仓库

使用此插件的项目

暂无相关数据。