10

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?

Fredrik Pihl
  • 44,604
  • 7
  • 83
  • 130
MarkovDmitriy
  • 165
  • 1
  • 2
  • 9

1 Answers1

30

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!

Fredrik Pihl
  • 44,604
  • 7
  • 83
  • 130
  • 2
    Based on your note: **Total num pixels (bytes) = width * height * 3 / 2** you can calculate **widthHeight = frameSize * 2 / 3;** Then you could check the common sizes for a match. Or go for the common aspect ratio of 4:3. **width = widthHeight / 3; height = widthHeight / 4; check = width * height; ASSERT(check == widthHeight);** There are, of course, other aspect ratios to check. 16:9 for high def for example. – Jesse Chisholm Sep 10 '14 at 21:32
  • You are absolutely right. My idea with this answer was just to provide some basic insight to get the OP started. You can spend a lifetime investigating all aspects of YCbCr-data :-) – Fredrik Pihl Sep 11 '14 at 08:28
  • 1
    re: lifetime - Yep. This OP is just about 4:2:0, it all changes if you're talking 4:2:2 or any of the other variations of YCbCr. And converting to other color formats (RGB) even changes if you are talking co-sited. Your answer is an excellent primer for YCbCr 4:2:0. Those who have need for the gory details of the rest are reading thick tomes. ;-D – Jesse Chisholm Dec 16 '14 at 16:54