网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

C/C++操作YUV视频-创新互联

1.读取YUV视频
#includeusing namespace std;

void readYUV()
{FILE* pfImgRaw = NULL;
	if (!(pfImgRaw = fopen("E:/path/to/your/nv12.yuv", "rb")))
	{printf("open input file failure!\n");
	}
	printf("load yuv file is OK!\n");
}
2.获取YUV视频帧数
#includeusing namespace std;

void countYUVFrame()
{int imgWidth = 1280;
	int imgHeight = 720;
	int nums_frame;

	FILE* pfImgRaw = NULL;
	if (!(pfImgRaw = fopen("E:/path/to/your/nv12.yuv", "rb")))
	{printf("open input file failure!\n");
	}
	printf("load yuv file is OK!\n");

	fseek(pfImgRaw, 0, SEEK_END);  //将文件的指针指到文件末尾
	long frame_size = ftell(pfImgRaw);  //该函数返回位置标识符的当前值。如果发生错误,则返回 -1L.
	long persize = imgWidth * imgHeight * 3 / 2;  //默认YUV格式为nv12,所以每帧的大小为w*h*3/2
	nums_frame = (int)(frame_size / persize);  //总帧数=文件总大小/每帧大小
	rewind(pfImgRaw);  //防止稍后还需要操作文件,重新将文件的指针指向开头
}
3.将读取的YUV数据用opencv显示出来
#include#include#include#include "opencv2/imgproc/imgproc_c.h"
using namespace std;
using namespace cv;
void countYUVFrame()
{int imgWidth = 1280;
	int imgHeight = 720;
	int nums_frame;
	unsigned char* pu8ImgCur;
	int l32BufLen = imgWidth * imgHeight * 1.5;

	FILE* pfImgRaw = NULL;
	if (!(pfImgRaw = fopen("E:/path/to/your/nv12.yuv", "rb")))
	{printf("open input file failure!\n");
	}
	printf("load yuv file is OK!\n");
	if (!(pu8ImgCur = (unsigned char*)malloc(l32BufLen)))
	{printf("malloc error!\n");
	}
	memset(pu8ImgCur, 0, l32BufLen);

	fseek(pfImgRaw, 0, SEEK_END);  //文件的指针指到文件末尾
	long frame_size = ftell(pfImgRaw);  //该函数返回位置标识符的当前值。如果发生错误,则返回 -1L.
	long persize = imgWidth * imgHeight * 3 / 2;  //默认YUV格式为nv12,所以每帧的大小为w*h*3/2
	nums_frame = (int)(frame_size / persize);  //总帧数=文件总大小/每帧大小
	rewind(pfImgRaw);  //防止稍后还需要操作文件,重新将文件的指针指向开头

	fread(pu8ImgCur, sizeof(unsigned char), l32BufLen, pfImgRaw);
	cv::Mat cv_img;
	cv::Mat cv_yuv(imgHeight + imgHeight / 2, imgWidth, CV_8UC1, pu8ImgCur);//pFrame为YUV数据地址,另外这里就是用 CV_8UC1非 CV_8UC3.
	cv_img = cv::Mat(imgHeight, imgWidth, CV_8UC3);
	cv::cvtColor(cv_yuv, cv_img, COLOR_YUV2BGR_NV12);  //这里的Mat应该是BGR顺序的,但是显示的又是RGB顺序,我不太明白
	imshow("result", cv_img);
	waitKey(0);
	fclose(pfImgRaw);
}

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧

成都创新互联成都网站建设按需搭建网站,是成都网站营销公司,为宣传片制作提供网站建设服务,有成熟的网站定制合作流程,提供网站定制设计服务:原型图制作、网站创意设计、前端HTML5制作、后台程序开发等。成都网站制作热线:028-86922220
当前文章:C/C++操作YUV视频-创新互联
标题网址:http://bjjierui.cn/article/epohs.html

其他资讯