diff --git a/src/encoder_abstract.h b/src/encoder_abstract.h index ccc5672..83a6fe5 100644 --- a/src/encoder_abstract.h +++ b/src/encoder_abstract.h @@ -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 diff --git a/src/encoder_x264.cpp b/src/encoder_x264.cpp index 1f1ce9a..8c8ae6b 100644 --- a/src/encoder_x264.cpp +++ b/src/encoder_x264.cpp @@ -25,6 +25,7 @@ #include "model_options.h" #include "model_status.h" #include "binaries.h" +#include "mediainfo.h" #include #include @@ -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; diff --git a/src/encoder_x265.cpp b/src/encoder_x265.cpp index 97645b6..d89fe4f 100644 --- a/src/encoder_x265.cpp +++ b/src/encoder_x265.cpp @@ -25,6 +25,7 @@ #include "model_options.h" #include "model_status.h" #include "binaries.h" +#include "mediainfo.h" #include #include @@ -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; diff --git a/src/mediainfo.cpp b/src/mediainfo.cpp new file mode 100644 index 0000000..cdbe929 --- /dev/null +++ b/src/mediainfo.cpp @@ -0,0 +1,80 @@ +/////////////////////////////////////////////////////////////////////////////// +// Simple x264 Launcher +// Copyright (C) 2004-2014 LoRd_MuldeR +// +// 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 +#include +#include +#include + +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); +} diff --git a/src/mediainfo.h b/src/mediainfo.h new file mode 100644 index 0000000..254750d --- /dev/null +++ b/src/mediainfo.h @@ -0,0 +1,43 @@ +/////////////////////////////////////////////////////////////////////////////// +// Simple x264 Launcher +// Copyright (C) 2004-2014 LoRd_MuldeR +// +// 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); +}; diff --git a/src/thread_encode.cpp b/src/thread_encode.cpp index 86d1ce4..cee4bd0 100644 --- a/src/thread_encode.cpp +++ b/src/thread_encode.cpp @@ -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); diff --git a/src/thread_encode.h b/src/thread_encode.h index 673c845..82f53bc 100644 --- a/src/thread_encode.h +++ b/src/thread_encode.h @@ -106,7 +106,6 @@ protected: void encode(void); //Static functions - static int getInputType(const QString &fileExt); static QString getPasslogFile(const QString &outputFile); signals: diff --git a/src/version.h b/src/version.h index 2d70e12..d06b6ec 100644 --- a/src/version.h +++ b/src/version.h @@ -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) diff --git a/src/win_addJob.cpp b/src/win_addJob.cpp index 8efb256..9f5f38b 100644 --- a/src/win_addJob.cpp +++ b/src/win_addJob.cpp @@ -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("The selected encoder does not support the selected input format!"), tr("Abort"), tr("Ingnore (at your own risk!)")) != 1) { - if(QMessageBox::warning(this, tr("Unsupported input format"), tr("The selected encoder does not support the selected input format!"), tr("Abort"), tr("Ingnore (at your own risk!)")) != 1) - { - return; - } + return; } } diff --git a/x264_launcher_MSVC2013.vcxproj b/x264_launcher_MSVC2013.vcxproj index ac189f3..3976c95 100644 --- a/x264_launcher_MSVC2013.vcxproj +++ b/x264_launcher_MSVC2013.vcxproj @@ -343,6 +343,7 @@ copy /Y "$(QTDIR)\plugins\imageformats\qgif4.dll" "$(TargetDir)\imageformats" $(SolutionDir)tmp\moc\moc_%(Filename).cpp;%(Outputs) + @@ -407,6 +408,7 @@ copy /Y "$(QTDIR)\plugins\imageformats\qgif4.dll" "$(TargetDir)\imageformats" + diff --git a/x264_launcher_MSVC2013.vcxproj.filters b/x264_launcher_MSVC2013.vcxproj.filters index 4fe4221..32f450b 100644 --- a/x264_launcher_MSVC2013.vcxproj.filters +++ b/x264_launcher_MSVC2013.vcxproj.filters @@ -105,6 +105,9 @@ Header Files + + Header Files + @@ -257,6 +260,9 @@ Source Files + + Source Files +