OSDN Git Service

Added support for presets to NVEncC.
[x264-launcher/x264-launcher.git] / src / encoder_nvencc.cpp
index 0aa4628..06bbb2c 100644 (file)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 // Simple x264 Launcher
-// Copyright (C) 2004-2019 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2020 LoRd_MuldeR <MuldeR2@GMX.de>
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -40,7 +40,7 @@
 #include <QPair>
 
 //x265 version info
-static const unsigned int VERSION_NVENCC_MINIMUM_VER = 436;
+static const unsigned int VERSION_NVENCC_MINIMUM_VER = 449;
 
 // ------------------------------------------------------------
 // Helper Macros
@@ -48,6 +48,26 @@ static const unsigned int VERSION_NVENCC_MINIMUM_VER = 436;
 
 #define NVENCC_UPDATE_PROGRESS(X) do \
 { \
+       bool ok[2] = { false, false }; \
+       unsigned int progressInt = (X)->cap(1).toUInt(&ok[0]); \
+       unsigned int progressFrc = (X)->cap(2).toUInt(&ok[1]); \
+       setStatus(JobStatus_Running); \
+       if(ok[0] && ok[1]) \
+       { \
+               const double progress = (double(progressInt) / 100.0) + (double(progressFrc) / 1000.0); \
+               if(!qFuzzyCompare(progress, last_progress)) \
+               { \
+                       setProgress(floor(progress * 100.0)); \
+                       size_estimate = qFuzzyIsNull(size_estimate) ? estimateSize(m_outputFile, progress) : ((0.667 * size_estimate) + (0.333 * estimateSize(m_outputFile, progress))); \
+                       last_progress = progress; \
+               } \
+       } \
+       setDetails(line.mid(offset).trimmed()); \
+} \
+while(0)
+
+#define NVENCC_UPDATE_PROGRESS_OLD(X) do \
+{ \
        bool ok = false; \
        unsigned int progressFrames = (X)->cap(1).toUInt(&ok); \
        double progress = 0.0; \
@@ -124,7 +144,7 @@ public:
 
        virtual QStringList getPresets(void) const
        {
-               return QStringList();
+               return QStringList() << "performance" << "quality";
        }
 
        virtual QStringList getProfiles(const quint32 &variant) const
@@ -150,7 +170,9 @@ public:
        {
                switch(format)
                {
+               case MediaInfo::FILETYPE_AVISYNTH:
                case MediaInfo::FILETYPE_YUV4MPEG2:
+               case MediaInfo::FILETYPE_UNKNOWN:
                        return true;
                default:
                        return false;
@@ -159,11 +181,11 @@ public:
 
        virtual QString getBinaryPath(const SysinfoModel *sysinfo, const quint32 &encArch, const quint32 &encVariant) const
        {
-               QString arch;
+               QString arch, ext;
                switch(encArch)
                {
-                       case 0: arch = "x86"; break;
-                       case 1: arch = "x64"; break;
+                       case 0: arch = "x86";             break;
+                       case 1: arch = "x64"; ext = "64"; break;
                        default: MUTILS_THROW("Unknown encoder arch!");
                }
                switch(encVariant)
@@ -172,7 +194,7 @@ public:
                        case 1: break;
                        default: MUTILS_THROW("Unknown encoder variant!");
                }
-               return QString("%1/toolset/%2/nvencc/nvencc_%2.exe").arg(sysinfo->getAppPath(), arch);
+               return QString("%1/toolset/%2/nvencc/nvencc%3.exe").arg(sysinfo->getAppPath(), arch, ext);
        }
 
        virtual QStringList getDependencies(const SysinfoModel *sysinfo, const quint32 &encArch, const quint32 &encVariant) const
@@ -192,11 +214,11 @@ public:
 
                }
                return QStringList()
-               << QString("%1/toolset/%2/avcodec-57.dll"  ).arg(sysinfo->getAppPath(), arch)
-               << QString("%1/toolset/%2/avfilter-6.dll"  ).arg(sysinfo->getAppPath(), arch)
-               << QString("%1/toolset/%2/avformat-57.dll" ).arg(sysinfo->getAppPath(), arch)
-               << QString("%1/toolset/%2/avutil-55.dll"   ).arg(sysinfo->getAppPath(), arch)
-               << QString("%1/toolset/%2/swresample-2.dll").arg(sysinfo->getAppPath(), arch);
+               << QString("%1/toolset/%2/nvencc/avcodec-58.dll"  ).arg(sysinfo->getAppPath(), arch)
+               << QString("%1/toolset/%2/nvencc/avfilter-7.dll"  ).arg(sysinfo->getAppPath(), arch)
+               << QString("%1/toolset/%2/nvencc/avformat-58.dll" ).arg(sysinfo->getAppPath(), arch)
+               << QString("%1/toolset/%2/nvencc/avutil-56.dll"   ).arg(sysinfo->getAppPath(), arch)
+               << QString("%1/toolset/%2/nvencc/swresample-3.dll").arg(sysinfo->getAppPath(), arch);
        }
 
        virtual QString getHelpCommand(void) const
@@ -319,6 +341,15 @@ void NVEncEncoder::buildCommandLine(QStringList &cmdLine, const bool &usePipe, c
                MUTILS_THROW("Bad encoder variant !!!");
        }
 
+       const QString preset = m_options->preset().simplified().toLower();
+       if(!preset.isEmpty())
+       {
+               if(preset.compare(QString::fromLatin1(OptionsModel::SETTING_UNSPECIFIED), Qt::CaseInsensitive) != 0)
+               {
+                       cmdLine << "--preset" << preset;
+               }
+       }
+
        switch(m_options->rcMode())
        {
        case 0:
@@ -377,7 +408,8 @@ void NVEncEncoder::buildCommandLine(QStringList &cmdLine, const bool &usePipe, c
 
 void NVEncEncoder::runEncodingPass_init(QList<QRegExp*> &patterns)
 {
-       patterns << new QRegExp("^(\\d+) frames:");
+       patterns << new QRegExp("\\[(\\d+)\\.(\\d+)%\\].+frames", Qt::CaseInsensitive);
+       patterns << new QRegExp("^(\\d+) frames:", Qt::CaseInsensitive);
        patterns << new QRegExp("Selected\\s+codec\\s+is\\s+not\\s+supported", Qt::CaseInsensitive);
        patterns << new QRegExp("nvEncodeAPI.dll\\s+does\\s+not\\s+exists\\s+in\\s+your\\s+system", Qt::CaseInsensitive);
 }
@@ -391,10 +423,14 @@ void NVEncEncoder::runEncodingPass_parseLine(const QString &line, const QList<QR
        }
        else if ((offset = patterns[1]->lastIndexIn(line)) >= 0)
        {
-               log(QString("ERROR: YOUR HARDWARE DOES *NOT* SUPPORT THE '%1' CODEC !!!\n").arg(s_nvencEncoderInfo.variantToString(m_options->encVariant())));
+               NVENCC_UPDATE_PROGRESS_OLD(patterns[1]);
        }
        else if ((offset = patterns[2]->lastIndexIn(line)) >= 0)
        {
+               log(QString("ERROR: YOUR HARDWARE DOES *NOT* SUPPORT THE '%1' CODEC !!!\n").arg(s_nvencEncoderInfo.variantToString(m_options->encVariant())));
+       }
+       else if ((offset = patterns[3]->lastIndexIn(line)) >= 0)
+       {
                log("ERROR: NVIDIA ENCODER API (NVENCODEAPI.DLL) IS *NOT* AVAILABLE !!!\n");
        }
        else if(!line.isEmpty())