1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2015 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_API
= 3;
35 static const unsigned int VER_X264_VSPIPE_VER
= 24;
37 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
)
39 AbstractSource(jobObject
, options
, sysinfo
, preferences
, jobStatus
, abort
, pause
, semaphorePause
, sourceFile
),
40 m_sourceName("VapourSynth (vpy)"),
41 m_binaryFile(VPS_BINARY(m_sysinfo
, m_preferences
))
43 /*Nothing to do here*/
46 VapoursynthSource::~VapoursynthSource(void)
48 /*Nothing to do here*/
51 const QString
&VapoursynthSource::getName(void)
56 // ------------------------------------------------------------
58 // ------------------------------------------------------------
60 bool VapoursynthSource::isSourceAvailable()
62 if(!(m_sysinfo
->hasVapourSynth() && (!m_sysinfo
->getVPSPath().isEmpty()) && QFileInfo(VPS_BINARY(m_sysinfo
, m_preferences
)).isFile()))
64 log(tr("\nVPY INPUT REQUIRES VAPOURSYNTH, BUT IT IS *NOT* AVAILABLE !!!"));
70 void VapoursynthSource::checkVersion_init(QList
<QRegExp
*> &patterns
, QStringList
&cmdLine
)
72 cmdLine
<< "--version";
73 patterns
<< new QRegExp("\\bVapourSynth\\b", Qt::CaseInsensitive
);
74 patterns
<< new QRegExp("\\bCore\\s+r(\\d+)\\b", Qt::CaseInsensitive
);
75 patterns
<< new QRegExp("\\bAPI\\s+r(\\d+)\\b", Qt::CaseInsensitive
);
78 void VapoursynthSource::checkVersion_parseLine(const QString
&line
, QList
<QRegExp
*> &patterns
, unsigned int &core
, unsigned int &build
, bool &modified
)
82 if((offset
= patterns
[1]->lastIndexIn(line
)) >= 0)
85 unsigned int temp
= patterns
[1]->cap(1).toUInt(&ok
);
88 else if((offset
= patterns
[2]->lastIndexIn(line
)) >= 0)
91 unsigned int temp
= patterns
[2]->cap(1).toUInt(&ok
);
101 QString
VapoursynthSource::printVersion(const unsigned int &revision
, const bool &modified
)
103 unsigned int core
, build
;
104 splitRevision(revision
, core
, build
);
106 return tr("\nVapourSynth version: r%1 (API r%2)").arg(QString::number(build
), QString::number(core
));
109 bool VapoursynthSource::isVersionSupported(const unsigned int &revision
, const bool &modified
)
111 unsigned int core
, build
;
112 splitRevision(revision
, core
, build
);
114 if((build
< VER_X264_VSPIPE_VER
) || (core
< VER_X264_VSPIPE_API
))
117 if(core
< VER_X264_VSPIPE_API
)
119 log(tr("\nERROR: Your version of VapourSynth is unsupported! (requires API r%1 or newer)").arg(QString::number(VER_X264_VSPIPE_API
)));
121 if(build
< VER_X264_VSPIPE_VER
)
123 log(tr("\nERROR: Your version of VapourSynth is unsupported! (requires version r%1 or newer)").arg(QString::number(VER_X264_VSPIPE_VER
)));
125 log(tr("You can find the latest VapourSynth version at: http://www.vapoursynth.com/"));
129 if(core
!= VER_X264_VSPIPE_API
)
131 log(tr("\nWARNING: Running with an unknown VapourSynth API version, problem may appear! (this application works best with API r%1)").arg(QString::number(VER_X264_VSPIPE_API
)));
137 // ------------------------------------------------------------
138 // Check Source Properties
139 // ------------------------------------------------------------
141 void VapoursynthSource::checkSourceProperties_init(QList
<QRegExp
*> &patterns
, QStringList
&cmdLine
)
144 cmdLine
<< QDir::toNativeSeparators(x264_path2ansi(m_sourceFile
, true));
147 patterns
<< new QRegExp("\\bFrames:\\s+(\\d+)\\b");
148 patterns
<< new QRegExp("\\bWidth:\\s+(\\d+)\\b");
149 patterns
<< new QRegExp("\\bHeight:\\s+(\\d+)\\b");
150 patterns
<< new QRegExp("\\bFPS:\\s+(\\d+)\\b");
151 patterns
<< new QRegExp("\\bFPS:\\s+(\\d+)/(\\d+)\\b");
154 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
)
158 if((offset
= patterns
[0]->lastIndexIn(line
)) >= 0)
161 unsigned int temp
= patterns
[0]->cap(1).toUInt(&ok
);
162 if(ok
) frames
= temp
;
164 if((offset
= patterns
[1]->lastIndexIn(line
)) >= 0)
167 unsigned int temp
=patterns
[1]->cap(1).toUInt(&ok
);
168 if(ok
) fSizeW
= temp
;
170 if((offset
= patterns
[2]->lastIndexIn(line
)) >= 0)
173 unsigned int temp
= patterns
[2]->cap(1).toUInt(&ok
);
174 if(ok
) fSizeH
= temp
;
176 if((offset
= patterns
[3]->lastIndexIn(line
)) >= 0)
179 unsigned int temp
= patterns
[3]->cap(1).toUInt(&ok
);
180 if(ok
) fpsNom
= temp
;
182 if((offset
= patterns
[4]->lastIndexIn(line
)) >= 0)
184 bool ok1
= false, ok2
= false;
185 unsigned int temp1
= patterns
[4]->cap(1).toUInt(&ok1
);
186 unsigned int temp2
= patterns
[4]->cap(2).toUInt(&ok2
);
200 // ------------------------------------------------------------
201 // Check Source Properties
202 // ------------------------------------------------------------
204 void VapoursynthSource::buildCommandLine(QStringList
&cmdLine
)
207 cmdLine
<< QDir::toNativeSeparators(x264_path2ansi(m_sourceFile
, true));
211 void VapoursynthSource::flushProcess(QProcess
&processInput
)
213 while(processInput
.bytesAvailable() > 0)
215 log(tr("vpyp [info]: %1").arg(QString::fromUtf8(processInput
.readLine()).simplified()));
218 if(processInput
.exitCode() != EXIT_SUCCESS
)
220 const int exitCode
= processInput
.exitCode();
221 log(tr("\nWARNING: Input process exited with error (code: %1), your encode might be *incomplete* !!!").arg(QString::number(exitCode
)));
222 if((exitCode
< 0) || (exitCode
>= 32))
224 log(tr("\nIMPORTANT: The Vapoursynth process terminated abnormally. This means Vapoursynth or one of your Vapoursynth-Plugin's just crashed."));