1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
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.
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 ///////////////////////////////////////////////////////////////////////////////
24 #include "source_avisynth.h"
27 #include "model_sysinfo.h"
28 #include "model_preferences.h"
34 static const unsigned int VER_X264_AVS2YUV_VER = 242;
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)
59 // ------------------------------------------------------------
61 // ------------------------------------------------------------
63 bool AvisynthSource::isSourceAvailable()
65 if(!(m_sysinfo->hasAVSSupport()))
67 log(tr("\nAVS INPUT REQUIRES AVISYNTH, BUT IT IS *NOT* AVAILABLE !!!"));
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 &coreVers, unsigned int &revision, bool &modified)
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);
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)
104 revision = (temp2 * 10) + (temp3 % 10);
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 return tr("Avs2YUV version: %1.%2.%3").arg(QString::number(revision / REV_MULT), QString::number((revision % REV_MULT) / 10),QString::number((revision % REV_MULT) % 10));
121 bool AvisynthSource::isVersionSupported(const unsigned int &revision, const bool &modified)
123 if((revision != UINT_MAX) && ((revision % REV_MULT) < VER_X264_AVS2YUV_VER))
125 log(tr("\nERROR: Your version of avs2yuv is unsupported (required version: v0.24 BugMaster's mod 2)"));
126 log(tr("You can find the required version at: http://komisar.gin.by/tools/avs2yuv/"));
132 // ------------------------------------------------------------
133 // Check Source Properties
134 // ------------------------------------------------------------
136 void AvisynthSource::checkSourceProperties_init(QList<QRegExp*> &patterns, QStringList &cmdLine)
138 cmdLine << "-frames" << "1";
139 cmdLine << QDir::toNativeSeparators(x264_path2ansi(m_sourceFile, true)) << "NUL";
141 patterns << new QRegExp(": (\\d+)x(\\d+), (\\d+) fps, (\\d+) frames");
142 patterns << new QRegExp(": (\\d+)x(\\d+), (\\d+)/(\\d+) fps, (\\d+) frames");
145 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)
147 qWarning("parseLine \"%1\"", line.toUtf8().constData());
151 if((offset = patterns[0]->lastIndexIn(line)) >= 0)
153 bool ok1 = false, ok2 = false;
154 bool ok3 = false, ok4 = false;
155 unsigned int temp1 = patterns[0]->cap(1).toUInt(&ok1);
156 unsigned int temp2 = patterns[0]->cap(2).toUInt(&ok2);
157 unsigned int temp3 = patterns[0]->cap(3).toUInt(&ok3);
158 unsigned int temp4 = patterns[0]->cap(4).toUInt(&ok4);
159 if(ok1) fSizeW = temp1;
160 if(ok2) fSizeH = temp2;
161 if(ok3) fpsNom = temp3;
162 if(ok4) frames = temp4;
164 else if((offset = patterns[1]->lastIndexIn(line)) >= 0)
166 bool ok1 = false, ok2 = false;
167 bool ok3 = false, ok4 = false, ok5 = false;
168 unsigned int temp1 = patterns[1]->cap(1).toUInt(&ok1);
169 unsigned int temp2 = patterns[1]->cap(2).toUInt(&ok2);
170 unsigned int temp3 = patterns[1]->cap(3).toUInt(&ok3);
171 unsigned int temp4 = patterns[1]->cap(4).toUInt(&ok4);
172 unsigned int temp5 = patterns[1]->cap(5).toUInt(&ok5);
173 if(ok1) fSizeW = temp1;
174 if(ok2) fSizeH = temp2;
175 if(ok3) fpsNom = temp3;
176 if(ok4) fpsDen = temp4;
177 if(ok5) frames = temp5;
185 if(line.contains("failed to load avisynth.dll", Qt::CaseInsensitive))
187 log(tr("\nWarning: It seems that %1-Bit Avisynth is not currently installed !!!").arg(m_preferences->getUseAvisyth64Bit() ? "64" : "32"));
189 if(line.contains(QRegExp("couldn't convert input clip to (YV16|YV24)", Qt::CaseInsensitive)))
191 log(tr("\nWarning: YV16 (4:2:2) and YV24 (4:4:4) color-spaces only supported in Avisynth 2.6 !!!"));
195 // ------------------------------------------------------------
197 // ------------------------------------------------------------
199 void AvisynthSource::buildCommandLine(QStringList &cmdLine)
201 cmdLine << QDir::toNativeSeparators(x264_path2ansi(m_sourceFile, true));
205 void AvisynthSource::flushProcess(QProcess &processInput)
207 while(processInput.bytesAvailable() > 0)
209 log(tr("av2y [info]: %1").arg(QString::fromUtf8(processInput.readLine()).simplified()));
212 if(processInput.exitCode() != EXIT_SUCCESS)
214 const int exitCode = processInput.exitCode();
215 log(tr("\nWARNING: Input process exited with error (code: %1), your encode might be *incomplete* !!!").arg(QString::number(exitCode)));
216 if((exitCode < 0) || (exitCode >= 32))
218 log(tr("\nIMPORTANT: The Avs2YUV process terminated abnormally. This means Avisynth or one of your Avisynth-Plugin's just crashed."));
219 log(tr("IMPORTANT: Please fix your Avisynth script and try again! If you use Avisynth-MT, try using a *stable* Avisynth instead!"));