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

Method parseY4MFile

YUViewLib/src/playlistitem/playlistItemRawFile.cpp:205–422  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

203}
204
205bool playlistItemRawFile::parseY4MFile()
206{
207 // Read a chunck of data from the file. Thecnically, the header can be arbitrarily long, but in
208 // practice, 512 bytes should cover the length of all headers
209 QByteArray rawData;
210 this->dataSource.readBytes(rawData, 0, 512);
211
212 DEBUG_RAWFILE("playlistItemRawFile::parseY4MFile Read Y4M");
213
214 // A Y4M file must start with the signature string "YUV4MPEG2 ".
215 if (rawData.left(10) != "YUV4MPEG2 ")
216 return setError("Y4M File header does not start with YUV4MPEG2 header signature.");
217
218 DEBUG_RAWFILE("playlistItemRawFile::parseY4MFile Found signature YUV4MPEG2");
219
220 // Next, there can be any number of parameters. Each paramter starts with a space.
221 // The only requirement is, that width, height and framerate are specified.
222 int64_t offset = 9;
223 unsigned width = 0;
224 unsigned height = 0;
225 auto format =
226 video::yuv::PixelFormatYUV(video::yuv::Subsampling::YUV_420, 8, video::yuv::PlaneOrder::YUV);
227
228 while (rawData.at(offset++) == ' ')
229 {
230 char parameterIndicator = rawData.at(offset++);
231 if (parameterIndicator == 'W' || parameterIndicator == 'H')
232 {
233 QByteArray number;
234 auto c = rawData.at(offset);
235 while (QChar(c).isDigit())
236 {
237 number.append(c);
238 c = rawData.at(++offset);
239 }
240
241 bool ok = true;
242 if (parameterIndicator == 'W')
243 {
244 width = unsigned(number.toInt(&ok));
245 if (!ok)
246 return setError("Error parsing the Y4M header: Invalid width value.");
247 }
248 if (parameterIndicator == 'H')
249 {
250 height = unsigned(number.toInt(&ok));
251 if (!ok)
252 return setError("Error parsing the Y4M header: Invalid height value.");
253 }
254 DEBUG_RAWFILE("playlistItemRawFile::parseY4MFile Read frame size " << width << "x" << height);
255 }
256 else if (parameterIndicator == 'F')
257 {
258 // The format is: "25:1" (nom:den)
259 QByteArray nominator;
260 auto c = rawData.at(offset);
261 while (QChar(c).isDigit())
262 {

Callers 1

playlistItemRawFileMethod · 0.95

Calls 13

PixelFormatYUVClass · 0.85
SizeClass · 0.85
appendMethod · 0.80
getFileSizeMethod · 0.80
setPixelFormatYUVMethod · 0.80
getYUVVideoMethod · 0.80
readBytesMethod · 0.45
atMethod · 0.45
getNameMethod · 0.45
sizeMethod · 0.45
getSubsamplingMethod · 0.45
getBitsPerSampleMethod · 0.45

Tested by

no test coverage detected