-
-
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. A single ffmpeg share library is included in sdk, and will be loaded at runtime(except iOS).
You can use the bundled libffmpeg if no special demand. To use system ffmpeg(4.0 or later) libraries or the ones in your app:
- 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 choose one of
- 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/filename. For exampleSetGlobalOption("avutil_lib", "/opt/lib/libavutil.so.56")
. Thekey
can also have no _lib suffix since 0.16.1. - call
SetGlobalOption(key, value)
once(usually before other mdk calls), wherekey
isavutil
,avcodec
,avformat
,avfilter
,swresample
andswscale
, value is corresponding module hande(fromdlopen()
,GetModuleHandle()
orLoadLibrary()
) of typevoid*
, or library path/filename(since 0.16.1). For exampleSetGlobalOption("avutil", (void*)avutil_handle)
. You may needRTLD_NOLOAD
for macOS 10.15+ and link your own ffmpeg libs.
- 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(since 0.12.0): in each dir load single ffmpeg library > ffmpeg module library, the closest and highest version(compared with build version, usually latest release) > no version. iterate dirs first.
For example, on windows, mdk will search avutil like this
- if build against ffmpeg 6.x headers:
ffmpeg-6.dll in mdk.dll dir
=>avutil-58.dll in mdk.dll dir
=>ffmpeg-7.dll in mdk.dll dir
=>avutil-59.dll in mdk.dll dir
=>ffmpeg-5.dll in mdk.dll dir
=>avutil-57.dll in mdk.dll dir
=>ffmpeg-4.dll in mdk.dll dir
=>avutil-56.dll in mdk.dll dir
=>ffmpeg.dll in mdk.dll dir
=>avutil.dll in mdk.dll dir
For apple platforms, FFmpeg.framework
will also be searched(after libffmpeg.*.dylib
and lib${avmodule}.*.dylib
on macOS).
Since macOS 10.15, dlopen is not allowed in app by default, so mdk has to (weak)link against ffmpeg and standard ffmpeg libraries. Make sure ffmpeg libs are in mdk's rpath list(@loader_path/Libraries, @loader_path, @executable_path/../Frameworks, /usr/local/lib) so they will be automatically loaded, or you can load manually
FFmpeg is embeded into mdk. You can bundle your own FFmpeg.framework
(add it in xcode as a dependency), then FFmpeg.framework
will be used