Hi everyone,
I am developing a codec as a hobby project and I am an absolute beginner in this field with a signal processing background.
I am stuck in the reading of a YUV file. This is what I did:
1. Allocated memory to an pointer of size Height*width for Y frame
2. 1 Allocated memory to an pointer of size Height*width/4 for U frame and V frame respectively.
3. I am using fread to read the frame. However what happens is U and V frames are completely filled with the value = 205 and the resulting frame when opened using YUVTools is pink in color.
I am unable to figure out why "205" is being read.
Also I was advised to try using int,unsigned char, char pointers for the frames .. but I get the same result.
Can anyone help me out with this? Thanks a lot in advance ...
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays! or rip iTunes movies!
+ Reply to Thread
Results 1 to 18 of 18
Thread
-
-
What kind of YUV file? YUY2? YV12? What you're describing is YUV with 4:1:1 subsampling (Height*width/4 for U frame and V frame) like in DV video but no decoder I know of outputs that.
Maybe you could post a few frames of the video. -
Originally Posted by jagabo
It's just interpreted differently as far as chroma placement is concerned. -
Hi,
I should have mentioned that. I am using YV12 (4:2:0).
But what is weird now is that even in the Y frame, roughly the last 200 pixels are fixed at 205 and the entire U and V frame go to 205. As you mentioned I am attaching the first frame of the Football sequence which is what I am using.
frame1.yuv -
Originally Posted by Gavino
-
Originally Posted by krao
-
Hi Jagabo
It is 176 * 144.
I was given this by a colleague and the original name is FOOTBALL_176x144_7.5_orig_01.yuv. He mentioned that it is of 4:2:0 format and I am reading Y , then U and then V in that order.
However as I mentioned before, part of the Y frame and the entire U and V frames are fixed at 205. -
Originally Posted by krao
Looking at it with a hex editor, I don't see any sequence of values 205, at least not around the point where the Y plane ends and the U plane begins (offset 25344). But there is a clear change in the range of values at this point (starting 10, 8, 9, 8, ...).
This suggests there is something wrong with your code to read the file.
Could you post the relevant part of the code here? -
Hi,
I was unable to post anything the whole day due to some Apache server error ! Was there a server problem?
Anyways here is my code...it is fairly simple..is anything wrong with it?
Code:void ReadYUV() { FILE *pInpVideo, *pTestOut; unsigned char *pInp, *pYFrame, *pUFrame, *pVFrame; int i; int nHeight = 144; int nWidth = 176; int nSize = nHeight*nWidth; pYFrame = malloc(sizeof(unsigned char)* nSize); pUFrame = malloc(sizeof(unsigned char)*(nSize/4)); pVFrame = malloc(sizeof(unsigned char)*(nSize/4)); pInpVideo = fopen ("C:\\Codec\\FOREMAN_176x144_7.5_orig_01.yuv","r") ; pTestOut = fopen (C:\\testout.yuv","w"); if(!pInpVideo) printf("error"); fread (pYFrame, sizeof(unsigned char), (nSize), pInpVideo); fread (pUFrame, sizeof(unsigned char), (nSize)/4, pInpVideo); fread (pVFrame, sizeof(unsigned char), (nSize)/4, pInpVideo); fwrite(pYFrame, sizeof(unsigned char), (nSize), pTestOut); fwrite(pUFrame, sizeof(unsigned char), (nSize)/4, pTestOut); fwrite(pVFrame, sizeof(unsigned char), (nSize)/4, pTestOut); fclose(pTestOut); fclose(pInpVideo); }
-
Oh wow !! I think the mistake I have been making is using "r" in the fopen statement instead of "rb" ...
Thanks a lot Jagabo and Gavino for your help !! Hope I learn quickly and help others like you'll did too !! -
Hi! I try to compose two YUV image (4:2:0, same resolution) in only one image (side by side) but i have some problem with this code because result is four compressed image in one!
i need yours help!!!
Code:#include <stdio.h> #include <stdlib.h> int main(void) { FILE *pInpVideo_one, *pInpVideo_two, *pTestOut; unsigned char *pYFrame, *pUFrame, *pVFrame, *pYFrame_one, *pUFrame_one, *pVFrame_one, *pYFrame_two, *pUFrame_two, *pVFrame_two; int nHeight = 144; int nWidth = 176; int nSize = nHeight*nWidth; int nWidth_out = nWidth*2; int nSize_out = nHeight*nWidth_out; pYFrame_one = malloc(sizeof(unsigned char)* nSize); pUFrame_one = malloc(sizeof(unsigned char)*(nSize/4)); // un byte per ogni 4 pixel pVFrame_one = malloc(sizeof(unsigned char)*(nSize/4)); // un byte per ogni 4 pixel pYFrame_two = malloc(sizeof(unsigned char)* nSize); pUFrame_two = malloc(sizeof(unsigned char)*(nSize/4)); // un byte per ogni 4 pixel pVFrame_two = malloc(sizeof(unsigned char)*(nSize/4)); // un byte per ogni 4 pixel pInpVideo_one = fopen ("frame1.yuv","rb") ; pInpVideo_two = fopen ("bus.yuv","rb") ; pTestOut = fopen ("test_uscita.yuv","wb"); if(!pInpVideo_two) printf("error"); fread (pYFrame_one, sizeof(unsigned char), (nSize), pInpVideo_one); fread (pUFrame_one, sizeof(unsigned char), (nSize)/4, pInpVideo_one); fread (pVFrame_one, sizeof(unsigned char), (nSize)/4, pInpVideo_one); fread (pYFrame_two, sizeof(unsigned char), (nSize), pInpVideo_two); fread (pUFrame_two, sizeof(unsigned char), (nSize)/4, pInpVideo_two); fread (pVFrame_two, sizeof(unsigned char), (nSize)/4, pInpVideo_two); fwrite(pYFrame_one, sizeof(unsigned char), (nSize), pTestOut); fseek(pTestOut, 0, SEEK_END); fwrite(pYFrame_two, sizeof(unsigned char), (nSize), pTestOut); fseek(pTestOut, 0, SEEK_END); fwrite(pUFrame_one, sizeof(unsigned char), (nSize)/4, pTestOut); fseek(pTestOut, 0, SEEK_END); fwrite(pUFrame_two, sizeof(unsigned char), (nSize)/4, pTestOut); fseek(pTestOut, 0, SEEK_END); fwrite(pVFrame_one, sizeof(unsigned char), (nSize)/4, pTestOut); fseek(pTestOut, 0, SEEK_END); fwrite(pVFrame_two, sizeof(unsigned char), (nSize)/4, pTestOut); fseek(pTestOut, 0, SEEK_END); fclose(pTestOut); fclose(pInpVideo_one); fclose(pInpVideo_two); return 0; }
-
By simply appending the data (for each plane) for the two images, you are joining them top-to-bottom rather than side-by-side, creating an image of 288x176 instead of 144x352.
(Obviously, if you try to view this as a 144x352 image, it will look odd.)
For each plane, you need to write the data row by row in a loop to get them side-by-side.
(Note also that the variables nWidth_out and nSize_out are unused.) -
Thank you for reply. I did not understand very well how I write the data row by row in a loop
Can you make an example? Thanks -
If you want your frames side by side you need to stack your planes side by side, not top/bottom. Ie, you did this (1=frame1, 2=frame2):
Code:11111111 11111111 11111111 11111111 22222222 22222222 22222222 22222222
Code:1111111122222222 1111111122222222 1111111122222222 1111111122222222
Code:for (int y=0; y<nHeight; y++) { fwrite(&pYFrame_one[y*nWidth], sizeof(unsigned char), nWidth, pTestOut); fwrite(&pYFrame_two[y*nWidth], sizeof(unsigned char), nWidth, pTestOut); }
Last edited by jagabo; 27th Jan 2011 at 11:32.
-
It works fine!!!! Thanks a lot!
I did not understand how to interpret the position of rows in the yuv file.
Now I will try to build side by side on a yuv video. Let's hope so ... -
The goal is getting more difficult!
I wish I could take the video streams in real time, coded in YUV (4:2:0), by two different cameras. Someone tell me how to do it using C (or C + +)? Work under Linux. I trust in you.
Thanks a lot!
Similar Threads
-
Pioneer BDR 205 won't play BDMV video discs
By kurbads in forum Blu-ray RippingReplies: 4Last Post: 30th Jan 2012, 03:39 -
Pioneer BDR 205 Region Free?
By tegstar83 in forum DVD & Blu-ray WritersReplies: 7Last Post: 13th Nov 2010, 04:57 -
Pioneer BDR-205 requires HD video card to work??
By lafjax in forum DVD & Blu-ray WritersReplies: 4Last Post: 1st Jan 2010, 11:51 -
Help reading .yuv files
By lotsoflayne in forum Newbie / General discussionsReplies: 1Last Post: 23rd Sep 2009, 20:09