「已注销」 2022-01-09 20:21 采纳率: 66.7%
浏览 37
已结题

请问这样生成出的yuv文件为什么是原来的1/20?

代码如下,是我的储存方式有问题嘛?

```c++

#include<iostream>
#include<fstream>

using namespace std;
typedef struct YUVPixel {
    int Y;
    int U;
    int V;
} YUVPixel;
int main()
{
    FILE* orignal_data = fopen("ParkScene_1920x1080_24_16bit_444.yuv", "r");
    FILE* f_r = fopen("r_data.yuv", "w");
    if (orignal_data == NULL)
        printf("open file error:\n");
    unsigned int width = 1920, height = 1080;
    unsigned char* raw_16bit_pixels = (unsigned char*)malloc(width * height * 3 * sizeof(unsigned char));
    fread(raw_16bit_pixels, 1, width * height * 3, orignal_data); //暂时忽略其返回值
    YUVPixel yuv_pixel;
    unsigned char Ylow, Yhigh,Ulow,Uhigh,Vlow,Vhigh;
    unsigned int Ytemp,Utemp,Vtemp;
    for (int j = 0;j < height;j++)
        for (int i = 0;i < width;i++)
        {
            yuv_pixel.Y = raw_16bit_pixels[1920 * j + i];//读入Y
            yuv_pixel.U = raw_16bit_pixels[1920 * j + i + 1920 * 1080];//读入U
            yuv_pixel.V = raw_16bit_pixels[1920 * j + i + 1920 * 1080 * 2];//读入V
            Ylow = (yuv_pixel.Y )& 0xff;
            Yhigh = (yuv_pixel.Y )>> 8;
            Ytemp = Yhigh;
            Ytemp <<= 8;
            Ytemp += Ylow;//Y的合成
            Ulow = (yuv_pixel.U) & 0xff;
            Uhigh = (yuv_pixel.U) >> 8;
            Utemp = Uhigh;
            Utemp <<= 8;
            Utemp += Ulow;//U的合成
            Vlow = (yuv_pixel.V) & 0xff;
            Vhigh = (yuv_pixel.V) >> 8;
            Vtemp = Uhigh;
            Vtemp <<= 8;
            Vtemp += Vlow;//V的合成
          //  cout << Utemp << "比较" << yuv_pixel.U << endl;
            fputc(Ytemp, f_r);//写入Y
            fputc(Utemp, f_r);//写入U
            fputc(Vtemp, f_r);//写入V
        }
    fclose(f_r);
    return 0;
}

```

  • 写回答

2条回答 默认 最新

  • CSDN专家-link 2022-01-09 20:31
    关注

    之前文件中颜色分量0-255是用整形存储的,每个分量4字节,改写后,颜色分量改用字符型存储,每个分量1个字节。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 1月17日
  • 已采纳回答 1月9日
  • 创建了问题 1月9日

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改