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 ///////////////////////////////////////////////////////////////////////////////
22 #include "mediainfo.h"
29 static const char *YUV4MPEG2 = "YUV4MPEG2";
31 int MediaInfo::analyze(const QString &fileName)
33 const QString suffix = QFileInfo(fileName).suffix();
35 //Try to guess Avisynth or VapourSynth from the file extension first!
36 if((suffix.compare("avs", Qt::CaseInsensitive) == 0) || (suffix.compare("avsi", Qt::CaseInsensitive) == 0))
38 return FILETYPE_AVISYNTH;
40 if((suffix.compare("vpy", Qt::CaseInsensitive) == 0) || (suffix.compare("py", Qt::CaseInsensitive) == 0))
42 return FILETYPE_VAPOURSYNTH;
45 //Check for YUV4MEPG2 format next
46 if(isYuv4Mpeg(fileName))
48 return FILETYPE_YUV4MPEG2;
52 return FILETYPE_UNKNOWN;
55 bool MediaInfo::isYuv4Mpeg(const QString &fileName)
57 QFile testFile(fileName);
59 //Try to open test file
60 if(!testFile.open(QIODevice::ReadOnly))
62 qWarning("[isYuv4Mpeg] Failed to open input file!");
67 const size_t len = strlen(YUV4MPEG2);
68 QByteArray header = testFile.read(len);
71 //Did we read enough header bytes?
72 if(len != header.size())
74 qWarning("[isYuv4Mpeg] File is too short to be analyzed!");
78 //Compare YUV4MPEG2 signature
79 return (memcmp(header.constData(), YUV4MPEG2, len) == 0);