| 183 | } |
| 184 | |
| 185 | bool FFmpegLibraryFunctions::loadFFmpegLibraryInPath(QString path, LibraryVersion &libraryVersion) |
| 186 | { |
| 187 | // We will load the following libraries (in this order): |
| 188 | // avutil, swresample, avcodec, avformat. |
| 189 | |
| 190 | if (!path.isEmpty()) |
| 191 | { |
| 192 | QDir givenPath(path); |
| 193 | if (!givenPath.exists()) |
| 194 | { |
| 195 | this->log("The given path is invalid"); |
| 196 | return false; |
| 197 | } |
| 198 | |
| 199 | // Get the absolute path |
| 200 | path = givenPath.absolutePath() + "/"; |
| 201 | this->log("Absolute path " + path); |
| 202 | } |
| 203 | |
| 204 | // The ffmpeg libraries are named using a major version number. E.g: avutil-55.dll on windows. |
| 205 | // On linux, the libraries may be named differently. On Ubuntu they are named |
| 206 | // libavutil-ffmpeg.so.55. On arch linux the name is libavutil.so.55. We will try to look for both |
| 207 | // namings. On MAC os (installed with homebrew), there is a link to the lib named |
| 208 | // libavutil.54.dylib. |
| 209 | unsigned nrNames = (is_Q_OS_LINUX) ? 2 : ((is_Q_OS_WIN) ? 1 : 1); |
| 210 | bool success = false; |
| 211 | for (unsigned i = 0; i < nrNames; i++) |
| 212 | { |
| 213 | this->unloadAllLibraries(); |
| 214 | |
| 215 | // This is how we the library name is constructed per platform |
| 216 | QString constructLibName; |
| 217 | if (is_Q_OS_WIN) |
| 218 | constructLibName = "%1-%2"; |
| 219 | if (is_Q_OS_LINUX && i == 0) |
| 220 | constructLibName = "lib%1-ffmpeg.so.%2"; |
| 221 | if (is_Q_OS_LINUX && i == 1) |
| 222 | constructLibName = "lib%1.so.%2"; |
| 223 | if (is_Q_OS_MAC) |
| 224 | constructLibName = "lib%1.%2.dylib"; |
| 225 | |
| 226 | auto loadLibrary = |
| 227 | [this, &constructLibName, &path](QLibrary &lib, QString libName, unsigned version) { |
| 228 | auto filename = constructLibName.arg(libName).arg(version); |
| 229 | lib.setFileName(path + filename); |
| 230 | auto success = lib.load(); |
| 231 | this->log("Loading library " + filename + (success ? " succeded" : " failed")); |
| 232 | return success; |
| 233 | }; |
| 234 | |
| 235 | if (!loadLibrary(this->libAvutil, "avutil", libraryVersion.avutil.major)) |
| 236 | continue; |
| 237 | if (!loadLibrary(this->libSwresample, "swresample", libraryVersion.swresample.major)) |
| 238 | continue; |
| 239 | if (!loadLibrary(this->libAvcodec, "avcodec", libraryVersion.avcodec.major)) |
| 240 | continue; |
| 241 | if (!loadLibrary(this->libAvformat, "avformat", libraryVersion.avformat.major)) |
| 242 | continue; |
nothing calls this directly
no test coverage detected