OSDN Git Service

Bump version.
[x264-launcher/x264-launcher.git] / src / encoder_x265.cpp
index f960b54..3bd209d 100644 (file)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 // Simple x264 Launcher
-// Copyright (C) 2004-2016 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2018 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
@@ -30,6 +30,7 @@
 #include "model_clipInfo.h"
 
 //MUtils
+#include <MUtils/Global.h>
 #include <MUtils/Exception.h>
 
 //Qt
@@ -39,8 +40,8 @@
 #include <QPair>
 
 //x265 version info
-static const unsigned int VERSION_X265_MINIMUM_VER =  19;
-static const unsigned int VERSION_X265_MINIMUM_REV = 140;
+static const unsigned int VERSION_X265_MINIMUM_VER = 29;
+static const unsigned int VERSION_X265_MINIMUM_REV =  1;
 
 // ------------------------------------------------------------
 // Helper Macros
@@ -159,21 +160,23 @@ public:
 
        virtual QString getBinaryPath(const SysinfoModel *sysinfo, const quint32 &encArch, const quint32 &encVariant) const
        {
-               QString arch, variant;
+               QString arch;
                switch(encArch)
                {
                        case 0: arch = "x86"; break;
                        case 1: arch = "x64"; break;
                        default: MUTILS_THROW("Unknown encoder arch!");
                }
-               switch(encVariant)
+               if((encVariant < 0) || (encVariant > 2))
                {
-                       case 0: variant =  "8bit"; break;
-                       case 1: variant = "10bit"; break;
-                       case 2: variant = "12bit"; break;
-                       default: MUTILS_THROW("Unknown encoder arch!");
+                       MUTILS_THROW("Unknown encoder variant!");
                }
-               return QString("%1/toolset/%2/x265_%3_%2.exe").arg(sysinfo->getAppPath(), arch, variant);
+               return QString("%1/toolset/%2/x265_%2.exe").arg(sysinfo->getAppPath(), arch);
+       }
+
+       virtual QString getHelpCommand(void) const
+       {
+               return "--fullhelp";
        }
 };
 
@@ -224,30 +227,23 @@ void X265Encoder::checkVersion_init(QList<QRegExp*> &patterns, QStringList &cmdL
        patterns << new QRegExp("\\bHEVC\\s+encoder\\s+version\\s+(\\d)\\.(\\d+)\\b", Qt::CaseInsensitive);
 }
 
-void X265Encoder::checkVersion_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &core, unsigned int &build, bool &modified)
+void X265Encoder::checkVersion_parseLine(const QString &line, const QList<QRegExp*> &patterns, unsigned int &core, unsigned int &build, bool &modified)
 {
        int offset = -1;
 
        if((offset = patterns[0]->lastIndexIn(line)) >= 0)
        {
-               bool ok[3] = { false, false, false };
                unsigned int temp[3];
-               temp[0] = patterns[0]->cap(1).toUInt(&ok[0]);
-               temp[1] = patterns[0]->cap(2).toUInt(&ok[1]);
-               temp[2] = patterns[0]->cap(3).toUInt(&ok[2]);
-               if(ok[0] && ok[1])
+               if(MUtils::regexp_parse_uint32(*patterns[0], temp, 3))
                {
-                       core = (10 * temp[0]) + temp[1];
+                       core  = (10 * temp[0]) + temp[1];
+                       build = temp[2];
                }
-               if(ok[2]) build = temp[2];
        }
        else if((offset = patterns[1]->lastIndexIn(line)) >= 0)
        {
-               bool ok[2] = { false, false };
                unsigned int temp[2];
-               temp[0] = patterns[1]->cap(1).toUInt(&ok[0]);
-               temp[1] = patterns[1]->cap(2).toUInt(&ok[1]);
-               if(ok[0] && ok[1])
+               if (MUtils::regexp_parse_uint32(*patterns[0], temp, 2))
                {
                        core = (10 * temp[0]) + temp[1];
                }
@@ -275,7 +271,7 @@ bool X265Encoder::isVersionSupported(const unsigned int &revision, const bool &m
 
        if((core < VERSION_X265_MINIMUM_VER) || ((core == VERSION_X265_MINIMUM_VER) && (build < VERSION_X265_MINIMUM_REV)))
        {
-               log(tr("\nERROR: Your version of x265 is too old! (Minimum required revision is 0.%1+%2)").arg(QString::number(VERSION_X265_MINIMUM_VER), QString::number(VERSION_X265_MINIMUM_REV)));
+               log(tr("\nERROR: Your version of x265 is too old! (Minimum required revision is %1.%2+%3)").arg(QString::number(VERSION_X265_MINIMUM_VER / 10), QString::number(VERSION_X265_MINIMUM_VER % 10), QString::number(VERSION_X265_MINIMUM_REV)));
                return false;
        }
        else if(core > VERSION_X265_MINIMUM_VER)
@@ -295,15 +291,31 @@ void X265Encoder::buildCommandLine(QStringList &cmdLine, const bool &usePipe, co
 {
        double crf_int = 0.0, crf_frc = 0.0;
 
-       switch(m_options->rcMode())
+       cmdLine << "-D";
+       switch (m_options->encVariant())
        {
        case 0:
-               cmdLine << "--qp" << QString::number(qRound(m_options->quantizer()));
+               cmdLine << QString::number(8);
                break;
        case 1:
+               cmdLine << QString::number(10);
+               break;
+       case 2:
+               cmdLine << QString::number(12);
+               break;
+       default:
+               MUTILS_THROW("Unknown encoder variant!");
+       }
+
+       switch(m_options->rcMode())
+       {
+       case 0:
                crf_frc = modf(m_options->quantizer(), &crf_int);
                cmdLine << "--crf" << QString("%1.%2").arg(QString::number(qRound(crf_int)), QString::number(qRound(crf_frc * 10.0)));
                break;
+       case 1:
+               cmdLine << "--qp" << QString::number(qRound(m_options->quantizer()));
+               break;
        case 2:
        case 3:
                cmdLine << "--bitrate" << QString::number(m_options->bitrate());
@@ -388,7 +400,7 @@ void X265Encoder::runEncodingPass_init(QList<QRegExp*> &patterns)
        patterns << new QRegExp("\\[\\s*(\\d+)\\.(\\d+)%\\]\\s+(\\d+)/(\\d+)\\s(\\d+).(\\d+)\\s(\\d+).(\\d+)\\s+(\\d+):(\\d+):(\\d+)\\s+(\\d+):(\\d+):(\\d+)"); //regExpModified
 }
 
-void X265Encoder::runEncodingPass_parseLine(const QString &line, QList<QRegExp*> &patterns, const ClipInfo &clipInfo, const int &pass, double &last_progress, double &size_estimate)
+void X265Encoder::runEncodingPass_parseLine(const QString &line, const QList<QRegExp*> &patterns, const ClipInfo &clipInfo, const int &pass, double &last_progress, double &size_estimate)
 {
        int offset = -1;
        if((offset = patterns[0]->lastIndexIn(line)) >= 0)