# Raw YUY2 to YV12 format?

1. Hi guys my 1st post.
Would any of you know how to convert YUY2 to YV12 format.

Currently I have a byte array which contains YUY2 data.
The resolution should be 704x576.
The byte array is of size - 811008. Should 704x576 not be 45504.

Is there any code samples or an algorithm to do this?

Many thanks...
Al.
2. I think you meant to type 405504 but YUY2 is two bytes per pixel. 704*576*2 = 811008.

YUY2 to YV12 is pretty simple. You should be able to figure it out from information at fourcc.org:

http://fourcc.org/yuv.php

Be sure to take into account interlacing if your output will be interlaced YV12.
3. Ok so if I have these YUY2 bytes - YUYV YUYV
If I convert them to YV12 bytes should I have YYYYVU?
4. Not exactly. YV12 is a planar format. You'll end up with three arrays, one of Y at the full resolution, followed by one of the V at half (both dimensions) resolution, and one of the U at half resolution.

four YUY2 pixels (2x2 array):

Code:
```Y(0,0) U(0,0) Y(0,1) V(0,0)
Y(1,0) U(1,0) Y(1,1) V(1,0)```
to four YV12 pixels (2x2 array + 1x1 array + 1x1 array):

Code:
```Y(0,0) Y(0,1)
Y(1,0) Y(1,1)

(V(0,0) + V(1,0)) / 2

(U(0,0) + U(1,0)) / 2```

http://avisynth.org/mediawiki/Sampling
5. Should the last line read (U(0,0) + U(1,0)) / 2?
6. Yes, typo. Fixed it.
7. Would I be correct in assuming that after the conversion using the above resolution of 704*576 I will have these array sizes

Y - 405504 bytes
V - 101376 bytes
U - 101376 bytes
8. Originally Posted by allyli2007
Would I be correct in assuming that after the conversion using the above resolution of 704*576 I will have these array sizes

Y - 405504 bytes
V - 101376 bytes
U - 101376 bytes
Yes.
9. Afternoon allyli2007,

Some time ago, I did some demonstrations** of the layout and posted some raw yuv
images of those that I engineered into the tool. It was designed only to spit out the yuv
images in binary format. And to open or import them in video editor like AVIsynth required
one of their plugins. It was this method that I used to test our my tool's success not to
mention, my understanding and correct coding, etc.

I also wrote a tiny calculator to help me understand the Luma/Chroma placement, but at
some point, I bOrked it and haven't found the energy to fix it. Maybe I should. Hmm.. I
remember starting out with just a simple calculation (resoution based) and got the chroma
size, and then the chroma playcement, and then.. Well, maybe later. Anyway.

Here's an example of something that I posted two years ago from the last response I made
on the subject (before other things bogged me down and I went onto other things) here.

** The point I'm making with the image you see below is to help suggest an
idea for you to visualize the layout using a guide. This helped me to understand what I
was learning.

Explanation of the illustration-- The partial (though crude) image you see below is a basic
representation of how the YUY2 layout can look. And in this pictured view, I had
incorporated Color Coded Cells, Numerical Position, and the Color Values used. Its
purpose was to aid in the actual format and look, and it helped me to verify my
progress. I had a i420 and YV12 pic too, but I can't seem to find it, though those
two never did make it to my last post on that thread. I was so close to releasing a
utility (that spits out the layout like the one below) but my personal life got the
better of me.

-vhelp 4291

Statistics