VC環境下是如何讀入*.yuv序列
阿新 • • 發佈:2018-12-30
#include <stdio.h>
#include <malloc.h>
void main()
{
char *Y;
char *Cb;
char *Cr;
int width = 352, height = 288;
FILE *fp;
FILE *fy;
int i;
Y = (char*)malloc(width*height);
Cb = (char*)malloc(width*height/4);
Cr = (char*)malloc(width*height/4);
fp= fopen("input.yuv","rb");
if(fp == NULL)
printf("open input.yuv failed\n");
fy = fopen("output.yuv", "ab+");
if(fy == NULL)
printf("open output.yuv failed\n");
for(i = 0; i<1; i++)
{
//fseek(fp, i*width*height, 0);
if(0 == fread(Y, width*height, 1, fp))
printf("read error\n");
if(0 == fwrite(Y, width*height, 1, fy))
printf("write error\n");
fread(Cb, width*height/4, 1, fp);
fread(Cr, width*height/4, 1, fp);
fwrite(Cb, width*height/4, 1, fy);
fwrite(Cr, width*height/4, 1, fy);
}
fclose(fp);
fclose(fy);
free(Y);
free(Cb);
free(Cr);
#include <malloc.h>
void main()
{
char *Y;
char *Cb;
char *Cr;
int width = 352, height = 288;
FILE *fp;
FILE *fy;
int i;
Y = (char*)malloc(width*height);
Cb = (char*)malloc(width*height/4);
Cr = (char*)malloc(width*height/4);
fp= fopen("input.yuv","rb");
if(fp == NULL)
printf("open input.yuv failed\n");
fy = fopen("output.yuv", "ab+");
if(fy == NULL)
printf("open output.yuv failed\n");
for(i = 0; i<1; i++)
{
//fseek(fp, i*width*height, 0);
if(0 == fread(Y, width*height, 1, fp))
printf("read error\n");
if(0 == fwrite(Y, width*height, 1, fy))
printf("write error\n");
fread(Cb, width*height/4, 1, fp);
fread(Cr, width*height/4, 1, fp);
fwrite(Cb, width*height/4, 1, fy);
fwrite(Cr, width*height/4, 1, fy);
}
fclose(fp);
fclose(fy);
free(Y);
free(Cb);
free(Cr);
}
轉載來自http://bbs.chinavideo.org/viewthread.php?tid=989&extra=page%3D1,此文章集合了網友h.264各種問題和回答