///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
-// Copyright (C) 2004-2015 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2016 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
#include "global.h"
#include "model_options.h"
#include "model_status.h"
-#include "binaries.h"
#include "mediainfo.h"
+#include "model_sysinfo.h"
+#include "model_clipInfo.h"
//MUtils
#include <MUtils/Exception.h>
#include <QStringList>
#include <QDir>
#include <QRegExp>
+#include <QPair>
//x265 version info
-static const unsigned int VERSION_X265_MINIMUM_VER = 14;
-static const unsigned int VERSION_X265_MINIMUM_REV = 424;
+static const unsigned int VERSION_X265_MINIMUM_VER = 20;
+static const unsigned int VERSION_X265_MINIMUM_REV = 16;
// ------------------------------------------------------------
// Helper Macros
} \
while(0)
-static QString MAKE_NAME(const char *baseName, const OptionsModel *options)
-{
- const QString arch = (options->encArch() == OptionsModel::EncArch_x64) ? "x64" : "x86";
- const QString vari = (options->encVariant() == OptionsModel::EncVariant_HiBit ) ? "16-Bit" : "8-Bit";
- return QString("%1, %2, %3").arg(QString::fromLatin1(baseName), arch, vari);
-}
-
// ------------------------------------------------------------
// Encoder Info
// ------------------------------------------------------------
class X265EncoderInfo : public AbstractEncoderInfo
{
public:
- virtual QString getVariantId(const int &variant) const
+ virtual QString getName(void) const
{
- switch(variant)
- {
- case OptionsModel::EncVariant_LoBit:
- return QString::fromLatin1("8-Bit");
- case OptionsModel::EncVariant_HiBit:
- return QString::fromLatin1("16-Bit");
- default:
- return QString::fromLatin1("N/A");
- }
+ return "x265 (HEVC/H.265)";
}
- virtual QStringList getTunings(void) const
+ virtual QList<ArchId> getArchitectures(void) const
{
- QStringList tunings;
- tunings << "Grain" << "PSNR" << "SSIM" << "FastDecode" << "ZeroLatency";
- return tunings;
+ return QList<ArchId>()
+ << qMakePair(QString("32-Bit (x86)"), ARCH_TYPE_X86)
+ << qMakePair(QString("64-Bit (x64)"), ARCH_TYPE_X64);
}
- virtual QStringList getProfiles(const int &variant) const
+ virtual QStringList getVariants(void) const
+ {
+ return QStringList() << "8-Bit" << "10-Bit" << "12-Bit";
+ }
+ virtual QList<RCMode> getRCModes(void) const
{
- return QStringList();
+ return QList<RCMode>()
+ << qMakePair(QString("CRF"), RC_TYPE_QUANTIZER)
+ << qMakePair(QString("CQ"), RC_TYPE_QUANTIZER)
+ << qMakePair(QString("2-Pass"), RC_TYPE_MULTIPASS)
+ << qMakePair(QString("ABR"), RC_TYPE_RATE_KBPS);
}
- virtual QStringList supportedOutputFormats(void) const
+ virtual QStringList getTunings(void) const
{
- QStringList extLst;
- extLst << "hevc";
- return extLst;
+ return QStringList() << "Grain" << "PSNR" << "SSIM" << "FastDecode" << "ZeroLatency";
}
- virtual bool isRCModeSupported(const int rcMode) const
+ virtual QStringList getPresets(void) const
{
- switch(rcMode)
+ return QStringList()
+ << "ultrafast" << "superfast" << "veryfast" << "faster" << "fast"
+ << "medium" << "slow" << "slower" << "veryslow" << "placebo";
+ }
+
+ virtual QStringList getProfiles(const quint32 &variant) const
+ {
+ QStringList profiles;
+ switch(variant)
{
- case OptionsModel::RCMode_CRF:
- case OptionsModel::RCMode_CQ:
- case OptionsModel::RCMode_2Pass:
- case OptionsModel::RCMode_ABR:
- return true;
- default:
- return false;
+ case 0: profiles << "main" << "main-intra" << "mainstillpicture" << "main444-8" << "main444-intra" << "main444-stillpicture"; break;
+ case 1: profiles << "main10" << "main10-intra" << "main422-10" << "main422-10-intra" << "main444-10" << "main444-10-intra"; break;
+ case 2: profiles << "main12" << "main12-intra" << "main422-12" << "main422-12-intra" << "main444-12" << "main444-12-intra"; break;
+ default: MUTILS_THROW("Unknown encoder variant!");
}
+ return profiles;
+ }
+
+ virtual QStringList supportedOutputFormats(void) const
+ {
+ return QStringList() << "hevc";
}
virtual bool isInputTypeSupported(const int format) const
return false;
}
}
+
+ virtual QString getBinaryPath(const SysinfoModel *sysinfo, const quint32 &encArch, const quint32 &encVariant) const
+ {
+ QString arch, variant;
+ switch(encArch)
+ {
+ case 0: arch = "x86"; break;
+ case 1: arch = "x64"; break;
+ default: MUTILS_THROW("Unknown encoder arch!");
+ }
+ switch(encVariant)
+ {
+ case 0: variant = "8bit"; break;
+ case 1: variant = "10bit"; break;
+ case 2: variant = "12bit"; break;
+ default: MUTILS_THROW("Unknown encoder arch!");
+ }
+ return QString("%1/toolset/%2/x265_%3_%2.exe").arg(sysinfo->getAppPath(), arch, variant);
+ }
+
+ virtual QString getHelpCommand(void) const
+ {
+ return "--fullhelp";
+ }
};
static const X265EncoderInfo s_x265EncoderInfo;
-const AbstractEncoderInfo &X265Encoder::getEncoderInfo(void)
+const AbstractEncoderInfo& X265Encoder::encoderInfo(void)
{
return s_x265EncoderInfo;
}
+const AbstractEncoderInfo &X265Encoder::getEncoderInfo(void) const
+{
+ return encoderInfo();
+}
+
// ------------------------------------------------------------
// Constructor & Destructor
// ------------------------------------------------------------
X265Encoder::X265Encoder(JobObject *jobObject, const OptionsModel *options, const SysinfoModel *const sysinfo, const PreferencesModel *const preferences, JobStatus &jobStatus, volatile bool *abort, volatile bool *pause, QSemaphore *semaphorePause, const QString &sourceFile, const QString &outputFile)
:
- AbstractEncoder(jobObject, options, sysinfo, preferences, jobStatus, abort, pause, semaphorePause, sourceFile, outputFile),
- m_encoderName(MAKE_NAME("x265 (H.265/HEVC)", m_options)),
- m_binaryFile(ENC_BINARY(sysinfo, options))
+ AbstractEncoder(jobObject, options, sysinfo, preferences, jobStatus, abort, pause, semaphorePause, sourceFile, outputFile)
{
if(options->encType() != OptionsModel::EncType_X265)
{
/*Nothing to do here*/
}
-const QString &X265Encoder::getName(void)
+QString X265Encoder::getName(void) const
{
- return m_encoderName;
+ return s_x265EncoderInfo.getFullName(m_options->encArch(), m_options->encVariant());
}
// ------------------------------------------------------------
// Encoding Functions
// ------------------------------------------------------------
-void X265Encoder::buildCommandLine(QStringList &cmdLine, const bool &usePipe, const unsigned int &frames, const QString &indexFile, const int &pass, const QString &passLogFile)
+void X265Encoder::buildCommandLine(QStringList &cmdLine, const bool &usePipe, const ClipInfo &clipInfo, const QString &indexFile, const int &pass, const QString &passLogFile)
{
double crf_int = 0.0, crf_frc = 0.0;
switch(m_options->rcMode())
{
- case OptionsModel::RCMode_CQ:
- cmdLine << "--qp" << QString::number(qRound(m_options->quantizer()));
- break;
- case OptionsModel::RCMode_CRF:
+ 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 OptionsModel::RCMode_2Pass:
- case OptionsModel::RCMode_ABR:
+ case 1:
+ cmdLine << "--qp" << QString::number(qRound(m_options->quantizer()));
+ break;
+ case 2:
+ case 3:
cmdLine << "--bitrate" << QString::number(m_options->bitrate());
break;
default:
cmdLine << "--stats" << QDir::toNativeSeparators(passLogFile);
}
- cmdLine << "--preset" << m_options->preset().toLower();
+ 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;
+ }
+ }
- if(!m_options->tune().simplified().isEmpty())
+ const QString tune = m_options->tune().simplified().toLower();
+ if(!tune.isEmpty())
{
- if(m_options->tune().simplified().compare(QString::fromLatin1(OptionsModel::TUNING_UNSPECIFIED), Qt::CaseInsensitive) != 0)
+ if(tune.compare(QString::fromLatin1(OptionsModel::SETTING_UNSPECIFIED), Qt::CaseInsensitive) != 0)
{
- cmdLine << "--tune" << m_options->tune().simplified().toLower();
+ cmdLine << "--tune" << tune;
}
}
- if(m_options->profile().compare("auto", Qt::CaseInsensitive) != 0)
+ const QString profile = m_options->profile().simplified().toLower();
+ if(!profile.isEmpty())
{
- if((m_options->encType() == OptionsModel::EncType_X264) && (m_options->encVariant() == OptionsModel::EncVariant_LoBit))
+ if(profile.compare(QString::fromLatin1(OptionsModel::PROFILE_UNRESTRICTED), Qt::CaseInsensitive) != 0)
{
- cmdLine << "--profile" << m_options->profile().toLower();
+ cmdLine << "--profile" << profile;
}
}
if(usePipe)
{
- if(frames < 1) MUTILS_THROW("Frames not set!");
- cmdLine << "--frames" << QString::number(frames);
+ if (clipInfo.getFrameCount() < 1)
+ {
+ MUTILS_THROW("Frames not set!");
+ }
+ cmdLine << "--frames" << QString::number(clipInfo.getFrameCount());
cmdLine << "--y4m" << "-";
}
else
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 int &pass, double &last_progress, double &size_estimate)
+void X265Encoder::runEncodingPass_parseLine(const QString &line, 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)