# arthenica/ffmpeg-kit architecture

> Architecture diagram of the GitHub repository arthenica/ffmpeg-kit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arthenica/ffmpeg-kit
- Repository: https://github.com/arthenica/ffmpeg-kit

## Overview

##### Main Components
- Core FFmpeg Library Integration: At the heart, there is the FFmpeg code that is “wrapped”. The build scripts and native source code (in directories such as “android”, “apple”, “linux”, etc.) integrate FFmpeg (built using scripts, Doxyfiles, Makefiles, Gradle build scripts, etc.) with additional custom functionality.
- Platform-Specific Wrapper Modules:
– Android: Contains Java (and native C/C++ code under “android/ffmpeg-kit-android-lib”), Gradle configuration, and shell scripts (android.sh) for building.
– Apple (iOS, macOS, tvOS): Contains Objective-C source files in the “apple” directory, Makefile.am, Doxyfile and build scripts (ios.sh, macos.sh, tvos.sh).
– Linux: Contains C/C++ code (in “linux/src”) along with its build scripts, Makefiles, and configuration files.
- Hybrid/Binding Layers:
– Flutter: Under the “flutter” directory, with Dart code implementing the wrapper API and corresponding platform-specific interfaces.
– React Native: Contains the JavaScript (and TypeScript definition) layer plus native modules for Android and iOS (inside “react-native”).
– Flutter Platform Interface: Serves as an abstraction so that the Flutter API works across different platforms.
- Build & Automation Infrastructure:
– Build Scripts: Shell scripts (android.sh, ios.sh, linux.sh, macos.sh, tvos.sh) and additional scripts in “scripts” and “tools” to configure, patch, and produce final library artifacts.
– Continuous Integration: The “.github/workflows” for automated builds and tests.
- Documentation & Test Applications:
– Extensive documentation is contained in “docs” (both Doxygen-based HTML docs and Wiki links in README) and references to test applications in the separate FFmpegKit Test project.

##### Relationships and Data Flow
- The build system (scripts and tools) uses configuration files and patches from the “tools” and “scripts” directories to compile FFmpeg into platform-specific native libraries.
- Each platform directory (android, apple, linux, etc.) further wraps that native functionality in a native API (Java for Android, Objective-C for Apple, C++ for Linux).
- Higher-level binding modules (Flutter, React Native) then call these native APIs using their respective language bridges (Dart plugins, JavaScript bridged modules).
- At runtime, the higher-level APIs pass commands (FFmpeg/FFprobe command strings and options) down through the wrapper layers to invoke the actual FFmpeg commands.
- Prebuilt packages and binary distributions (available from Maven Central, CocoaPods, pub, and npm) represent these final build artifacts.

##### Architectural Patterns and Design Principles
- Layered / Modular Architecture: Separation between the build/integration layer, the native platform wrappers, and the hybrid API layers ensures each platform is independently maintained.
- Cross-Platform Abstraction: The same wrapper library (FFmpegKit) is implemented in multiple languages and adapted using proper platform-specific conventions.
- Reusability and Extensibility: The design exposes clear extension points (via the API wrappers and build scripts) for enabling/disabling external libraries or optional libraries.
- CI/CD Integration: Automated workflows (GitHub Actions) ensure that each platform’s build script and packaging process is validated regularly.

##### Relevant Technologies and Frameworks
- FFmpeg (core multimedia engine)
- Native languages:
– C/C++ (for building FFmpeg and native interfaces)
– Java (Android wrapper)
– Objective-C (Apple platforms)
– Dart (Flutter)
– JavaScript/TypeScript (React Native)
- Build and Packaging: Gradle, Make, Xcode projects, CocoaPods, XCFramework format, and shell scripting.
- CI Tools: GitHub workflows for mobile and linux builds.

##### Elements
- A separate section or note reflecting the multiple distribution channels (GitHub releases, Maven Central, CocoaPods, pub, npm).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Build & Integration Layer"
        BA("Build Scripts & Tools"):::build
        BA1("Shell Scripts & Build Tools"):::build
        BA2("CI/CD Workflows"):::build
    end

    subgraph "Native Wrappers"
        A("Android Wrapper"):::native
        AP("Apple Wrapper"):::native
        L("Linux Wrapper"):::native
        FCI("Core FFmpeg Integration"):::core
    end

    subgraph "Hybrid Bindings"
        F("Flutter Binding"):::hybrid
        RN("React Native Binding"):::hybrid
    end

    subgraph "Documentation & Packaging"
        DOC("Documentation & README"):::docs
    end

    %% Build & Integration relationships
    BA --> BA1
    BA --> BA2
    BA1 --> A
    BA1 --> AP
    BA1 --> L

    %% Native Wrappers use Core FFmpeg Integration
    A --> FCI
    AP --> FCI
    L --> FCI

    %% Hybrid Bindings call Native Wrappers
    F --> A
    F --> AP
    RN --> A
    RN --> AP

    %% Documentation links to build process
    DOC -.-> BA

    %% Click Events for Core FFmpeg Integration
    click FCI "https://github.com/arthenica/ffmpeg-kit/tree/main/linux/src"
    click FCI "https://github.com/arthenica/ffmpeg-kit/tree/main/android/ffmpeg-kit-android-lib/src/main/cpp"
    click FCI "https://github.com/arthenica/ffmpeg-kit/tree/main/apple/src"

    %% Click Events for Platform-Specific Wrapper Modules
    click A "https://github.com/arthenica/ffmpeg-kit/tree/main/android"
    click A "https://github.com/arthenica/ffmpeg-kit/tree/main/android/ffmpeg-kit-android-lib"
    click AP "https://github.com/arthenica/ffmpeg-kit/tree/main/apple"
    click L "https://github.com/arthenica/ffmpeg-kit/tree/main/linux"

    %% Click Events for Hybrid/Binding Layers
    click F "https://github.com/arthenica/ffmpeg-kit/tree/main/flutter/flutter"
    click F "https://github.com/arthenica/ffmpeg-kit/tree/main/flutter/flutter_platform_interface"
    click RN "https://github.com/arthenica/ffmpeg-kit/tree/main/react-native"

    %% Click Events for Build & Automation Infrastructure
    click BA1 "https://github.com/arthenica/ffmpeg-kit/tree/main/scripts/"
    click BA1 "https://github.com/arthenica/ffmpeg-kit/tree/main/tools/"
    click BA2 "https://github.com/arthenica/ffmpeg-kit/tree/main/.github/workflows"

    %% Click Events for Documentation & Test Applications
    click DOC "https://github.com/arthenica/ffmpeg-kit/tree/main/docs/"
    click DOC "https://github.com/arthenica/ffmpeg-kit/blob/main/README.md"

    %% Styles for layers with colours
    classDef build fill:#ffe6e6,stroke:#cc0000,stroke-width:2px;
    classDef native fill:#e6f2ff,stroke:#004d99,stroke-width:2px;
    classDef hybrid fill:#e6ffe6,stroke:#008000,stroke-width:2px;
    classDef docs fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef core fill:#fff0e6,stroke:#cc6600,stroke-width:2px;
```
