-
Notifications
You must be signed in to change notification settings - Fork 2.3k
How to Decrease Binary Size
The size of FFmpegKit binaries is determined by the following two factors:
- External libraries enabled
- FFmpeg components enabled
FFmpegKit already defines eight packages with different external libraries enabled.
You can use a similar approach and create your own package by enabling only external libraries you need.
If you don't enable any of them, your package will have the minimum size, just as the current min package published.
Sometimes, not enabling unused external libraries is not enough, and you may want to decrease binary size further.
You can achieve that by modifying FFmpeg components enabled.
Three files, ffmpeg.sh for Android, ffmpeg.sh for Linux and
ffmpeg.sh for Apple platforms,
under the scripts folder defines which FFmpeg components are enabled for each platform respectively.
Current versions of these scripts do not modify default components and only disable features/devices not available on
specified platforms.
configure line located in the lower part of these files is responsible for enabling/disabling FFmpeg components.
./configure \
--cross-prefix="${HOST}-" \
--sysroot="${ANDROID_SYSROOT}" \
--prefix="${FFMPEG_LIBRARY_PATH}" \
--pkg-config="${HOST_PKG_CONFIG_PATH}" \
--enable-version3 \
--arch="${TARGET_ARCH}" \
...
Enabling/disabling a component can be done by appending options to configure line. Options starting with --enable- prefix are used to enable a component and options starting with --disable- prefix are used to disable it.
In order to scripts the smallest possible binary, you need to disable all FFmpeg components and enable only required ones.
For example, if you are using FFmpegKit to read JPEG files and create an mpeg4 video, you can use the following
options to disable all FFmpeg components and enable only necessary ones (scale, null and format filters are added for format conversion).
--disable-everything \
--enable-decoder=bmp,jpeg2000,jpegls,mjpeg,mjpegb,smvjpeg \
--enable-demuxer=bmp,jpeg2000,jpegls,mjpeg,mjpegb,smvjpeg,image2 \
--enable-muxer=mp4 \
--enable-protocol=file \
--enable-encoder=mpeg4 \
--enable-filter=scale,null,format \
Hybrid plugins of FFmpegKit use the binaries of native FFmpegKit platform (Android, iOS, macOS) releases. To decrease their size, the size of the native FFmpegKit binary they depend on must be decreased.
-
Top level build scripts we have for native
FFmpegKitplatforms (android.sh,ios.sh,macos.sh,tvos.sh) must be used to build a custom nativeFFmpegKitbinary.Building section of the wiki explains how to use those scripts and the first part of this page shows how unused
ffmpegcomponents can be disabled. -
After that, the hybrid plugin must be cloned and the dependencies inside the platform specific build files (
build.gradle,Podfile) of the hybrid plugin must be modified. Public nativeFFmpegKitdependency must be replaced with the customFFmpegKitlibrary built locally.
Copyright (c) 2021-2025 FFmpegKit
- Status
- Versions
- Changelog
- Project Layout
- API
- Using
- Building
- External Libraries
- Patents
- License