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_vapoursynth.h"
27 #include "model_sysinfo.h"
28 #include "model_preferences.h"
34 static const unsigned int VER_X264_VSPIPE_VER = 22;
36 VapoursynthSource::VapoursynthSource(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)
38 AbstractSource(jobObject, options, sysinfo, preferences, jobStatus, abort, pause, semaphorePause, sourceFile),
39 m_sourceName("VapourSynth (vpy)"),
40 m_binaryFile(VPS_BINARY(m_sysinfo, m_preferences))
42 /*Nothing to do here*/
45 VapoursynthSource::~VapoursynthSource(void)
47 /*Nothing to do here*/
50 const QString &VapoursynthSource::getName(void)
55 // ------------------------------------------------------------
57 // ------------------------------------------------------------
59 bool VapoursynthSource::isSourceAvailable()
61 if(!(m_sysinfo->hasVPSSupport() && (!m_sysinfo->getVPSPath().isEmpty()) && QFileInfo(VPS_BINARY(m_sysinfo, m_preferences)).isFile()))
63 log(tr("\nVPY INPUT REQUIRES VAPOURSYNTH, BUT IT IS *NOT* AVAILABLE !!!"));
69 void VapoursynthSource::checkVersion_init(QList<QRegExp*> &patterns, QStringList &cmdLine)
71 cmdLine << "-version";
72 patterns << new QRegExp("\\bVapourSynth\\b", Qt::CaseInsensitive);
73 patterns << new QRegExp("\\bCore\\s+r(\\d+)\\b", Qt::CaseInsensitive);
74 patterns << new QRegExp("\\bAPI\\s+r(\\d+)\\b", Qt::CaseInsensitive);
77 void VapoursynthSource::checkVersion_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &coreVers, unsigned int &revision, bool &modified)
81 if((offset = patterns[1]->lastIndexIn(line)) >= 0)
84 unsigned int temp = patterns[1]->cap(1).toUInt(&ok);
85 if(ok) revision = temp;
87 else if((offset = patterns[2]->lastIndexIn(line)) >= 0)
90 unsigned int temp = patterns[2]->cap(1).toUInt(&ok);
91 if(ok) coreVers = temp;
100 void VapoursynthSource::printVersion(const unsigned int &revision, const bool &modified)
102 log(tr("\nVapourSynth version: r%1 (API r%2)").arg(QString::number(revision % REV_MULT), QString::number(revision / REV_MULT)));
105 bool VapoursynthSource::isVersionSupported(const unsigned int &revision, const bool &modified)
107 if((revision % REV_MULT) < VER_X264_VSPIPE_VER)
109 log(tr("\nERROR: Your version of VapourSynth is unsupported (requires version r%1 or newer").arg(QString::number(VER_X264_VSPIPE_VER)));
110 log(tr("You can find the latest VapourSynth version at: http://www.vapoursynth.com/"));
116 // ------------------------------------------------------------
117 // Check Source Properties
118 // ------------------------------------------------------------
120 void VapoursynthSource::checkSourceProperties_init(QList<QRegExp*> &patterns, QStringList &cmdLine)
122 cmdLine << QDir::toNativeSeparators(x264_path2ansi(m_sourceFile, true));
123 cmdLine << "-" << "-info";
125 patterns << new QRegExp("\\bFrames:\\s+(\\d+)\\b");
126 patterns << new QRegExp("\\bWidth:\\s+(\\d+)\\b");
127 patterns << new QRegExp("\\bHeight:\\s+(\\d+)\\b");
128 patterns << new QRegExp("\\bFPS:\\s+(\\d+)\\b");
129 patterns << new QRegExp("\\bFPS:\\s+(\\d+)/(\\d+)\\b");
132 void VapoursynthSource::checkSourceProperties_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &frames, unsigned int &fSizeW, unsigned int &fSizeH, unsigned int &fpsNom, unsigned int &fpsDen)
136 if((offset = patterns[0]->lastIndexIn(line)) >= 0)
139 unsigned int temp = patterns[0]->cap(1).toUInt(&ok);
140 if(ok) frames = temp;
142 if((offset = patterns[1]->lastIndexIn(line)) >= 0)
145 unsigned int temp =patterns[1]->cap(1).toUInt(&ok);
146 if(ok) fSizeW = temp;
148 if((offset = patterns[2]->lastIndexIn(line)) >= 0)
151 unsigned int temp = patterns[2]->cap(1).toUInt(&ok);
152 if(ok) fSizeH = temp;
154 if((offset = patterns[3]->lastIndexIn(line)) >= 0)
157 unsigned int temp = patterns[3]->cap(1).toUInt(&ok);
158 if(ok) fpsNom = temp;
160 if((offset = patterns[4]->lastIndexIn(line)) >= 0)
162 bool ok1 = false, ok2 = false;
163 unsigned int temp1 = patterns[4]->cap(1).toUInt(&ok1);
164 unsigned int temp2 = patterns[4]->cap(2).toUInt(&ok2);
178 // ------------------------------------------------------------
179 // Check Source Properties
180 // ------------------------------------------------------------
182 void VapoursynthSource::buildCommandLine(QStringList &cmdLine)
184 cmdLine << QDir::toNativeSeparators(x264_path2ansi(m_sourceFile, true));
185 cmdLine << "-" << "-y4m";
188 void VapoursynthSource::flushProcess(QProcess &processInput)
190 while(processInput.bytesAvailable() > 0)
192 log(tr("vpyp [info]: %1").arg(QString::fromUtf8(processInput.readLine()).simplified()));
195 if(processInput.exitCode() != EXIT_SUCCESS)
197 const int exitCode = processInput.exitCode();
198 log(tr("\nWARNING: Input process exited with error (code: %1), your encode might be *incomplete* !!!").arg(QString::number(exitCode)));
199 if((exitCode < 0) || (exitCode >= 32))
201 log(tr("\nIMPORTANT: The Vapoursynth process terminated abnormally. This means Vapoursynth or one of your Vapoursynth-Plugin's just crashed."));