Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

yuv

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?

like image 326
MarkovDmitriy Avatar asked Oct 30 '13 08:10

MarkovDmitriy


1 Answers

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!

like image 120
Fredrik Pihl Avatar answered Oct 12 '22 22:10

Fredrik Pihl