How to find out resolution and count of frames in YUV 4:2:0 file?

yuv
MarkovDmitriy picture MarkovDmitriy · Oct 30, 2013 · Viewed 12.2k times · Source

How to find out resolution and count of frames in YUV 4:2:0 file if i know how many pixel(luma samples) in the image?

Answer

Fredrik Pihl picture Fredrik Pihl · Oct 30, 2013

YUV 4:2:0 planar looks like this:

----------------------
|     Y      | Cb|Cr |
----------------------

where:

Y = width x height pixels (bytes)
Cb = Y / 4 pixels (bytes)
Cr = Y / 4 pixels (bytes)

Total num pixels (bytes) = width * height * 3 / 2

This is how pixels are placed in 4:2:0 sub-sampling:

420

As you can see, each chroma value is shared between 4 luma-pixels.

Basically, the only thing you can do is to see which frame-sizes divides the total file-size evenly.

As an example, consider the classic forman-clip, which you can download from http://trace.eas.asu.edu/yuv/foreman/foreman_cif.7z

The size of that clip is 45619200 bytes. How do one get the dimensions and number of frames from that? Try different resolutions!

is it SDTV?

In [7]: 45619200 / float(720*576*3/2)
Out[7]: 73.33333333333333

nope!

is it QCIF?

In [8]: 45619200 / float(176*144*3/2)
Out[8]: 1200.0

might be...

is it CIF?

In [9]: 45619200 / float(352*288*3/2)
Out[9]: 300.0

might be...

Only way to find out is trying to display it.

Let's try QCIF

wring

that doesn't look right. Lets try CIF

right

Bingo!