1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2022 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"
28 #include <MUtils/Global.h>
33 static const unsigned int VER_X264_AVS2YUV_VER
= 246;
35 // ------------------------------------------------------------
37 // ------------------------------------------------------------
39 class AvisynthSourceInfo
: public AbstractSourceInfo
42 virtual QString
getBinaryPath(const SysinfoModel
*const sysinfo
, const bool& x64
) const
44 return QString("%1/toolset/%2/avs2yuv_%2.exe").arg(sysinfo
->getAppPath(), (x64
? "x64": "x86"));
47 virtual QStringList
getExtraPaths(const SysinfoModel
*const sysinfo
, const bool& x64
) const
49 const QString avsPath
= sysinfo
->getAVSPath();
50 if (!avsPath
.isEmpty())
53 return QStringList() << QString("%1/%2").arg(avsPath
, x64
? QLatin1String("x64") : QLatin1String("x86"));
59 static const AvisynthSourceInfo s_avisynthEncoderInfo
;
61 const AbstractSourceInfo
&AvisynthSource::getSourceInfo(void)
63 return s_avisynthEncoderInfo
;
67 // ------------------------------------------------------------
68 // Constructor & Destructor
69 // ------------------------------------------------------------
71 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
)
73 AbstractSource(jobObject
, options
, sysinfo
, preferences
, jobStatus
, abort
, pause
, semaphorePause
, sourceFile
)
75 /*Nothing to do here*/
78 AvisynthSource::~AvisynthSource(void)
80 /*Nothing to do here*/
83 QString
AvisynthSource::getName(void) const
85 return tr("Avisynth (avs)");
88 // ------------------------------------------------------------
90 // ------------------------------------------------------------
92 bool AvisynthSource::isSourceAvailable()
94 if(!(m_sysinfo
->hasAvisynth()))
96 log(tr("\nAVS INPUT REQUIRES AVISYNTH, BUT IT IS *NOT* AVAILABLE !!!"));
102 void AvisynthSource::checkVersion_init(QList
<QRegExp
*> &patterns
, QStringList
&cmdLine
)
104 patterns
<< new QRegExp("\\bAvs2YUV (\\d+).(\\d+)\\b", Qt::CaseInsensitive
);
105 patterns
<< new QRegExp("\\bAvs2YUV (\\d+).(\\d+)bm(\\d)\\b", Qt::CaseInsensitive
);
108 void AvisynthSource::checkVersion_parseLine(const QString
&line
, const QList
<QRegExp
*> &patterns
, unsigned int &core
, unsigned int &build
, bool &modified
)
112 if((offset
= patterns
[0]->lastIndexIn(line
)) >= 0)
114 bool ok1
= false, ok2
= false;
115 unsigned int temp1
= patterns
[0]->cap(1).toUInt(&ok1
);
116 unsigned int temp2
= patterns
[0]->cap(2).toUInt(&ok2
);
124 else if((offset
= patterns
[1]->lastIndexIn(line
)) >= 0)
126 bool ok1
= false, ok2
= false, ok3
= false;
127 unsigned int temp1
= patterns
[1]->cap(1).toUInt(&ok1
);
128 unsigned int temp2
= patterns
[1]->cap(2).toUInt(&ok2
);
129 unsigned int temp3
= patterns
[1]->cap(3).toUInt(&ok3
);
130 if(ok1
&& ok2
&& ok3
)
133 build
= (temp2
* 10) + (temp3
% 10);
140 bool AvisynthSource::checkVersion_succeeded(const int &exitCode
)
142 return (exitCode
== EXIT_SUCCESS
) || (exitCode
== 2);
145 QString
AvisynthSource::printVersion(const unsigned int &revision
, const bool &modified
)
147 unsigned int core
, build
;
148 splitRevision(revision
, core
, build
);
150 return tr("Avs2YUV version: %1.%2.%3").arg(QString::number(core
), QString::number(build
/ 10),QString::number(build
% 10));
153 bool AvisynthSource::isVersionSupported(const unsigned int &revision
, const bool &modified
)
155 unsigned int core
, build
;
156 splitRevision(revision
, core
, build
);
158 if((revision
!= UINT_MAX
) && (build
< VER_X264_AVS2YUV_VER
))
160 log(tr("\nERROR: Your version of avs2yuv is unsupported (required version: v0.24 BugMaster's mod 6)"));
161 log(tr("You can find the required version at: http://komisar.gin.by/tools/avs2yuv/"));
167 // ------------------------------------------------------------
168 // Check Source Properties
169 // ------------------------------------------------------------
171 void AvisynthSource::checkSourceProperties_init(QList
<QRegExp
*> &patterns
, QStringList
&cmdLine
)
173 if(!m_options
->customAvs2YUV().isEmpty())
175 cmdLine
<< splitParams(m_options
->customAvs2YUV());
178 cmdLine
<< "-frames" << "1";
179 cmdLine
<< QDir::toNativeSeparators(x264_path2ansi(m_sourceFile
, true)) << "NUL";
181 patterns
<< new QRegExp(":\\s+(\\d+)\\s*x\\s*(\\d+)\\s*,\\s+\\w+\\s*,\\s+\\d+-bits\\s*,\\s+\\w+\\s*,\\s+(\\d+)\\s+fps\\s*,\\s+(\\d+)\\s+frames");
182 patterns
<< new QRegExp(":\\s+(\\d+)\\s*x\\s*(\\d+)\\s*,\\s+\\w+\\s*,\\s+\\d+-bits\\s*,\\s+\\w+\\s*,\\s+(\\d+)\\s*/\\s*(\\d+)\\s+fps\\s*,\\s+(\\d+)\\s+frames");
185 void AvisynthSource::checkSourceProperties_parseLine(const QString
&line
, const QList
<QRegExp
*> &patterns
, ClipInfo
&clipInfo
)
190 if((offset
= patterns
[0]->lastIndexIn(line
)) >= 0)
192 if (MUtils::regexp_parse_uint32((*patterns
[0]), temp
, 4))
194 clipInfo
.setFrameSize(temp
[0], temp
[1]);
195 clipInfo
.setFrameRate(temp
[2], 0);
196 clipInfo
.setFrameCount(temp
[3]);
199 else if((offset
= patterns
[1]->lastIndexIn(line
)) >= 0)
201 if (MUtils::regexp_parse_uint32((*patterns
[1]), temp
, 5))
203 clipInfo
.setFrameSize(temp
[0], temp
[1]);
204 clipInfo
.setFrameRate(temp
[2], temp
[3]);
205 clipInfo
.setFrameCount(temp
[4]);
214 if(line
.contains("failed to load avisynth.dll", Qt::CaseInsensitive
))
216 log(tr("\nWarning: It seems that Avisynth is not currently installed/available !!!"));
218 if(line
.contains(QRegExp("couldn't convert input clip to (YV16|YV24)", Qt::CaseInsensitive
)))
220 log(tr("\nWarning: YV16 (4:2:2) and YV24 (4:4:4) color-spaces only supported in Avisynth 2.6 !!!"));
224 // ------------------------------------------------------------
226 // ------------------------------------------------------------
228 void AvisynthSource::buildCommandLine(QStringList
&cmdLine
)
230 if(!m_options
->customAvs2YUV().isEmpty())
232 cmdLine
<< splitParams(m_options
->customAvs2YUV());
235 cmdLine
<< QDir::toNativeSeparators(x264_path2ansi(m_sourceFile
, true));
239 void AvisynthSource::flushProcess(QProcess
&processInput
)
241 while(processInput
.bytesAvailable() > 0)
243 log(tr("av2y [info]: %1").arg(QString::fromUtf8(processInput
.readLine()).simplified()));
246 if(processInput
.exitCode() != EXIT_SUCCESS
)
248 const int exitCode
= processInput
.exitCode();
249 log(tr("\nWARNING: Input process exited with error (code: %1), your encode might be *incomplete* !!!").arg(QString::number(exitCode
)));
250 if((exitCode
< 0) || (exitCode
>= 32))
252 log(tr("\nIMPORTANT: The Avs2YUV process terminated abnormally. This means Avisynth or one of your Avisynth-Plugin's just crashed."));
253 log(tr("IMPORTANT: Please fix your Avisynth script and try again! If you use Avisynth-MT, try using a *stable* Avisynth instead!"));