搜尋套件、儲存庫與 APP 分類

套件詳情v1.7.2

flutter_quick_video_encoder

使用硬體H.264編碼器將原始RGB影像編碼為MP4影片。也支援PCM音訊與M4A檔案。

AndroidiOSmacOS
近 30 天下載
1.2萬
喜歡數
28
Pub 分數
150

安裝套件

flutter pub add flutter_quick_video_encoder

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,可在 Android、iOS 和 macOS 上使用硬體 H.264 編碼器,高效地將原始 RGB 幀編碼為 MP4 影片。它支援 PCM 音訊輸入,以建立 M4A 音訊軌道,非常適合即時影片錄製與處理。此套件利用原生平台功能,以極低的 CPU 使用率實現高效率。專為需要快速、低延遲影片編碼的多媒體應用程式開發者設計。

適用情境

  • 即時影片錄製
  • 直播流捕獲
  • 影片編輯工作流程
  • 設備端影片壓縮
  • 音視頻同步

主要特色

  • 硬體加速的 H.264 編碼
  • PCM 音頻支援
  • 跨平台相容性
  • 低CPU開銷
  • 用於幀輸入的簡單API

適合對象

  • 移動視頻應用
  • 基於相機的應用程式
  • 媒體處理工具
  • 嵌入式視頻系統
  • 高性能錄製

使用建議

  • 需要原生平台權限
  • 僅限RGB輸入格式
  • 編碼無軟體回退
  • 平台特定的設定需要
  • 音訊同步需要精確的定時

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

pub package

Logo

Quickly encode raw RGB images & PCM audio to MP4 video using the system h264 encoder

No Dependencies

FlutterQuickVideoEncoder has zero dependencies besides Flutter, Android, iOS, and MacOS themselves. No FFMPEG.

We use AVFoundation on iOS and MediaCodec on Android. These are native system libraries.

For encoding raw RGB pixels

Unlike the video_compress package, this package takes raw rgb pixel buffers as input, not video files.

⭐ Stars ⭐

Please star this repo & on pub.dev. We all benefit from having a larger community.

Usage

await FlutterQuickVideoEncoder.setup(
    width: 1920,
    height: 1080,
    fps: 60,
    videoBitrate: 2500000,
    audioChannels: 1,
    audioBitrate: 64000,
    sampleRate: 44100,
    filepath: "/documents/video.mp4", // output file
);
for(int i = 0; i < frameCount; i++) {
    Uint8List rgba = _renderVideoFrame(i);  // your video function
    Uint8List pcm = _renderAudioFrame(i); // your audio function
    await FlutterQuickVideoEncoder.appendVideoFrame(rgba); 
    await FlutterQuickVideoEncoder.appendAudioFrame(pcm);
}
await FlutterQuickVideoEncoder.finish();

Example App

Enable the platforms you need.

cd ./example                      
flutter config --enable-macos-desktop                                                      
flutter config --enable-android 
flutter config --enable-ios 
flutter create .
flutter run

Create video frames using ui.Image

The easiest way to render a video frame is to use Flutter!

For example, you can render an RGBA frame using ui.Image

Future<Uint8List> _generateVideoFrame(int frameIndex) async {
    const int boxSize = 50; // Size of the moving box

    // Calculate the box position
    int boxX = (frameIndex * 5) % width;
    int boxY = (frameIndex * 5) % height;

    // Paint the moving box
    final recorder = ui.PictureRecorder();
    final canvas = Canvas(recorder);
    final paint = Paint();

    // Draw a white background
    paint.color = Colors.white;
    canvas.drawRect(Rect.fromLTWH(0, 0, width.toDouble(), height.toDouble()), paint);

    // Draw the blue box
    paint.color = Colors.blue;
    canvas.drawRect(Rect.fromLTWH(boxX.toDouble(), boxY.toDouble(), boxSize.toDouble(), boxSize.toDouble()), paint);

    // Convert canvas to image
    final picture = recorder.endRecording();
    final img = await picture.toImage(width, height);

    // Convert the image to a byte array
    final byteData = await img.toByteData(format: ui.ImageByteFormat.rawRgba);
    return byteData!.buffer.asUint8List();
}

Create video frames from Widgets

You can also create video frames from widgets, using RenderRepaintBoundary

import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'dart:typed_data';

class MyWidget extends StatefulWidget {
  @override
  _MyWidgetState createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  GlobalKey repaintBoundaryKey = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return RepaintBoundary(
      key: repaintBoundaryKey,
      child: YourWidget(), // Replace with your actual widget
    );
  }

  // you would then call appendVideoFrame with this data
  Future<Uint8List?> captureWidgetAsRGBA() async {
    try {
      RenderRepaintBoundary boundary = repaintBoundaryKey.currentContext!.findRenderObject() as RenderRepaintBoundary;
      ui.Image image = await boundary.toImage(pixelRatio: 1.0);
      ByteData? byteData = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
      return byteData?.buffer.asUint8List();
    } catch (e) {
      print(e);
      return null;
    }
  }
}

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。