Reputation: 41
I have a typedef structure containing the YUV components that I took from a video frame.
I need to find a way to write these YUV components into a (.YUV) file extension so I could use it for my application in C language.
Does anyone know, How can I can do it?
Best Regards
Upvotes: 0
Views: 3830
Reputation: 45634
Well, one of the more common yuv-formats (or rather YCbCr) is YV12
Its is also known as plane-separated 4:2:0 8bpp. Where the 4:2:0 denoted the subsampling used for the color components. 8bpp means the valid range is [0-255]
(not realy true, but lets not go there right now...)
It consists of width x height
bytes luma-samples (the Y-part) followed by width x height / 4
Cb-data and the same amount of Cr-data. Total number of bytes for one frame is width x height * 3 / 2
So basically all you need to do is to write the Y-component as uint8
, followed by Cb-data and Cr-data.
If you need some example code in c to look at, check my yuv-viewer on github. Hope it helps, if not, drop me a comment.
Upvotes: 2
Reputation: 1927
You will need to learn how to write to a file in binary mode. Take a look at these examples. Once that is clear, all you need to do is dump the hex values of the YUV channels into file.
Upvotes: 0