首先考虑一下YUV播放的思路:
要将YUV文件转成RGB,然后给RGB转成BMP,写上BMP头信息,然后在播放器上一帧一帧显示BMP图片。
YUV播放器具体制作过程:
1、 首先打开VS2015,新建一个MFC项目(基于对话框),项目名称叫yuv,完成后会出现如图所示的界面,将下图中确定和取消键删除。

2、点击界面最左边的工具箱按钮添加一个Edit Control 用来显示路径,添加三个Button用来控制打开,播放和退出,添加一个PICTURE Control,用来显示视频。

3、分别右键Button1、Button2、Button3选择属性,在右下角,将ID改为 IDC_OPEN,IDC_PALY,IDC_EXIT,caption (指的就是button的名字)分别改为open,play,exit。右键PICTURE Control添加变量。访问public,变量类型CStatic,变量名为m_picture。在PICTURE属性中将ID改为IDC_STATIC_PIC,type改为Rectangle。


4、双击open按键,会跳转到yuvDlg.cpp中,在void CyuvDlg::OnBnClickedOpen()添加代码如下:

5、双击play按钮添加代码

6、在yuvDlg.h中添加
public:
CWinThread* m_pWinThread;
FILE* ptrSource;
CString m_openfile;
CStatic m_picture;
void YUVTORGB(const char* file, int width, int height, int n);(YUV转成RGB)
void WriteBmp(int width, int height, unsigned char *R, unsigned char *G, unsigned char *B, char *BmpFileName);//写BMP头信息
7、在yuvDlg.cpp第二行添加头文件

8、在yuvDlg.cpp添加全局变量

9、在yuvDlg.cpp下添加void CyuvDlg::YUVTORGB(const char *file, int width, int height, int n)并在该函数中添加如下代码:







10、在yuvDlg.cpp下添加void CyuvDlg::WriteBmp(int width, int height, unsigned char *R, unsigned char *G, unsigned char *B, char *BmpFileName)并在该函数中添加如下代码:


11、最后双击exit按钮,添加代码如下:

网友评论