Skip to content

FFmpeg Runtime

WangBin edited this page Sep 6, 2019 · 25 revisions

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, and avglue module is merged into main library(default). There are some benefits:

  1. 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.
  2. 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.

Select FFmpeg runtime

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, they will be loaded automatically.
  • Otherwise, you can
    • set environment vars AVUTIL_LIB, AVCODEC_LIB, AVFORMAT_LIB, AVFILTER_LIB, SWRESAMPLE_LIB and SWSCALE_LIB with ffmpeg module path.
    • call SetGlobalOption(key, value) once(usually before other mdk calls), where key is avutil_lib, avcodec_lib, avformat_lib, avfilter_lib, swresample_lib and swscale_lib, value is corresponding path.

Once ffmpeg is loaded, SetGlobalOption(key, value) can be called again if you need.

Build FFmpeg

https://github.com/wang-bin/avbuild

Clone this wiki locally