2014-02-24 23:13:42 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Simple x264 Launcher
|
2017-01-07 18:48:20 +01:00
|
|
|
// Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
|
2014-02-24 23:13:42 +01:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
// http://www.gnu.org/licenses/gpl-2.0.txt
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "source_avisynth.h"
|
|
|
|
|
|
|
|
#include "global.h"
|
|
|
|
|
2016-10-02 16:18:01 +02:00
|
|
|
#include <MUtils/Global.h>
|
|
|
|
|
2014-02-24 23:13:42 +01:00
|
|
|
#include <QDir>
|
|
|
|
#include <QProcess>
|
|
|
|
|
2017-01-07 20:47:37 +01:00
|
|
|
static const unsigned int VER_X264_AVS2YUV_VER = 245;
|
2014-02-24 23:13:42 +01:00
|
|
|
|
2015-08-02 21:16:36 +02:00
|
|
|
// ------------------------------------------------------------
|
|
|
|
// Encoder Info
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
|
|
|
class AvisynthSourceInfo : public AbstractSourceInfo
|
|
|
|
{
|
|
|
|
public:
|
2016-10-02 16:18:01 +02:00
|
|
|
virtual QString getBinaryPath(const SysinfoModel *const sysinfo, const bool& x64) const
|
2015-08-02 21:16:36 +02:00
|
|
|
{
|
|
|
|
return QString("%1/toolset/%2/avs2yuv_%2.exe").arg(sysinfo->getAppPath(), (x64 ? "x64": "x86"));
|
|
|
|
}
|
2016-10-02 16:18:01 +02:00
|
|
|
|
2016-10-02 17:34:48 +02:00
|
|
|
virtual QStringList getExtraPaths(const SysinfoModel *const sysinfo, const bool& x64) const
|
2016-10-02 16:18:01 +02:00
|
|
|
{
|
|
|
|
const QString avsPath = sysinfo->getAVSPath();
|
|
|
|
if (!avsPath.isEmpty())
|
|
|
|
{
|
|
|
|
|
2016-10-02 17:34:48 +02:00
|
|
|
return QStringList() << QString("%1/%2").arg(avsPath, x64 ? QLatin1String("x64") : QLatin1String("x86"));
|
2016-10-02 16:18:01 +02:00
|
|
|
}
|
2016-10-02 17:34:48 +02:00
|
|
|
return QStringList();
|
2016-10-02 16:18:01 +02:00
|
|
|
}
|
2015-08-02 21:16:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const AvisynthSourceInfo s_avisynthEncoderInfo;
|
|
|
|
|
|
|
|
const AbstractSourceInfo &AvisynthSource::getSourceInfo(void)
|
|
|
|
{
|
|
|
|
return s_avisynthEncoderInfo;
|
|
|
|
}
|
|
|
|
|
2016-10-02 16:18:01 +02:00
|
|
|
|
2014-02-26 00:55:11 +01:00
|
|
|
// ------------------------------------------------------------
|
|
|
|
// Constructor & Destructor
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
2014-02-24 23:13:42 +01:00
|
|
|
AvisynthSource::AvisynthSource(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)
|
|
|
|
:
|
2015-08-02 21:16:36 +02:00
|
|
|
AbstractSource(jobObject, options, sysinfo, preferences, jobStatus, abort, pause, semaphorePause, sourceFile)
|
2014-02-24 23:13:42 +01:00
|
|
|
{
|
|
|
|
/*Nothing to do here*/
|
|
|
|
}
|
|
|
|
|
|
|
|
AvisynthSource::~AvisynthSource(void)
|
|
|
|
{
|
|
|
|
/*Nothing to do here*/
|
|
|
|
}
|
|
|
|
|
2015-08-02 19:16:37 +02:00
|
|
|
QString AvisynthSource::getName(void) const
|
2014-02-26 16:08:06 +01:00
|
|
|
{
|
2015-08-02 21:16:36 +02:00
|
|
|
return tr("Avisynth (avs)");
|
2014-02-26 16:08:06 +01:00
|
|
|
}
|
|
|
|
|
2014-02-26 00:55:11 +01:00
|
|
|
// ------------------------------------------------------------
|
|
|
|
// Check Version
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
2014-02-25 22:44:39 +01:00
|
|
|
bool AvisynthSource::isSourceAvailable()
|
|
|
|
{
|
2015-02-28 17:12:35 +01:00
|
|
|
if(!(m_sysinfo->hasAvisynth()))
|
2014-02-25 22:44:39 +01:00
|
|
|
{
|
|
|
|
log(tr("\nAVS INPUT REQUIRES AVISYNTH, BUT IT IS *NOT* AVAILABLE !!!"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-24 23:13:42 +01:00
|
|
|
void AvisynthSource::checkVersion_init(QList<QRegExp*> &patterns, QStringList &cmdLine)
|
|
|
|
{
|
|
|
|
patterns << new QRegExp("\\bAvs2YUV (\\d+).(\\d+)\\b", Qt::CaseInsensitive);
|
2014-02-25 22:44:39 +01:00
|
|
|
patterns << new QRegExp("\\bAvs2YUV (\\d+).(\\d+)bm(\\d)\\b", Qt::CaseInsensitive);
|
2014-02-24 23:13:42 +01:00
|
|
|
}
|
|
|
|
|
2014-05-06 00:22:18 +02:00
|
|
|
void AvisynthSource::checkVersion_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &core, unsigned int &build, bool &modified)
|
2014-02-24 23:13:42 +01:00
|
|
|
{
|
|
|
|
int offset = -1;
|
2014-02-26 00:55:11 +01:00
|
|
|
|
2014-02-24 23:13:42 +01:00
|
|
|
if((offset = patterns[0]->lastIndexIn(line)) >= 0)
|
|
|
|
{
|
|
|
|
bool ok1 = false, ok2 = false;
|
2014-02-26 00:55:11 +01:00
|
|
|
unsigned int temp1 = patterns[0]->cap(1).toUInt(&ok1);
|
|
|
|
unsigned int temp2 = patterns[0]->cap(2).toUInt(&ok2);
|
|
|
|
if(ok1 && ok2)
|
|
|
|
{
|
2014-05-06 00:22:18 +02:00
|
|
|
core = temp1;
|
|
|
|
build = temp2;
|
2014-02-26 00:55:11 +01:00
|
|
|
}
|
2014-02-26 17:39:36 +01:00
|
|
|
log(line);
|
2014-02-24 23:13:42 +01:00
|
|
|
}
|
|
|
|
else if((offset = patterns[1]->lastIndexIn(line)) >= 0)
|
|
|
|
{
|
2014-02-26 00:55:11 +01:00
|
|
|
bool ok1 = false, ok2 = false, ok3 = false;
|
|
|
|
unsigned int temp1 = patterns[1]->cap(1).toUInt(&ok1);
|
|
|
|
unsigned int temp2 = patterns[1]->cap(2).toUInt(&ok2);
|
|
|
|
unsigned int temp3 = patterns[1]->cap(3).toUInt(&ok3);
|
|
|
|
if(ok1 && ok2 && ok3)
|
|
|
|
{
|
2014-05-06 00:22:18 +02:00
|
|
|
core = temp1;
|
|
|
|
build = (temp2 * 10) + (temp3 % 10);
|
2014-02-26 00:55:11 +01:00
|
|
|
}
|
2014-02-24 23:13:42 +01:00
|
|
|
modified = true;
|
2014-02-26 17:39:36 +01:00
|
|
|
log(line);
|
2014-02-24 23:13:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 00:55:11 +01:00
|
|
|
bool AvisynthSource::checkVersion_succeeded(const int &exitCode)
|
|
|
|
{
|
|
|
|
return (exitCode == EXIT_SUCCESS) || (exitCode == 2);
|
|
|
|
}
|
|
|
|
|
2014-02-26 17:39:36 +01:00
|
|
|
QString AvisynthSource::printVersion(const unsigned int &revision, const bool &modified)
|
2014-02-24 23:13:42 +01:00
|
|
|
{
|
2014-05-06 00:22:18 +02:00
|
|
|
unsigned int core, build;
|
|
|
|
splitRevision(revision, core, build);
|
|
|
|
|
|
|
|
return tr("Avs2YUV version: %1.%2.%3").arg(QString::number(core), QString::number(build / 10),QString::number(build % 10));
|
2014-02-24 23:13:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AvisynthSource::isVersionSupported(const unsigned int &revision, const bool &modified)
|
|
|
|
{
|
2014-05-06 00:22:18 +02:00
|
|
|
unsigned int core, build;
|
|
|
|
splitRevision(revision, core, build);
|
|
|
|
|
|
|
|
if((revision != UINT_MAX) && (build < VER_X264_AVS2YUV_VER))
|
2014-02-24 23:13:42 +01:00
|
|
|
{
|
2014-02-26 00:55:11 +01:00
|
|
|
log(tr("\nERROR: Your version of avs2yuv is unsupported (required version: v0.24 BugMaster's mod 2)"));
|
2014-02-24 23:13:42 +01:00
|
|
|
log(tr("You can find the required version at: http://komisar.gin.by/tools/avs2yuv/"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-26 00:55:11 +01:00
|
|
|
// ------------------------------------------------------------
|
|
|
|
// Check Source Properties
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
2014-02-24 23:13:42 +01:00
|
|
|
void AvisynthSource::checkSourceProperties_init(QList<QRegExp*> &patterns, QStringList &cmdLine)
|
|
|
|
{
|
2015-11-18 20:48:54 +01:00
|
|
|
if(!m_options->customAvs2YUV().isEmpty())
|
|
|
|
{
|
|
|
|
cmdLine << splitParams(m_options->customAvs2YUV());
|
|
|
|
}
|
|
|
|
|
2014-02-24 23:13:42 +01:00
|
|
|
cmdLine << "-frames" << "1";
|
|
|
|
cmdLine << QDir::toNativeSeparators(x264_path2ansi(m_sourceFile, true)) << "NUL";
|
|
|
|
|
|
|
|
patterns << new QRegExp(": (\\d+)x(\\d+), (\\d+) fps, (\\d+) frames");
|
|
|
|
patterns << new QRegExp(": (\\d+)x(\\d+), (\\d+)/(\\d+) fps, (\\d+) frames");
|
|
|
|
}
|
|
|
|
|
2016-05-08 18:33:48 +02:00
|
|
|
void AvisynthSource::checkSourceProperties_parseLine(const QString &line, QList<QRegExp*> &patterns, ClipInfo &clipInfo)
|
2014-02-24 23:13:42 +01:00
|
|
|
{
|
|
|
|
int offset = -1;
|
2014-02-26 00:55:11 +01:00
|
|
|
|
2014-02-24 23:13:42 +01:00
|
|
|
if((offset = patterns[0]->lastIndexIn(line)) >= 0)
|
|
|
|
{
|
2016-05-08 18:33:48 +02:00
|
|
|
bool ok[4] = { false, false, false, false };
|
|
|
|
quint32 temp[4];
|
|
|
|
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]);
|
|
|
|
temp[3] = patterns[0]->cap(4).toUInt(&ok[3]);
|
|
|
|
if (ok[0] && ok[1])
|
|
|
|
{
|
|
|
|
clipInfo.setFrameSize(temp[0], temp[1]);
|
|
|
|
}
|
|
|
|
if (ok[2])
|
|
|
|
{
|
|
|
|
clipInfo.setFrameRate(temp[2], 0);
|
|
|
|
}
|
|
|
|
if (ok[3])
|
|
|
|
{
|
|
|
|
clipInfo.setFrameCount(temp[3]);
|
|
|
|
}
|
2014-02-24 23:13:42 +01:00
|
|
|
}
|
|
|
|
else if((offset = patterns[1]->lastIndexIn(line)) >= 0)
|
|
|
|
{
|
2016-05-08 18:33:48 +02:00
|
|
|
bool ok[5] = { false, false, false, false, false };
|
|
|
|
quint32 temp[5];
|
|
|
|
temp[0] = patterns[1]->cap(1).toUInt(&ok[0]);
|
|
|
|
temp[1] = patterns[1]->cap(2).toUInt(&ok[1]);
|
|
|
|
temp[2] = patterns[1]->cap(3).toUInt(&ok[2]);
|
|
|
|
temp[3] = patterns[1]->cap(4).toUInt(&ok[3]);
|
|
|
|
temp[4] = patterns[1]->cap(5).toUInt(&ok[4]);
|
|
|
|
if (ok[0] && ok[1])
|
|
|
|
{
|
|
|
|
clipInfo.setFrameSize(temp[0], temp[1]);
|
|
|
|
}
|
|
|
|
if (ok[2] && ok[3])
|
|
|
|
{
|
|
|
|
clipInfo.setFrameRate(temp[2], temp[3]);
|
|
|
|
}
|
|
|
|
if (ok[4])
|
|
|
|
{
|
|
|
|
clipInfo.setFrameCount(temp[4]);
|
|
|
|
}
|
2014-02-24 23:13:42 +01:00
|
|
|
}
|
2014-02-26 00:55:11 +01:00
|
|
|
|
2014-02-24 23:13:42 +01:00
|
|
|
if(!line.isEmpty())
|
|
|
|
{
|
|
|
|
log(line);
|
|
|
|
}
|
2014-02-26 00:55:11 +01:00
|
|
|
|
2014-02-24 23:13:42 +01:00
|
|
|
if(line.contains("failed to load avisynth.dll", Qt::CaseInsensitive))
|
|
|
|
{
|
2015-02-28 17:12:35 +01:00
|
|
|
log(tr("\nWarning: It seems that Avisynth is not currently installed/available !!!"));
|
2014-02-24 23:13:42 +01:00
|
|
|
}
|
|
|
|
if(line.contains(QRegExp("couldn't convert input clip to (YV16|YV24)", Qt::CaseInsensitive)))
|
|
|
|
{
|
|
|
|
log(tr("\nWarning: YV16 (4:2:2) and YV24 (4:4:4) color-spaces only supported in Avisynth 2.6 !!!"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 00:55:11 +01:00
|
|
|
// ------------------------------------------------------------
|
|
|
|
// Source Processing
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
2014-02-24 23:13:42 +01:00
|
|
|
void AvisynthSource::buildCommandLine(QStringList &cmdLine)
|
|
|
|
{
|
2015-11-18 20:48:54 +01:00
|
|
|
if(!m_options->customAvs2YUV().isEmpty())
|
|
|
|
{
|
|
|
|
cmdLine << splitParams(m_options->customAvs2YUV());
|
|
|
|
}
|
|
|
|
|
2014-02-24 23:13:42 +01:00
|
|
|
cmdLine << QDir::toNativeSeparators(x264_path2ansi(m_sourceFile, true));
|
|
|
|
cmdLine << "-";
|
|
|
|
}
|
|
|
|
|
|
|
|
void AvisynthSource::flushProcess(QProcess &processInput)
|
|
|
|
{
|
|
|
|
while(processInput.bytesAvailable() > 0)
|
|
|
|
{
|
|
|
|
log(tr("av2y [info]: %1").arg(QString::fromUtf8(processInput.readLine()).simplified()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(processInput.exitCode() != EXIT_SUCCESS)
|
|
|
|
{
|
|
|
|
const int exitCode = processInput.exitCode();
|
|
|
|
log(tr("\nWARNING: Input process exited with error (code: %1), your encode might be *incomplete* !!!").arg(QString::number(exitCode)));
|
|
|
|
if((exitCode < 0) || (exitCode >= 32))
|
|
|
|
{
|
|
|
|
log(tr("\nIMPORTANT: The Avs2YUV process terminated abnormally. This means Avisynth or one of your Avisynth-Plugin's just crashed."));
|
|
|
|
log(tr("IMPORTANT: Please fix your Avisynth script and try again! If you use Avisynth-MT, try using a *stable* Avisynth instead!"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|