Improved detected of source file type + EncoderInfo object can check if the given source type is supported.
This commit is contained in:
parent
1cabbdc7b5
commit
cc3d25dfce
@ -33,9 +33,9 @@ public:
|
||||
virtual QString getVariantId(const int &variant) const = 0;
|
||||
virtual QStringList getProfiles(const int &variant) const = 0;
|
||||
virtual QStringList getTunings(void) const = 0;
|
||||
virtual QStringList supportedInputFormats(void) const = 0;
|
||||
virtual QStringList supportedOutputFormats(void) const = 0;
|
||||
virtual bool isRCModeSupported(const int rcMode) const = 0;
|
||||
virtual bool isInputTypeSupported(const int format) const = 0;
|
||||
};
|
||||
|
||||
class AbstractEncoder : public AbstractTool
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "model_options.h"
|
||||
#include "model_status.h"
|
||||
#include "binaries.h"
|
||||
#include "mediainfo.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QDir>
|
||||
@ -124,15 +125,6 @@ public:
|
||||
return profiles;
|
||||
}
|
||||
|
||||
virtual QStringList supportedInputFormats(void) const
|
||||
{
|
||||
QStringList extLst;
|
||||
extLst << "avi" << "mp4" << "mkv" << "flv";
|
||||
extLst << "mpg" << "m2v" << "m2ts" << "ts";
|
||||
extLst << "wmv" << "ogm" << "vob" << "y4m";
|
||||
return extLst;
|
||||
}
|
||||
|
||||
virtual QStringList supportedOutputFormats(void) const
|
||||
{
|
||||
QStringList extLst;
|
||||
@ -153,6 +145,19 @@ public:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool isInputTypeSupported(const int format) const
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
case MediaInfo::FILETYPE_AVISYNTH:
|
||||
case MediaInfo::FILETYPE_YUV4MPEG2:
|
||||
case MediaInfo::FILETYPE_UNKNOWN:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static const X264EncoderInfo s_x264EncoderInfo;
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "model_options.h"
|
||||
#include "model_status.h"
|
||||
#include "binaries.h"
|
||||
#include "mediainfo.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QDir>
|
||||
@ -109,13 +110,6 @@ public:
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
virtual QStringList supportedInputFormats(void) const
|
||||
{
|
||||
QStringList extLst;
|
||||
extLst << "y4m";
|
||||
return extLst;
|
||||
}
|
||||
|
||||
virtual QStringList supportedOutputFormats(void) const
|
||||
{
|
||||
QStringList extLst;
|
||||
@ -136,6 +130,16 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool isInputTypeSupported(const int format) const
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
case MediaInfo::FILETYPE_YUV4MPEG2:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static const X265EncoderInfo s_x265EncoderInfo;
|
||||
|
80
src/mediainfo.cpp
Normal file
80
src/mediainfo.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Simple x264 Launcher
|
||||
// Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// http://www.gnu.org/licenses/gpl-2.0.txt
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "mediainfo.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
#include <QByteArray>
|
||||
#include <QFileInfo>
|
||||
|
||||
static const char *YUV4MPEG2 = "YUV4MPEG2";
|
||||
|
||||
int MediaInfo::analyze(const QString &fileName)
|
||||
{
|
||||
const QString suffix = QFileInfo(fileName).suffix();
|
||||
|
||||
//Try to guess Avisynth or VapourSynth from the file extension first!
|
||||
if((suffix.compare("avs", Qt::CaseInsensitive) == 0) || (suffix.compare("avsi", Qt::CaseInsensitive) == 0))
|
||||
{
|
||||
return FILETYPE_AVISYNTH;
|
||||
}
|
||||
if((suffix.compare("vpy", Qt::CaseInsensitive) == 0) || (suffix.compare("py", Qt::CaseInsensitive) == 0))
|
||||
{
|
||||
return FILETYPE_VAPOURSYNTH;
|
||||
}
|
||||
|
||||
//Check for YUV4MEPG2 format next
|
||||
if(isYuv4Mpeg(fileName))
|
||||
{
|
||||
return FILETYPE_YUV4MPEG2;
|
||||
}
|
||||
|
||||
//Unknown file type
|
||||
return FILETYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
bool MediaInfo::isYuv4Mpeg(const QString &fileName)
|
||||
{
|
||||
QFile testFile(fileName);
|
||||
|
||||
//Try to open test file
|
||||
if(!testFile.open(QIODevice::ReadOnly))
|
||||
{
|
||||
qWarning("[isYuv4Mpeg] Failed to open input file!");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Read file header
|
||||
const size_t len = strlen(YUV4MPEG2);
|
||||
QByteArray header = testFile.read(len);
|
||||
testFile.close();
|
||||
|
||||
//Did we read enough header bytes?
|
||||
if(len != header.size())
|
||||
{
|
||||
qWarning("[isYuv4Mpeg] File is too short to be analyzed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Compare YUV4MPEG2 signature
|
||||
return (memcmp(header.constData(), YUV4MPEG2, len) == 0);
|
||||
}
|
43
src/mediainfo.h
Normal file
43
src/mediainfo.h
Normal file
@ -0,0 +1,43 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Simple x264 Launcher
|
||||
// Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// http://www.gnu.org/licenses/gpl-2.0.txt
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class QString;
|
||||
|
||||
class MediaInfo
|
||||
{
|
||||
public:
|
||||
typedef enum
|
||||
{
|
||||
FILETYPE_UNKNOWN = 0,
|
||||
FILETYPE_YUV4MPEG2 = 1,
|
||||
FILETYPE_AVISYNTH = 2,
|
||||
FILETYPE_VAPOURSYNTH = 3
|
||||
}
|
||||
fileType_t;
|
||||
|
||||
static int analyze(const QString &fileName);
|
||||
|
||||
private:
|
||||
MediaInfo(void) {/*NOP*/}
|
||||
~MediaInfo(void) {/*NOP*/}
|
||||
|
||||
static bool isYuv4Mpeg(const QString &fileName);
|
||||
};
|
@ -28,6 +28,7 @@
|
||||
#include "model_sysinfo.h"
|
||||
#include "job_object.h"
|
||||
#include "binaries.h"
|
||||
#include "mediainfo.h"
|
||||
|
||||
//Encoders
|
||||
#include "encoder_factory.h"
|
||||
@ -105,21 +106,6 @@ while(0)
|
||||
} \
|
||||
while(0)
|
||||
|
||||
/*
|
||||
* Input types
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
INPUT_NATIVE = 0,
|
||||
INPUT_AVISYN = 1,
|
||||
INPUT_VAPOUR = 2
|
||||
};
|
||||
|
||||
/*
|
||||
* Static vars
|
||||
*/
|
||||
//static const char *VPS_TEST_FILE = "import vapoursynth as vs\ncore = vs.get_core()\nv = core.std.BlankClip()\nv.set_output()\n";
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor & Destructor
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -144,13 +130,19 @@ EncodeThread::EncodeThread(const QString &sourceFileName, const QString &outputF
|
||||
m_encoder = EncoderFactory::createEncoder(m_jobObject, m_options, m_sysinfo, m_preferences, m_status, &m_abort, &m_pause, &m_semaphorePaused, m_sourceFileName, m_outputFileName);
|
||||
|
||||
//Create input handler object
|
||||
switch(getInputType(QFileInfo(m_sourceFileName).suffix()))
|
||||
switch(MediaInfo::analyze(m_sourceFileName))
|
||||
{
|
||||
case INPUT_AVISYN:
|
||||
m_pipedSource = new AvisynthSource (m_jobObject, m_options, m_sysinfo, m_preferences, m_status, &m_abort, &m_pause, &m_semaphorePaused, m_sourceFileName);
|
||||
case MediaInfo::FILETYPE_AVISYNTH:
|
||||
if(m_sysinfo->hasAVSSupport())
|
||||
{
|
||||
m_pipedSource = new AvisynthSource (m_jobObject, m_options, m_sysinfo, m_preferences, m_status, &m_abort, &m_pause, &m_semaphorePaused, m_sourceFileName);
|
||||
}
|
||||
break;
|
||||
case INPUT_VAPOUR:
|
||||
m_pipedSource = new VapoursynthSource(m_jobObject, m_options, m_sysinfo, m_preferences, m_status, &m_abort, &m_pause, &m_semaphorePaused, m_sourceFileName);
|
||||
case MediaInfo::FILETYPE_VAPOURSYNTH:
|
||||
if(m_sysinfo->hasVPSSupport())
|
||||
{
|
||||
m_pipedSource = new VapoursynthSource(m_jobObject, m_options, m_sysinfo, m_preferences, m_status, &m_abort, &m_pause, &m_semaphorePaused, m_sourceFileName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -204,6 +196,11 @@ void EncodeThread::checkedRun(void)
|
||||
ExecutionStateHandler executionStateHandler;
|
||||
encode();
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
log(tr("EXCEPTION ERROR IN THREAD: ").append(QString::fromLatin1(e.what())));
|
||||
setStatus(JobStatus_Failed);
|
||||
}
|
||||
catch(char *msg)
|
||||
{
|
||||
log(tr("EXCEPTION ERROR IN THREAD: ").append(QString::fromLatin1(msg)));
|
||||
@ -404,18 +401,6 @@ void EncodeThread::setDetails(const QString &text)
|
||||
}
|
||||
}
|
||||
|
||||
int EncodeThread::getInputType(const QString &fileExt)
|
||||
{
|
||||
int type = INPUT_NATIVE;
|
||||
|
||||
if(fileExt.compare("avs", Qt::CaseInsensitive) == 0) type = INPUT_AVISYN;
|
||||
if(fileExt.compare("avsi", Qt::CaseInsensitive) == 0) type = INPUT_AVISYN;
|
||||
if(fileExt.compare("vpy", Qt::CaseInsensitive) == 0) type = INPUT_VAPOUR;
|
||||
if(fileExt.compare("py", Qt::CaseInsensitive) == 0) type = INPUT_VAPOUR;
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
QString EncodeThread::getPasslogFile(const QString &outputFile)
|
||||
{
|
||||
QFileInfo info(outputFile);
|
||||
|
@ -106,7 +106,6 @@ protected:
|
||||
void encode(void);
|
||||
|
||||
//Static functions
|
||||
static int getInputType(const QString &fileExt);
|
||||
static QString getPasslogFile(const QString &outputFile);
|
||||
|
||||
signals:
|
||||
|
@ -26,7 +26,7 @@
|
||||
#define VER_X264_MAJOR 2
|
||||
#define VER_X264_MINOR 3
|
||||
#define VER_X264_PATCH 7
|
||||
#define VER_X264_BUILD 836
|
||||
#define VER_X264_BUILD 838
|
||||
|
||||
#define VER_X264_PORTABLE_EDITION (0)
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "model_sysinfo.h"
|
||||
#include "model_recently.h"
|
||||
#include "encoder_factory.h"
|
||||
#include "mediainfo.h"
|
||||
#include "win_help.h"
|
||||
#include "win_editor.h"
|
||||
|
||||
@ -532,8 +533,9 @@ void AddJobDialog::accept(void)
|
||||
return;
|
||||
}
|
||||
|
||||
//Is the type of the source file supported? (as far as we can tell)
|
||||
if(sourceFile.suffix().compare("AVS", Qt::CaseInsensitive) == 0)
|
||||
//Is the type of the source file supported?
|
||||
const int sourceType = MediaInfo::analyze(sourceFile.canonicalFilePath());
|
||||
if(sourceType == MediaInfo::FILETYPE_AVISYNTH)
|
||||
{
|
||||
if(!m_sysinfo->hasAVSSupport())
|
||||
{
|
||||
@ -543,7 +545,7 @@ void AddJobDialog::accept(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if((sourceFile.suffix().compare("VPY", Qt::CaseInsensitive) == 0) || (sourceFile.suffix().compare("PY", Qt::CaseInsensitive) == 0))
|
||||
else if(sourceType == MediaInfo::FILETYPE_VAPOURSYNTH)
|
||||
{
|
||||
if(!m_sysinfo->hasVPSSupport())
|
||||
{
|
||||
@ -553,15 +555,11 @@ void AddJobDialog::accept(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(!encoderInfo.isInputTypeSupported(sourceType))
|
||||
{
|
||||
const QStringList inputFormats = encoderInfo.supportedInputFormats();
|
||||
if(!inputFormats.contains(sourceFile.suffix(), Qt::CaseInsensitive))
|
||||
if(QMessageBox::warning(this, tr("Unsupported input format"), tr("<nobr>The selected encoder does <b>not</b> support the selected input format!</nobr>"), tr("Abort"), tr("Ingnore (at your own risk!)")) != 1)
|
||||
{
|
||||
if(QMessageBox::warning(this, tr("Unsupported input format"), tr("<nobr>The selected encoder does <b>not</b> support the selected input format!</nobr>"), tr("Abort"), tr("Ingnore (at your own risk!)")) != 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -343,6 +343,7 @@ copy /Y "$(QTDIR)\plugins\imageformats\qgif4.dll" "$(TargetDir)\imageformats"
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)tmp\moc\moc_%(Filename).cpp;%(Outputs)</Outputs>
|
||||
</CustomBuild>
|
||||
<ClInclude Include="src\job_object.h" />
|
||||
<ClInclude Include="src\mediainfo.h" />
|
||||
<ClInclude Include="src\model_options.h" />
|
||||
<ClInclude Include="src\model_preferences.h" />
|
||||
<ClInclude Include="src\model_recently.h" />
|
||||
@ -407,6 +408,7 @@ copy /Y "$(QTDIR)\plugins\imageformats\qgif4.dll" "$(TargetDir)\imageformats"
|
||||
<ClCompile Include="src\encoder_x265.cpp" />
|
||||
<ClCompile Include="src\ipc.cpp" />
|
||||
<ClCompile Include="src\job_object.cpp" />
|
||||
<ClCompile Include="src\mediainfo.cpp" />
|
||||
<ClCompile Include="src\model_jobList.cpp" />
|
||||
<ClCompile Include="src\model_logFile.cpp" />
|
||||
<ClCompile Include="src\model_options.cpp" />
|
||||
|
@ -105,6 +105,9 @@
|
||||
<ClInclude Include="src\encoder_factory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\mediainfo.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\main.cpp">
|
||||
@ -257,6 +260,9 @@
|
||||
<ClCompile Include="src\encoder_factory.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\mediainfo.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="src\win_main.h">
|
||||
|
Loading…
Reference in New Issue
Block a user