I wants to read only Luma content from the 4-2-0 YUV input. I wrote a code for that which works fine and able to dump only luma content into a separate file.
CODE:
int main()
{
size_t size = 0;
uint32_t frame_number = 0;
FILE* f0_in = fopen("input_420p.yuv", "r");
if (NULL == f0_in) {
printf("REF: Error in opening input file \n");
return 0;
}
FILE* f0_luma = fopen("input_420p_LumaContent.y", "w");
if (NULL == f0_luma) {
printf("REF: Error in opening output file for luma \n");
return 0;
}
uint32_t width_luma = 1632;
uint32_t height_luma = 1280;
uint32_t width_chroma = width_luma/2;
uint32_t height_chroma = height_luma/2;
uint32_t luma_size = width_luma * height_luma;
uint32_t chroma_size = width_chroma * height_chroma;
uint32_t frame_size = luma_size + 2*chroma_size;
unsigned char *inputLumaY;
unsigned char *inputChromaCB;
unsigned char *inputChromaCR;
inputLumaY = (unsigned char*) malloc(sizeof(unsigned char) * width_luma * height_luma);
if (inputLumaY == NULL) {
exit (1);
}
inputChromaCB = (unsigned char*) malloc(sizeof(unsigned char) * width_chroma * height_chroma);
if (inputChromaCB == NULL) {
exit (1);
}
inputChromaCR = (unsigned char*) malloc(sizeof(unsigned char) * width_chroma * height_chroma);
if (inputChromaCR == NULL) {
exit (1);
}
/* frame loop */
while (!feof(f0_in))
{
size = fread(inputLumaY, 1, luma_size, f0_in);
if (size == 0) {
printf ("REF: Error in reading luma content: %zu\n", size);
break;
}
size += fread(inputChromaCB, 1, chroma_size, f0_in);
if (size == 0) {
printf ("REF: Error in reading cb content: %zu\n", size);
break;
}
size += fread(inputChromaCR, 1, chroma_size, f0_in);
if (size == 0) {
printf ("REF: Error in reading cr content: %zu\n", size);
break;
}
if (size == frame_size)
{
fwrite((void *)inputLumaY, sizeof(unsigned char) , luma_size, f0_luma);
}
printf("Frame number:%d\n",frame_number);
frame_number++;
}
free(inputChromaCR);
free(inputChromaCB);
free(inputLumaY);
fclose(f0_in);
fclose(f0_luma);
return 0;
}
Query:
I want to skip reading chroma part and wants to use fseek
instead. So, because of fseek code will point to the next luma frame index for the next frame.
Can any one suggest the way for doing so.
Reason: I want to operate on Luma and wants to avoid the chroma buffer allocation in code. If I will able to replace file reading for chroma, then I will remove chroma buffer allocation.