OSDN Git Service

Bump version.
[x264-launcher/x264-launcher.git] / src / source_vapoursynth.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2016 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.
14 //
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.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #pragma once
23
24 #include "source_vapoursynth.h"
25
26 #include "global.h"
27
28 #include <QDir>
29 #include <QProcess>
30
31 static const unsigned int VER_X264_VSPIPE_API =  3;
32 static const unsigned int VER_X264_VSPIPE_VER = 24;
33
34 // ------------------------------------------------------------
35 // Encoder Info
36 // ------------------------------------------------------------
37
38 class VapoursyntSourceInfo : public AbstractSourceInfo
39 {
40 public:
41         virtual QString getBinaryPath(const SysinfoModel *sysinfo, const bool& x64) const
42         {
43                 return QString("%1/core%2/vspipe.exe").arg(sysinfo->getVPSPath(), (x64 ? "64" : "32"));
44         }
45 };
46
47 static const VapoursyntSourceInfo s_vapoursynthEncoderInfo;
48
49 const AbstractSourceInfo &VapoursynthSource::getSourceInfo(void)
50 {
51         return s_vapoursynthEncoderInfo;
52 }
53
54 // ------------------------------------------------------------
55 // Constructor & Destructor
56 // ------------------------------------------------------------
57
58 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)
59 :
60         AbstractSource(jobObject, options, sysinfo, preferences, jobStatus, abort, pause, semaphorePause, sourceFile)
61 {
62         /*Nothing to do here*/
63 }
64
65 VapoursynthSource::~VapoursynthSource(void)
66 {
67         /*Nothing to do here*/
68 }
69
70 QString VapoursynthSource::getName(void) const
71 {
72         return tr("VapourSynth (vpy)");
73 }
74
75 // ------------------------------------------------------------
76 // Check Version
77 // ------------------------------------------------------------
78
79 bool VapoursynthSource::isSourceAvailable()
80 {
81         if(!(m_sysinfo->hasVapourSynth() && (!m_sysinfo->getVPSPath().isEmpty()) && QFileInfo(getBinaryPath()).isFile()))
82         {
83                 log(tr("\nVPY INPUT REQUIRES VAPOURSYNTH, BUT IT IS *NOT* AVAILABLE !!!"));
84                 return false;
85         }
86         return true;
87 }
88
89 void VapoursynthSource::checkVersion_init(QList<QRegExp*> &patterns, QStringList &cmdLine)
90 {
91         cmdLine << "--version";
92         patterns << new QRegExp("\\bVapourSynth\\b", Qt::CaseInsensitive);
93         patterns << new QRegExp("\\bCore\\s+r(\\d+)\\b", Qt::CaseInsensitive);
94         patterns << new QRegExp("\\bAPI\\s+r(\\d+)\\b", Qt::CaseInsensitive);
95 }
96
97 void VapoursynthSource::checkVersion_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &core, unsigned int &build, bool &modified)
98 {
99         int offset = -1;
100
101         if((offset = patterns[1]->lastIndexIn(line)) >= 0)
102         {
103                 bool ok = false;
104                 unsigned int temp = patterns[1]->cap(1).toUInt(&ok);
105                 if(ok) build = temp;
106         }
107         else if((offset = patterns[2]->lastIndexIn(line)) >= 0)
108         {
109                 bool ok = false;
110                 unsigned int temp = patterns[2]->cap(1).toUInt(&ok);
111                 if(ok) core = temp;
112         }
113
114         if(!line.isEmpty())
115         {
116                 log(line);
117         }
118 }
119
120 QString VapoursynthSource::printVersion(const unsigned int &revision, const bool &modified)
121 {
122         unsigned int core, build;
123         splitRevision(revision, core, build);
124
125         return tr("\nVapourSynth version: r%1 (API r%2)").arg(QString::number(build), QString::number(core));
126 }
127
128 bool VapoursynthSource::isVersionSupported(const unsigned int &revision, const bool &modified)
129 {
130         unsigned int core, build;
131         splitRevision(revision, core, build);
132
133         if((build < VER_X264_VSPIPE_VER) || (core < VER_X264_VSPIPE_API))
134         {
135                 
136                 if(core < VER_X264_VSPIPE_API)
137                 {
138                         log(tr("\nERROR: Your version of VapourSynth is unsupported! (requires API r%1 or newer)").arg(QString::number(VER_X264_VSPIPE_API)));
139                 }
140                 if(build < VER_X264_VSPIPE_VER)
141                 {
142                         log(tr("\nERROR: Your version of VapourSynth is unsupported! (requires version r%1 or newer)").arg(QString::number(VER_X264_VSPIPE_VER)));
143                 }
144                 log(tr("You can find the latest VapourSynth version at: http://www.vapoursynth.com/"));
145                 return false;
146         }
147
148         if(core != VER_X264_VSPIPE_API)
149         {
150                 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)));
151         }
152
153         return true;
154 }
155
156 // ------------------------------------------------------------
157 // Check Source Properties
158 // ------------------------------------------------------------
159
160 void VapoursynthSource::checkSourceProperties_init(QList<QRegExp*> &patterns, QStringList &cmdLine)
161 {
162         cmdLine << "--info";
163         cmdLine << QDir::toNativeSeparators(x264_path2ansi(m_sourceFile, true));
164         cmdLine << "-";
165
166         patterns << new QRegExp("\\bFrames:\\s+(\\d+)\\b");
167         patterns << new QRegExp("\\bWidth:\\s+(\\d+)\\b");
168         patterns << new QRegExp("\\bHeight:\\s+(\\d+)\\b");
169         patterns << new QRegExp("\\bFPS:\\s+(\\d+)\\b");
170         patterns << new QRegExp("\\bFPS:\\s+(\\d+)/(\\d+)\\b");
171 }
172
173 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)
174 {
175         int offset = -1;
176
177         if((offset = patterns[0]->lastIndexIn(line)) >= 0)
178         {
179                 bool ok = false;
180                 unsigned int temp = patterns[0]->cap(1).toUInt(&ok);
181                 if(ok) frames = temp;
182         }
183         if((offset = patterns[1]->lastIndexIn(line)) >= 0)
184         {
185                 bool ok = false;
186                 unsigned int temp =patterns[1]->cap(1).toUInt(&ok);
187                 if(ok) fSizeW = temp;
188         }
189         if((offset = patterns[2]->lastIndexIn(line)) >= 0)
190         {
191                 bool ok = false;
192                 unsigned int temp = patterns[2]->cap(1).toUInt(&ok);
193                 if(ok) fSizeH = temp;
194         }
195         if((offset = patterns[3]->lastIndexIn(line)) >= 0)
196         {
197                 bool ok = false;
198                 unsigned int temp = patterns[3]->cap(1).toUInt(&ok);
199                 if(ok) fpsNom = temp;
200         }
201         if((offset = patterns[4]->lastIndexIn(line)) >= 0)
202         {
203                 bool ok1 = false, ok2 = false;
204                 unsigned int temp1 = patterns[4]->cap(1).toUInt(&ok1);
205                 unsigned int temp2 = patterns[4]->cap(2).toUInt(&ok2);
206                 if(ok1 && ok2)
207                 {
208                         fpsNom = temp1;
209                         fpsDen = temp2;
210                 }
211         }
212
213         if(!line.isEmpty())
214         {
215                 log(line);
216         }
217 }
218
219 // ------------------------------------------------------------
220 // Check Source Properties
221 // ------------------------------------------------------------
222
223 void VapoursynthSource::buildCommandLine(QStringList &cmdLine)
224 {
225         cmdLine << "--y4m";
226         cmdLine << QDir::toNativeSeparators(x264_path2ansi(m_sourceFile, true));
227         cmdLine << "-";
228 }
229
230 void VapoursynthSource::flushProcess(QProcess &processInput)
231 {
232         while(processInput.bytesAvailable() > 0)
233         {
234                 log(tr("vpyp [info]: %1").arg(QString::fromUtf8(processInput.readLine()).simplified()));
235         }
236         
237         if(processInput.exitCode() != EXIT_SUCCESS)
238         {
239                 const int exitCode = processInput.exitCode();
240                 log(tr("\nWARNING: Input process exited with error (code: %1), your encode might be *incomplete* !!!").arg(QString::number(exitCode)));
241                 if((exitCode < 0) || (exitCode >= 32))
242                 {
243                         log(tr("\nIMPORTANT: The Vapoursynth process terminated abnormally. This means Vapoursynth or one of your Vapoursynth-Plugin's just crashed."));
244                 }
245         }
246 }