Updated Avs2YUV to v0.24 (BugMaster's mod 3).
[simple-x264-launcher.git] / src / source_avisynth.cpp
blob509c8379c77adf0e777f1901b14eb93333355105
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #pragma once
24 #include "source_avisynth.h"
26 #include "global.h"
27 #include "model_sysinfo.h"
28 #include "model_preferences.h"
29 #include "binaries.h"
31 #include <QDir>
32 #include <QProcess>
34 static const unsigned int VER_X264_AVS2YUV_VER = 243;
36 // ------------------------------------------------------------
37 // Constructor & Destructor
38 // ------------------------------------------------------------
40 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)
42 AbstractSource(jobObject, options, sysinfo, preferences, jobStatus, abort, pause, semaphorePause, sourceFile),
43 m_sourceName("Avisynth (avs)"),
44 m_binaryFile(AVS_BINARY(m_sysinfo, m_preferences))
46 /*Nothing to do here*/
49 AvisynthSource::~AvisynthSource(void)
51 /*Nothing to do here*/
54 const QString &AvisynthSource::getName(void)
56 return m_sourceName;
59 // ------------------------------------------------------------
60 // Check Version
61 // ------------------------------------------------------------
63 bool AvisynthSource::isSourceAvailable()
65 if(!(m_sysinfo->hasAVSSupport()))
67 log(tr("\nAVS INPUT REQUIRES AVISYNTH, BUT IT IS *NOT* AVAILABLE !!!"));
68 return false;
70 return true;
73 void AvisynthSource::checkVersion_init(QList<QRegExp*> &patterns, QStringList &cmdLine)
75 patterns << new QRegExp("\\bAvs2YUV (\\d+).(\\d+)\\b", Qt::CaseInsensitive);
76 patterns << new QRegExp("\\bAvs2YUV (\\d+).(\\d+)bm(\\d)\\b", Qt::CaseInsensitive);
79 void AvisynthSource::checkVersion_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &core, unsigned int &build, bool &modified)
81 int offset = -1;
83 if((offset = patterns[0]->lastIndexIn(line)) >= 0)
85 bool ok1 = false, ok2 = false;
86 unsigned int temp1 = patterns[0]->cap(1).toUInt(&ok1);
87 unsigned int temp2 = patterns[0]->cap(2).toUInt(&ok2);
88 if(ok1 && ok2)
90 core = temp1;
91 build = temp2;
93 log(line);
95 else if((offset = patterns[1]->lastIndexIn(line)) >= 0)
97 bool ok1 = false, ok2 = false, ok3 = false;
98 unsigned int temp1 = patterns[1]->cap(1).toUInt(&ok1);
99 unsigned int temp2 = patterns[1]->cap(2).toUInt(&ok2);
100 unsigned int temp3 = patterns[1]->cap(3).toUInt(&ok3);
101 if(ok1 && ok2 && ok3)
103 core = temp1;
104 build = (temp2 * 10) + (temp3 % 10);
106 modified = true;
107 log(line);
111 bool AvisynthSource::checkVersion_succeeded(const int &exitCode)
113 return (exitCode == EXIT_SUCCESS) || (exitCode == 2);
116 QString AvisynthSource::printVersion(const unsigned int &revision, const bool &modified)
118 unsigned int core, build;
119 splitRevision(revision, core, build);
121 return tr("Avs2YUV version: %1.%2.%3").arg(QString::number(core), QString::number(build / 10),QString::number(build % 10));
124 bool AvisynthSource::isVersionSupported(const unsigned int &revision, const bool &modified)
126 unsigned int core, build;
127 splitRevision(revision, core, build);
129 if((revision != UINT_MAX) && (build < VER_X264_AVS2YUV_VER))
131 log(tr("\nERROR: Your version of avs2yuv is unsupported (required version: v0.24 BugMaster's mod 2)"));
132 log(tr("You can find the required version at: http://komisar.gin.by/tools/avs2yuv/"));
133 return false;
135 return true;
138 // ------------------------------------------------------------
139 // Check Source Properties
140 // ------------------------------------------------------------
142 void AvisynthSource::checkSourceProperties_init(QList<QRegExp*> &patterns, QStringList &cmdLine)
144 cmdLine << "-frames" << "1";
145 cmdLine << QDir::toNativeSeparators(x264_path2ansi(m_sourceFile, true)) << "NUL";
147 patterns << new QRegExp(": (\\d+)x(\\d+), (\\d+) fps, (\\d+) frames");
148 patterns << new QRegExp(": (\\d+)x(\\d+), (\\d+)/(\\d+) fps, (\\d+) frames");
151 void AvisynthSource::checkSourceProperties_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &frames, unsigned int &fSizeW, unsigned int &fSizeH, unsigned int &fpsNom, unsigned int &fpsDen)
153 int offset = -1;
155 if((offset = patterns[0]->lastIndexIn(line)) >= 0)
157 bool ok1 = false, ok2 = false;
158 bool ok3 = false, ok4 = false;
159 unsigned int temp1 = patterns[0]->cap(1).toUInt(&ok1);
160 unsigned int temp2 = patterns[0]->cap(2).toUInt(&ok2);
161 unsigned int temp3 = patterns[0]->cap(3).toUInt(&ok3);
162 unsigned int temp4 = patterns[0]->cap(4).toUInt(&ok4);
163 if(ok1) fSizeW = temp1;
164 if(ok2) fSizeH = temp2;
165 if(ok3) fpsNom = temp3;
166 if(ok4) frames = temp4;
168 else if((offset = patterns[1]->lastIndexIn(line)) >= 0)
170 bool ok1 = false, ok2 = false;
171 bool ok3 = false, ok4 = false, ok5 = false;
172 unsigned int temp1 = patterns[1]->cap(1).toUInt(&ok1);
173 unsigned int temp2 = patterns[1]->cap(2).toUInt(&ok2);
174 unsigned int temp3 = patterns[1]->cap(3).toUInt(&ok3);
175 unsigned int temp4 = patterns[1]->cap(4).toUInt(&ok4);
176 unsigned int temp5 = patterns[1]->cap(5).toUInt(&ok5);
177 if(ok1) fSizeW = temp1;
178 if(ok2) fSizeH = temp2;
179 if(ok3) fpsNom = temp3;
180 if(ok4) fpsDen = temp4;
181 if(ok5) frames = temp5;
184 if(!line.isEmpty())
186 log(line);
189 if(line.contains("failed to load avisynth.dll", Qt::CaseInsensitive))
191 log(tr("\nWarning: It seems that %1-Bit Avisynth is not currently installed !!!").arg(m_preferences->getUseAvisyth64Bit() ? "64" : "32"));
193 if(line.contains(QRegExp("couldn't convert input clip to (YV16|YV24)", Qt::CaseInsensitive)))
195 log(tr("\nWarning: YV16 (4:2:2) and YV24 (4:4:4) color-spaces only supported in Avisynth 2.6 !!!"));
199 // ------------------------------------------------------------
200 // Source Processing
201 // ------------------------------------------------------------
203 void AvisynthSource::buildCommandLine(QStringList &cmdLine)
205 cmdLine << QDir::toNativeSeparators(x264_path2ansi(m_sourceFile, true));
206 cmdLine << "-";
209 void AvisynthSource::flushProcess(QProcess &processInput)
211 while(processInput.bytesAvailable() > 0)
213 log(tr("av2y [info]: %1").arg(QString::fromUtf8(processInput.readLine()).simplified()));
216 if(processInput.exitCode() != EXIT_SUCCESS)
218 const int exitCode = processInput.exitCode();
219 log(tr("\nWARNING: Input process exited with error (code: %1), your encode might be *incomplete* !!!").arg(QString::number(exitCode)));
220 if((exitCode < 0) || (exitCode >= 32))
222 log(tr("\nIMPORTANT: The Avs2YUV process terminated abnormally. This means Avisynth or one of your Avisynth-Plugin's just crashed."));
223 log(tr("IMPORTANT: Please fix your Avisynth script and try again! If you use Avisynth-MT, try using a *stable* Avisynth instead!"));