MCPcopy Create free account
hub / github.com/IENT/YUView / guessFormatFromFilename

Method guessFormatFromFilename

YUViewLib/src/filesource/FileSource.cpp:145–303  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143}
144
145FileSource::fileFormat_t FileSource::guessFormatFromFilename() const
146{
147 FileSource::fileFormat_t format;
148
149 // We are going to check two strings (one after the other) for indicators on the frames size, fps
150 // and bit depth. 1: The file name, 2: The folder name that the file is contained in.
151
152 auto dirName = this->fileInfo.absoluteDir().dirName();
153 auto fileName = this->fileInfo.fileName();
154 if (fileName.isEmpty())
155 return format;
156
157 for (auto const &name : {fileName, dirName})
158 {
159 // First, we will try to get a frame size from the name
160 if (!format.frameSize.isValid())
161 {
162 // The regular expressions to match. They are sorted from most detailed to least so that the
163 // most detailed ones are tested first.
164 auto regExprList =
165 QStringList()
166 << "([0-9]+)(?:x|X|\\*)([0-9]+)_([0-9]+)(?:Hz)?_([0-9]+)b?[\\._]" // Something_2160x1440_60_8_more.yuv
167 // or
168 // Something_2160x1440_60_8b.yuv
169 // or
170 // Something_2160x1440_60Hz_8_more.yuv
171 << "([0-9]+)(?:x|X|\\*)([0-9]+)_([0-9]+)(?:Hz)?[\\._]" // Something_2160x1440_60_more.yuv
172 // or Something_2160x1440_60.yuv
173 << "([0-9]+)(?:x|X|\\*)([0-9]+)[\\._]"; // Something_2160x1440_more.yuv or
174 // Something_2160x1440.yuv
175
176 for (auto regExpStr : regExprList)
177 {
178 QRegularExpression exp(regExpStr);
179 auto match = exp.match(name);
180 if (match.hasMatch())
181 {
182 auto widthString = match.captured(1);
183 auto heightString = match.captured(2);
184 format.frameSize = Size(widthString.toInt(), heightString.toInt());
185
186 auto rateString = match.captured(3);
187 if (!rateString.isEmpty())
188 format.frameRate = rateString.toDouble();
189
190 auto bitDepthString = match.captured(4);
191 if (!bitDepthString.isEmpty())
192 format.bitDepth = bitDepthString.toUInt();
193
194 break; // Don't check the following expressions
195 }
196 }
197 }
198
199 // try resolution indicators with framerate: "1080p50", "720p24" ...
200 if (!format.frameSize.isValid())
201 {
202 QRegularExpression rx1080p("1080p([0-9]+)");

Callers 2

setFormatFromFileNameMethod · 0.80

Calls 4

SizeClass · 0.85
containsMethod · 0.80
isEmptyMethod · 0.45
isValidMethod · 0.45

Tested by 1