搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。