-
-
Notifications
You must be signed in to change notification settings - Fork 32
FFmpeg Runtime
FFmpeg is heavily used in some mdk modules, for example demuxer, muxer and software decoder. mdk main library does not depends on ffmpeg, and all modules can be implemented by platform dependent APIs. Previously, ffmpeg(LGPL) static libraries are linked into mdk-avglue plugin. Since v0.4.0, ffmpeg is loaded dynamically by default(except iOS), and avglue module is merged into main library(default). There are some benefits:
- Reduce the whole size. If FFmpeg exists in system, for example linux distributions, or already used somewhere else in your app, then the existing ffmpeg runtime can be reused. The size of app can be decreased considerably, from 5M to 40M.
- SDK can be used on more platforms. Linux library versioning and symbol versioning are not friendly to developers to make softwares compatible on different distributions. FFmpeg hardware accelerated codec VA-API depends on libva, whose major version changed before. On ubuntu 16.04 LTS, it's libva.so.1, but on 18.04 LTS, it becomes libva.so.2. So to support both OSes, there must be 2 mdk-avglue binaries. If ffmpeg is loaded at runtime, user can decide to build ffmpeg against each OS.
Since v0.4.0, a single ffmpeg share library is included in sdk, and will be loaded at runtime. You can use this if no special demand. MDK is compatible with ffmpeg 4.0 or later. To use system ffmpeg libraries, or the ones in your app, you can
- delete ffmpeg runtime in sdk
- If existing ffmpeg libraries are in library loading search dirs, and their names are standard, then they will be loaded automatically.
- Otherwise, you can
- set environment vars
AVUTIL_LIB
,AVCODEC_LIB
,AVFORMAT_LIB
,AVFILTER_LIB
,SWRESAMPLE_LIB
andSWSCALE_LIB
with ffmpeg module path. - call
SetGlobalOption(key, value)
once(usually before other mdk calls), wherekey
isavutil_lib
,avcodec_lib
,avformat_lib
,avfilter_lib
,swresample_lib
andswscale_lib
, value is corresponding path. For example `SetGlobalOption("avutil_lib", "/opt/lib/libavutil.so.56")
- set environment vars
Once ffmpeg is loaded, SetGlobalOption(key, value)
can be called again if you need.
If ffmpeg any module is not set manually by environment vars or SetGlobalOption(key, value)
, it's searched in the following order
dir: current mdk module dir > mdk framework dir(apple) > system default search dir file name: single ffmpeg library > ffmpeg modules w/ version > ffmpeg modules w/o version(last)
For example, on windows, mdk will search avutil like this: ffmpeg.dll in mdk.dll dir=>avutil-56.dll in mdk.dll dir=>ffmpeg.dll in %PATH%=>avutil-56.dll in %PATH%=>avutil.dll in mdk.dll dir=> avutil.dll in %PATH%
If sandbox is enabled in your app, libffmpeg.dylib or ffmpeg dylibs MUST be moved to mdk.framework/Versions/Current/