FFmpeg Runtime - wang-bin/mdk-sdk GitHub Wiki
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).
Select FFmpeg Runtime
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
LIBFFMPEG
,LIBAVUTIL
,LIBAVCODEC
,LIBAVFORMAT
,LIBAVFILTER
,LIBSWRESAMPLE
andLIBSWSCALE
with ffmpeg module path, var name withoutLIB
prefix is ok, e.g.AVUTIL
.LIBFFMPEG
orFFMPEG
tried last. - call
SetGlobalOption(key, value)
once(usually before other mdk calls), wherekey
isffmpeg
,avutil
,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.key
can also havelib
prefix, e.g.libavutil
. Ifffmpeg
orlibffmpeg
is set, all ffmpeg modules will be reloaded with the value.
- set environment vars
Once ffmpeg is loaded, SetGlobalOption(key, value)
can be called again if you need.
Runtime Lookup
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).
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
iOS, tvOS, visionOS
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