How arthenica/ffmpeg-kit works
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).