avi视频格式转yuv格式与播放yuv视频
因为要用到yuv格式视频。而眼下仅仅有avi格式的视频,所以须要转换,而且opencv不支持yuv编码的视频播放。所以须要转换为rgb编码。而后播放。写了两个程序。以供參考:
1,avi格式视频转yuv格式视频
2,播放并保存yuv视频
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
void avi2WriteYuv(const char *in,const char *out)
{
cv::VideoCapture vc;
bool flag = vc.open(in);
if (!flag)
{
printf("avi file open error \n");
system("pause");
exit(-1);
} int frmCount = vc.get(CV_CAP_PROP_FRAME_COUNT);
frmCount -= 5;
printf("frmCount: %d \n", frmCount); int w = vc.get(CV_CAP_PROP_FRAME_WIDTH);
int h = vc.get(CV_CAP_PROP_FRAME_HEIGHT);
printf("wwwwww%d\n", w);
printf("hhhhhh%d\n", h);
int bufLen = w*h * 3 / 2;
unsigned char* pYuvBuf = new unsigned char[bufLen];
FILE* pFileOut = fopen(out, "w+");
if (!pFileOut)
{
printf("pFileOut open error \n");
system("pause");
exit(-1);
}
printf("pFileOut open ok \n"); for (int i = 0; i<frmCount; i++)
{
printf("%d/%d \n", i + 1, frmCount); cv::Mat srcImg;
vc >> srcImg; cv::imshow("img", srcImg);
cv::waitKey(1); cv::Mat yuvImg;
cv::cvtColor(srcImg, yuvImg, CV_BGR2YUV_I420);
memcpy(pYuvBuf, yuvImg.data, bufLen*sizeof(unsigned char)); fwrite(pYuvBuf, bufLen*sizeof(unsigned char), 1, pFileOut);
} fclose(pFileOut);
delete[] pYuvBuf;
}
void DisplayYUV2RGB(const char *dir,const char *in,int _w,int _h)
{
int w = _w;
int h = _h;
printf("yuv file w: %d, h: %d \n", w, h); FILE* pFileIn = fopen(in, "rb+");
int bufLen = w*h * 3 / 2;
unsigned char* pYuvBuf = new unsigned char[bufLen];
int iCount = 0; for (int i = 0; i<95; i++)
{
fread(pYuvBuf, bufLen*sizeof(unsigned char), 1, pFileIn); cv::Mat yuvImg;
yuvImg.create(h * 3 / 2, w, CV_8UC1);
memcpy(yuvImg.data, pYuvBuf, bufLen*sizeof(unsigned char));
cv::Mat rgbImg;
cv::cvtColor(yuvImg, rgbImg, CV_YUV2BGR_I420); cv::imshow("img", rgbImg);
char s[100];
sprintf(s,"%spic%d%s",dir,i,".jpg");
cv::imwrite(s, rgbImg);
cv::waitKey(1); printf("%d \n", iCount++);
} delete[] pYuvBuf; fclose(pFileIn);
} int main(int argc, char *argv[])
{
const char *in = "C:/Users/jiang/Desktop/output/outfile.avi";
const char *out = "C:/Users/jiang/Desktop/output/outfile.yuv";
const char *dir = "C:/Users/jiang/Desktop/output/tupian1/";
avi2WriteYuv(in,out);
DisplayYUVtoRGB(dir,out, 1024, 768);
return 0;
}
avi视频格式转yuv格式与播放yuv视频的更多相关文章
- ubuntu14.04 yuv文件的播放及视频信息的查看
1.安装ffmpeg sudo add-apt-repository ppa:mc3man/trusty-media sudo apt-get update sudo apt-get install ...
- FLV视频在IIS6.0下不能播放 处理的方法
FLV视频在IIS6.0下不能播放 Flash视频由于其较高的压缩率和优越的下载速度,前景普遍看好,同时也为Flash课件增色不少.然而,在FLV视频播放中,却有两个头痛的问题 一.FLV视频在 ...
- 使用X264编码yuv格式的视频帧使用ffmpeg解码h264视频帧
前面一篇博客介绍在centos上搭建点击打开链接ffmpeg及x264开发环境.以下就来问个样例: 1.利用x264库将YUV格式视频文件编码为h264格式视频文件 2.利用ffmpeh库将h264格 ...
- 图像视频编码和FFmpeg(2)-----YUV格式介绍和应用
本文不讲FFmpeg,而是讲YUV图像格式.因为摄像头拍摄出来的原始图像一般都是YUV格式.在FFmpeg中,视频是通过多张YUV图像而得到. YUV图像格式是什么,这个可以看一下维基百科.这个超链接 ...
- linux mplayer 播放yuv格式 (转载)
转自:http://blog.csdn.net/ly0303521/article/details/38713791 在mplayer中查看YUV格式的图片或视频,可使用如下命令: mplayer - ...
- 【视频处理】YUV格式说明
YUV,是一种颜色编码方法,Y表示明亮度(Luminance.Luma),U和V则是色度.浓度(Chrominance.Chroma). YUV,Y`UV,YCbCr,YPbPr等都可以称为YUV,彼 ...
- Video标签播放视频?谷歌浏览器?safari?? 谷歌浏览器播放不了mp4格式的视频的原因
webm格式和mp4格式,判断了浏览器能否支持的视频类型后,给了一个if判断,如果是支持mp4格式,就返回视频后缀mp4,如果是webm,就返回后缀webm.结果,在谷歌浏览器中播放不了,为什么我指定 ...
- C#用ckplayer.js播放 MP4格式视频实现 边加载边播放
MVC设计模式下 在View页面里面使用ckplayer.js 加载视频 ,在MP4格式视频上传之后 我发现某些视频可以边加载边播放 但是有一些又不行,找了下原因是因为视频的元数据信息在第一帧的时候就 ...
- YUV格式分析
转自:http://www.cnblogs.com/armlinux/archive/2012/02/15/2396763.html Andrew Huang <bluedrum@163.com ...
随机推荐
- 构建第一个Spring Boot项目
1.启动IntelliJ IDEA,点击"Create New Project"  2.选择"Spring initializr",设定SDK及Spring ...
- RMQ_第一弹_Sparse Table
title: RMQ_第一弹_Sparse Table date: 2018-09-21 21:33:45 tags: acm RMQ ST dp 数据结构 算法 categories: ACM 概述 ...
- Could not open JDBC Connection for transaction; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server.
报错信息:Could not open JDBC Connection for transaction; nested exception is org.apache.commons.dbcp.SQL ...
- Bzoj4548 小奇的糖果(链表+树状数组)
题面 Bzoj 题解 很显然,我们只需要考虑单独取线段上方的情况,对于下方的把坐标取反再做一遍即可(因为我们只关心最终的答案) 建立树状数组维护一个横坐标区间内有多少个点,维护双向链表实现查询一个点左 ...
- CentOS重装grub修复损坏的系统
grub损坏一般有两种情况:第一.安装双系统时,后安装的系统把先安装的系统的MBR删除了.第二.误操作将grub文件删除了. 不管怎样都需要进入到救援模式,详细请看CentOS通过光盘启动救援数据 ( ...
- python 对字典"排序"
对字典进行排序?这其实是一个伪命题,搞清楚python字典的定义---字典本身默认以key的字符顺序输出显示---就像我们用的真实的字典一样,按照abcd字母的顺序排列,并且本质上各自没有先后关系,是 ...
- 【BZOJ 1419】1419: Red is good (概率DP)
1419: Red is good Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 807 Solved: 343 Description 桌面上有R张 ...
- 【UOJ #221】【NOI 2016】循环之美
http://uoj.ac/problem/221 因为\(a\)和\(b\)不互质时,\(\frac ab=\frac{\frac a{(a,b)}}{\frac b{(a,b)}}\),所以只用求 ...
- BZOJ3589动态树
**错误改了一上午. 先做熟练泼粪 k<=5,因此我们可以模拟这个过程,在线段树上把标记建出来然后pushup时候更新就好了. By:大奕哥 #include<bits/stdc++.h& ...
- python开发_json_一种轻量级的数据交换格式
以下是我做的对于python中json模块的demo 运行效果: Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.16 ...