OSDN Git Service

Fixed a typo.
[x264-launcher/x264-launcher.git] / src / mediainfo.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 #include "mediainfo.h"
23
24 #include <QString>
25 #include <QFile>
26 #include <QByteArray>
27 #include <QFileInfo>
28
29 static const char *YUV4MPEG2 = "YUV4MPEG2";
30
31 int MediaInfo::analyze(const QString &fileName)
32 {
33         const QString suffix = QFileInfo(fileName).suffix();
34
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))
37         {
38                 return FILETYPE_AVISYNTH;
39         }
40         if((suffix.compare("vpy", Qt::CaseInsensitive) == 0) || (suffix.compare("py", Qt::CaseInsensitive) == 0))
41         {
42                 return FILETYPE_VAPOURSYNTH;
43         }
44
45         //Check for YUV4MEPG2 format next
46         if(isYuv4Mpeg(fileName))
47         {
48                 return FILETYPE_YUV4MPEG2;
49         }
50
51         //Unknown file type
52         return FILETYPE_UNKNOWN;
53 }
54
55 bool MediaInfo::isYuv4Mpeg(const QString &fileName)
56 {
57         QFile testFile(fileName);
58
59         //Try to open test file
60         if(!testFile.open(QIODevice::ReadOnly))
61         {
62                 qWarning("[isYuv4Mpeg] Failed to open input file!");
63                 return false;
64         }
65
66         //Read file header
67         const size_t len = strlen(YUV4MPEG2);
68         QByteArray header = testFile.read(len);
69         testFile.close();
70
71         //Did we read enough header bytes?
72         if(len != header.size())
73         {
74                 qWarning("[isYuv4Mpeg] File is too short to be analyzed!");
75                 return false;
76         }
77
78         //Compare YUV4MPEG2 signature
79         return (memcmp(header.constData(), YUV4MPEG2, len) == 0);
80 }