测试用的YUV文件流分析(转)

我们要测试的文件foreman_part_qcif.yuv它包含三帧彩色图像。

以及文件foreman_part_qcif.y 注意后缀,它包含三帧灰度图像(只有y信号)

qicf文件的分辨率为176*144,并且每个分量用一个字节存储

则对于foreman_part_qcif.yuv文件,用于表达颜色的字节大小应该为:

 

3[帧数]*{176*144[亮度]+(1/4)*176*144[u色度信号]+(1/4)*176*144[v色度信号]}= 114048

查看该文件的大小后发现确为114,048 字节

 

说明该文件不同于其他图像格式的文件(bmp,jpeg等),它没有文件头,没有任何与表达颜色信号无关的内容。

 

用十六进制编辑器打开两个文件进行比对,如下图:

 

它们开始的内容是一样的。

 

从下面的两幅图可以看出:

两个文件从6300h(十六进制)之后开始出现不同,6300h转化为十进制是176*144=25344

刚好是y信号所占用的字节的大小。

对于文件foreman_part_qcif.yuv 它从6301h起开始排列第一帧的u信号。

对于文件foreman_part_qcif.y 它从6301h起开始排列第二帧的y信号。

 

 

由以上分析可以得出4:2:0的qcif.yuv文件的格式如下图:

cif文件的分辨率为352*288,

qcif即1/4的cif为176*144,

 

4:2:0的qcif.yuv文件结构

 

yuv文件不能直接在windows底下打开,通过工具YUVview可以显示该文件

YUV文件的具体格式:

A video sequence stored in the YUV format is stored  by concatenating
consecutive frames into a single big file. Each frame contains the Y pixels
for that frame first, followed by the U pixels (actually Cr pixel), followed
by V pixels (actually Cb pixels). Each component is raster-scanned from
the top left corner down to the bottom right corner.
Each pixel value is stored as a 8 bit unsigned character.

For example, a frame in a QCIF sequence with 176x144 Y pixels and
88x72 U and V pixels is stored in the following order:

           176
     +-------------+
     |                 |
     |     Y          | 144
     |                 |
     |                 |
     +-------------+
       88
     +------+
     |  U     |
     |         |72
     +------+
     |  V     |
     |         |72
     +------+

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
可以使用以下步骤来将YUV文件换为JPEG文件: 1. 安装turbojpeg库:在Linux中,可以使用以下命令安装turbojpeg库: ``` sudo apt-get install libturbojpeg ``` 2. 编写代码:下面是一个示例代码,它将YUV文件换为JPEG文件: ``` #include <stdio.h> #include <stdlib.h> #include <turbojpeg.h> int main(int argc, char **argv) { FILE *input_file, *output_file; unsigned char *input_buffer, *output_buffer; tjhandle tj_instance = tjInitCompress(); // 打开输入文件 input_file = fopen(argv[1], "rb"); if (!input_file) { printf("Failed to open input file\n"); return 1; } // 读取输入文件 fseek(input_file, 0, SEEK_END); long input_size = ftell(input_file); rewind(input_file); input_buffer = (unsigned char*)malloc(input_size); fread(input_buffer, 1, input_size, input_file); fclose(input_file); // 设置压缩参数 int width = atoi(argv[2]); int height = atoi(argv[3]); int in_subsamp = TJSAMP_420; int out_subsamp = TJSAMP_420; int jpeg_quality = 90; tjCompress2(tj_instance, input_buffer, width, 0, height, TJPF_YUV420, &output_buffer, NULL, NULL, in_subsamp, jpeg_quality, TJFLAG_FASTDCT); // 打开输出文件 output_file = fopen(argv[4], "wb"); if (!output_file) { printf("Failed to open output file\n"); tjFree(output_buffer); return 1; } // 写入输出文件 fwrite(output_buffer, 1, tjBufSize(width, height, out_subsamp), output_file); fclose(output_file); tjFree(output_buffer); tjDestroy(tj_instance); return 0; } ``` 3. 编译代码:使用以下命令编译代码: ``` gcc -o yuv2jpeg yuv2jpeg.c -lturbojpeg ``` 4. 运行代码:使用以下命令运行代码: ``` ./yuv2jpeg input.yuv width height output.jpg ``` 其中,`input.yuv`是输入的YUV文件,`width`和`height`是图像的宽度和高度,`output.jpg`是输出的JPEG文件

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值