颜色空间转换CSConvert:YUV420P转MonoY

  1. 1、实现功能
  2. 2、C代码实现
    1. THE END!

1、实现功能

将YUV420P转换成亮度分量Y,比较简单,实现代码如下:

2、C代码实现

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char** argv)
{
    int width, height;
    int frame_size, frame_size_y;
    FILE *fin, *fou;
    char *y, *u, *v,*u1,*v1;
    int i, frame_num = 0;
    char outname[512] = { 0, };
    printf("\nUsage:YUV420PtoMonoY.exe input.yuv output.yuv width height\n\n");
    if (argc != 5)
    {
        return -1;
    }
    fin = fopen(argv[1], "rb");
    if (fin == NULL)
    {
        printf("error:open %s fail\n", argv[1]);
        return -1;
    }

    sprintf_s(outname,"%s", argv[2]);

    width = atoi(argv[3]);
    height = atoi(argv[4]);

    frame_size = width*height * 3 / 2;
    frame_size_y = width * height;

    y = (char *)malloc(frame_size_y);
    if (y == NULL)
    {
        printf("malloc y fail\n");
        return -1;
    }

    fou = fopen(outname, "wb");
    if (fou == NULL)
    {
        printf("error: open %s fail\n", outname);
        return -1;
    }

    while (width*height == fread(y, 1, width*height, fin))
    {
        fwrite(y, 1, frame_size_y, fou);
        fseek(fin, frame_size_y/2, SEEK_CUR);

        printf("%dth frame ok!!\n", frame_num);
        frame_num++;
    }
    printf("YUV420P to MonoY successfully!!, stotal frames: %d\n",frame_num);

    free(y);
    y = NULL;

    fclose(fin);
    fclose(fou);

    system("pause");

    return 0;
}

THE END!


本博文只能阅读,谢绝转载,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 2963033731@qq.com

文章标题:颜色空间转换CSConvert:YUV420P转MonoY

字数:247

本文作者:Soaring Lee

发布时间:2019-10-19, 22:13:47

最后更新:2021-06-14, 12:13:44

原始链接:https://soaringleefighting.github.io/2019/10/19/【Codecs系列】颜色空间转换CSConvert:YUV420P转MonoY/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

×

喜欢就点赞,疼爱就打赏

相册