Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View .bin file (YCbCr 4:2:2 format)

I am given a .bin file. I know that the elements in this file correspond to Y Cb Cr values (4:2:2). Also, the data type is 8 bits. How can I view this?

I found a pretty good site: http://rawpixels.net/ which does what is expected but for YUV format. I want for YCbCr format.

Priliminary google search gives conversion to RGB, which is not desired. I have attached an example .bin file on dropbox. The size of image is 720 X 576.

like image 988
Saania Avatar asked Dec 01 '25 20:12

Saania


2 Answers

From Wikipedia

Y′CbCr is often confused with the YUV color space, and typically the terms YCbCr and YUV are used interchangeably, leading to some confusion; when referring to signals in video or digital form, the term "YUV" mostly means "Y′CbCr".

If you are on a linux-based system and have access to ffmpeg, the following command correctly displays the data

ffplay -f rawvideo -video_size 720x576 -pix_fmt yuyv422 38.bin

enter image description here

Another good tool for displaying of RGB/YCbCr images is vooya which is free for linux but not for windows.

My own tool, yuv-viewer works as well.

Hope this helps.

like image 178
Fredrik Pihl Avatar answered Dec 04 '25 09:12

Fredrik Pihl


You can up-sample the 4:2:2 down-sampled chroma like this:

////////////////////////////////////////////////////////////////////////////////
// unpack.c
// Mark Setchell
//
// Convert YCbCr 4:2:2 format file to full YCbCr without chroma subsampling
//
// Compile with:
//    gcc -o unpack unpack.c
// Run with:
//    ./unpack < input.bin > output.bin
////////////////////////////////////////////////////////////////////////////////

#include <stdio.h>
#include <sys/uio.h>
#include <unistd.h>
#include <sys/types.h>

int main(){
    unsigned char ibuf[4];  // Input data buffer format: Y Cb Y Cr
    unsigned char obuf[6];  // Output data buffer format: Y Cb Cr Y Cb Cr

    // Read 4 bytes at a time, and upsample chroma
    while(fread(ibuf,4,1,stdin)==1){
       obuf[0]=ibuf[0];
       obuf[1]=ibuf[1];
       obuf[2]=ibuf[3];
       obuf[3]=ibuf[2];
       obuf[4]=ibuf[1];
       obuf[5]=ibuf[3];
       fwrite(obuf,6,1,stdout);
    }
    return 0;
}

Then you would run this to up-sample:

./unpack < input.bin > output.bin

and then use ImageMagick convert to get a PNG (or JPEG, or TIF) like this:

convert -size 720x576 -depth 8 yuv:result.bin  image.png

enter image description here

In theory, ImageMagick should be able to do the up sampling itself (and not need a C program) with a command line like this, but I can't seem to make it work:

convert -interlace none -sampling-factor 4:2:2 -size 720x576 -depth 8 yuv:input.bin image.jpg

If anyone knows why - please comment!

like image 30
Mark Setchell Avatar answered Dec 04 '25 10:12

Mark Setchell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!