Skip to content

Commit

Permalink
Deploy FFmpeg dlls with windeployqt
Browse files Browse the repository at this point in the history
When we add support for dynamically linked FFmpeg, some FFmpeg libraries
will be available in the bin directory. windeployqt should then copy
these libraries to the application directory if the ffmpeg media backend
is included.

This patch extends windeployqt with support for deploying these FFmpeg
libraries.

Potential issues:

1. This patch hard codes the FFmpeg library names that we currently
   depend on, such as 'avcodec' or 'swresample'.
2. We don't take version number of the FFmpeg libs into account. This is
   done to reduce the maintenance burden when we upgrade FFmpeg, and
   should not be a problem as long as we have a single version of FFmpeg
   in the online installer.
3. Finding the library names is a bit quadratic in complexity, bound by
   the number of libraries in the bin folder, but should not be too
   slow.
4. We need to update windeployqt if we add or remove ffmpeg libraries.

An alternative would be to identify all dlls that the ffmpeg media
plugin depends on, and then deploy all files that exists in the bin
directory instead of hard-coding library names. This would, however be a
bit more fragile because we would not be able to warn if a library was
missing.

Note that this patch is a workaround. It is needed because Qt does not
properly support CMake's runtime dependency features with platform
plugins. Even if we added FFmpeg binaries to the dependencies set, they
would not be visible at install time.

Pick-to: 6.5
Change-Id: I4b23e50429d16e8487bf43ce9982ff37d02ffbe2
Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
(cherry picked from commit 138eebc)
(cherry picked from commit e2fbb43)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
  • Loading branch information
jogerh authored and Qt Cherry-pick Bot committed Feb 2, 2024
1 parent 6c1e0b5 commit 256bb59
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/tools/windeployqt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ struct Options {
bool systemD3dCompiler = true;
bool compilerRunTime = false;
bool softwareRasterizer = true;
bool ffmpeg = true;
PluginLists pluginSelections;
Platform platform = WindowsDesktopMsvc;
ModuleBitset additionalLibraries;
Expand Down Expand Up @@ -466,6 +467,11 @@ static inline int parseArguments(const QStringList &arguments, QCommandLineParse
QStringLiteral("Do not deploy the software rasterizer library."));
parser->addOption(suppressSoftwareRasterizerOption);

QCommandLineOption noFFmpegOption(QStringLiteral("no-ffmpeg"),
QStringLiteral("Do not deploy the ffmpeg libraries."));
parser->addOption(noFFmpegOption);


QCommandLineOption listOption(QStringLiteral("list"),
"Print only the names of the files copied.\n"
"Available options:\n"
Expand Down Expand Up @@ -583,6 +589,9 @@ static inline int parseArguments(const QStringList &arguments, QCommandLineParse
if (parser->isSet(suppressSoftwareRasterizerOption))
options->softwareRasterizer = false;

if (parser->isSet(noFFmpegOption))
options->ffmpeg = false;

if (parser->isSet(forceOption))
options->updateFileFlags |= ForceUpdateFile;
if (parser->isSet(dryRunOption)) {
Expand Down Expand Up @@ -1135,6 +1144,33 @@ static bool deployTranslations(const QString &sourcePath, const ModuleBitset &us
return true;
}

static QStringList findFFmpegLibs(const QString &qtBinDir, Platform platform)
{
const std::vector<QLatin1StringView> ffmpegHints = { "avcodec"_L1, "avformat"_L1, "avutil"_L1,
"swresample"_L1, "swscale"_L1 };
const QStringList bundledLibs =
findSharedLibraries(qtBinDir, platform, MatchDebugOrRelease, {});

QStringList ffmpegLibs;
for (const QLatin1StringView &libHint : ffmpegHints) {
const QStringList ffmpegLib = bundledLibs.filter(libHint, Qt::CaseInsensitive);

if (ffmpegLib.empty()) {
std::wcerr << "Warning: Cannot find FFmpeg libraries. Multimedia features will not work as expected.\n";
return {};
} else if (ffmpegLib.size() != 1u) {
std::wcerr << "Warning: Multiple versions of FFmpeg libraries found. Multimedia features will not work as expected.\n";
return {};
}

const QChar slash(u'/');
QFileInfo ffmpegLibPath{ qtBinDir + slash + ffmpegLib.front() };
ffmpegLibs.append(ffmpegLibPath.absoluteFilePath());
}

return ffmpegLibs;
}

struct DeployResult
{
operator bool() const { return success; }
Expand Down Expand Up @@ -1560,6 +1596,12 @@ static DeployResult deploy(const Options &options, const QMap<QString, QString>
}
} // Windows

// Add ffmpeg if we deploy the ffmpeg backend
if (options.ffmpeg
&& !plugins.filter(QStringLiteral("ffmpegmediaplugin"), Qt::CaseInsensitive).empty()) {
deployedQtLibraries.append(findFFmpegLibs(qtBinDir, options.platform));
}

// Update libraries
if (options.libraries) {
const QString targetPath = options.libraryDirectory.isEmpty() ?
Expand Down

0 comments on commit 256bb59

Please sign in to comment.