From 2c3d3bf045d2d98bc0d9ee46adda5bcf562c4979 Mon Sep 17 00:00:00 2001 From: manongjohn Date: Sat, 13 Mar 2021 18:39:35 -0500 Subject: [PATCH] Update autoset ffmpeg path --- toonz/sources/image/ffmpeg/tiio_ffmpeg.cpp | 101 +++++++++------------ 1 file changed, 45 insertions(+), 56 deletions(-) diff --git a/toonz/sources/image/ffmpeg/tiio_ffmpeg.cpp b/toonz/sources/image/ffmpeg/tiio_ffmpeg.cpp index 78adb79d..2fcf4361 100644 --- a/toonz/sources/image/ffmpeg/tiio_ffmpeg.cpp +++ b/toonz/sources/image/ffmpeg/tiio_ffmpeg.cpp @@ -21,87 +21,76 @@ Ffmpeg::Ffmpeg() { Ffmpeg::~Ffmpeg() {} bool Ffmpeg::checkFfmpeg() { - // check the user defined path in preferences first - QString path = Preferences::instance()->getFfmpegPath() + "/ffmpeg"; + QString exe = "ffmpeg"; #if defined(_WIN32) - path = path + ".exe"; + exe = exe + ".exe"; #endif + + // check the user defined path in preferences first + QString path = Preferences::instance()->getFfmpegPath() + "/" + exe; if (TSystem::doesExistFileOrLevel(TFilePath(path))) return true; - // check the Tahoma root directory next - path = QDir::currentPath() + "/ffmpeg"; -#if defined(_WIN32) - path = path + ".exe"; -#endif - if (TSystem::doesExistFileOrLevel(TFilePath(path))) { - Preferences::instance()->setValue(ffmpegPath, QDir::currentPath()); - return true; - } + // Let's try and autodetect the exe included with release + QStringList folderList; + + folderList.append("."); + folderList.append("./ffmpeg"); // ffmpeg folder #ifdef MACOSX - path = QDir::currentPath() + "/" + - QString::fromStdString(TEnv::getApplicationFileName()) + - ".app/ffmpeg/ffmpeg"; - if (TSystem::doesExistFileOrLevel(TFilePath(path))) { - Preferences::instance()->setValue( - ffmpegPath, QDir::currentPath() + "/" + - QString::fromStdString(TEnv::getApplicationFileName()) + - ".app/ffmpeg/"); - return true; - } + // Look inside app + folderList.append("./" + + QString::fromStdString(TEnv::getApplicationFileName()) + + ".app/ffmpeg"); // ffmpeg folder +#elif defined LINUX + // Need to account for symbolic links + folderList.append(TEnv::getWorkingDirectory().getQString() + + "/ffmpeg"); // ffmpeg folder #endif -#ifdef LINUX - QString currentPath = TEnv::getWorkingDirectory().getQString(); - path = currentPath + "/ffmpeg/ffmpeg"; - if (TSystem::doesExistFileOrLevel(TFilePath(path))) { - Preferences::instance()->setValue(ffmpegPath, currentPath + "/ffmpeg/"); + QString exePath = TSystem::findFileLocation(folderList, exe); + + if (!exePath.isEmpty()) { + Preferences::instance()->setValue(ffmpegPath, exePath); return true; } -#endif + // give up return false; } bool Ffmpeg::checkFfprobe() { - // check the user defined path in preferences first - QString path = Preferences::instance()->getFfmpegPath() + "/ffprobe"; + QString exe = "ffprobe"; #if defined(_WIN32) - path = path + ".exe"; + exe = exe + ".exe"; #endif + + // check the user defined path in preferences first + QString path = Preferences::instance()->getFfmpegPath() + "/" + exe; if (TSystem::doesExistFileOrLevel(TFilePath(path))) return true; - // check the Tahoma root directory next - path = QDir::currentPath() + "/ffprobe"; -#if defined(_WIN32) - path = path + ".exe"; -#endif - if (TSystem::doesExistFileOrLevel(TFilePath(path))) { - Preferences::instance()->setValue(ffmpegPath, QDir::currentPath()); - return true; - } + // Let's try and autodetect the exe included with release + QStringList folderList; + + folderList.append("."); + folderList.append("./ffmpeg"); // ffmpeg folder #ifdef MACOSX - path = QDir::currentPath() + "/" + - QString::fromStdString(TEnv::getApplicationFileName()) + - ".app/ffmpeg/ffprobe"; - if (TSystem::doesExistFileOrLevel(TFilePath(path))) { - Preferences::instance()->setValue( - ffmpegPath, QDir::currentPath() + "/" + - QString::fromStdString(TEnv::getApplicationFileName()) + - ".app/ffmpeg/"); - return true; - } + // Look inside app + folderList.append("./" + + QString::fromStdString(TEnv::getApplicationFileName()) + + ".app/ffmpeg"); // ffmpeg folder +#elif defined LINUX + // Need to account for symbolic links + folderList.append(TEnv::getWorkingDirectory().getQString() + + "/ffmpeg"); // ffmpeg folder #endif -#ifdef LINUX - QString currentPath = TEnv::getWorkingDirectory().getQString(); - path = currentPath + "/ffmpeg/ffprobe"; - if (TSystem::doesExistFileOrLevel(TFilePath(path))) { - Preferences::instance()->setValue(ffmpegPath, currentPath + "/ffmpeg/"); + QString exePath = TSystem::findFileLocation(folderList, exe); + + if (!exePath.isEmpty()) { + Preferences::instance()->setValue(ffmpegPath, exePath); return true; } -#endif // give up return false;