// HCFJ.cpp : implementation file // #include "stdafx.h" #include "pmlx.h" #include "HCFJ.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif / // CHCFJ dialog CHCFJ::CHCFJ(CWnd* pParent /*=NULL*/) : CDialog(CHCFJ::IDD, pParent) { //{{AFX_DATA_INIT(CHCFJ) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CHCFJ::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CHCFJ) DDX_Control(pDX, IDC_EDIT5, m_EDIT5); DDX_Control(pDX, IDC_EDIT3, m_EDIT3); DDX_Control(pDX, IDC_EDIT2, m_EDIT2); DDX_Control(pDX, IDC_EDIT1, m_EDIT1); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CHCFJ, CDialog) //{{AFX_MSG_MAP(CHCFJ) ON_BN_CLICKED(IDC_BUTAVI, OnButavi) ON_BN_CLICKED(IDC_BUTCUNF, OnButcunf) ON_BN_CLICKED(IDC_BUTDAORU, OnButdaoru) ON_BN_CLICKED(IDC_BUTEXIT, OnButexit) ON_BN_CLICKED(IDC_BUTNAME, OnButname) ON_BN_CLICKED(IDC_BUTSCBMP, OnButscbmp) ON_BN_CLICKED(IDC_BUTSELECT, OnButselect) //}}AFX_MSG_MAP END_MESSAGE_MAP() / // CHCFJ message handlers void CHCFJ::OnButavi() { // TODO: Add your control notification handler code here CFileFind finder; CString strBmpDir; m_EDIT3.GetWindowText(strBmpDir); strBmpDir+="//*.*"; AVIFileInit(); AVISTREAMINFO strhdr; PAVIFILE pfile; PAVISTREAM ps; PAVISTREAM pComStream; AVICOMPRESSOPTIONS pCompressOption; //结构体 AVICOMPRESSOPTIONS FAR * opts[1] = {&pCompressOption}; int nFrames =0; HRESULT hr; BOOL bFind = finder.FindFile(strBmpDir); while(bFind) { bFind = finder.FindNextFile(); if(!finder.IsDots() && !finder.IsDirectory()) { CString str = finder.GetFilePath(); FILE *fp = fopen(str,"rb"); BITMAPFILEHEADER bmpFileHdr; BITMAPINFOHEADER bmpInfoHdr; fseek( fp,0,SEEK_SET); fread(&bmpFileHdr,sizeof(BITMAPFILEHEADER),1, fp); fread(&bmpInfoHdr,sizeof(BITMAPINFOHEADER),1, fp); BYTE *tmp_buf = NULL; if(nFrames ==0 ) { CString szAviName; m_EDIT5.GetWindowText(szAviName); if(szAviName.Right(4)!=".avi") szAviName+=".avi"; AVIFileOpen(&pfile,szAviName,OF_WRITE | OF_CREATE,NULL); memset(&strhdr, 0, sizeof(strhdr)); strhdr.fccType = streamtypeVIDEO;// stream type strhdr.fccHandler = 0; strhdr.dwScale = 1; strhdr.dwRate = (int)3; // 15 fps strhdr.dwSuggestedBufferSize = bmpInfoHdr.biSizeImage ; SetRect(&strhdr.rcFrame, 0, 0, bmpInfoHdr.biWidth, bmpInfoHdr.biHeight); hr = AVIFileCreateStream(pfile,&ps,&strhdr); opts[0]->fccType = streamtypeVIDEO; opts[0]->fccHandler = mmioStringToFOURCC("MSVC", 0); opts[0]->dwQuality = 7500; opts[0]->dwBytesPerSecond = 0; opts[0]->dwFlags = AVICOMPRESSF_VALID || AVICOMPRESSF_KEYFRAMES; opts[0]->lpFormat = 0; opts[0]->cbFormat = 0; opts[0]->dwInterleaveEvery = 0; AVIMakeCompressedStream(&pComStream,ps,&pCompressOption,NULL); //压缩视频流 } tmp_buf = new BYTE[bmpInfoHdr.biWidth * bmpInfoHdr.biHeight * 3]; fread(tmp_buf,bmpInfoHdr.biWidth * bmpInfoHdr.biHeight * 3,1,fp); hr = AVIStreamSetFormat(pComStream,nFrames,&bmpInfoHdr,sizeof(bmpInfoHdr)); hr = AVIStreamWrite(pComStream,nFrames,1,(LPBYTE)tmp_buf,bmpInfoHdr.biSizeImage,AVIIF_KEYFRAME,NULL,NULL); nFrames ++; delete[] tmp_buf; fclose(fp); } } AVIStreamClose(pComStream); AVIStreamClose(ps); if(pfile != NULL) AVIFileRelease(pfile); AVIFileExit(); MessageBox("合成完成"); } void CHCFJ::OnButcunf() { // TODO: Add your control notification handler code here CString ReturnPach; //字符串变量 TCHAR szPath[_MAX_PATH]; //保存路径变量 BROWSEINFO bi; // BROWSEINFO结构变量 bi.hwndOwner = NULL; //HWND句柄 bi.pidlRoot = NULL; //默认值为NULL bi.lpszTitle = _T("文件浏览对话框"); //对话框标题 bi.pszDisplayName = szPath; //选择文件夹路径 bi.ulFlags = BIF_RETURNONLYFSDIRS; //标记 bi.lpfn = NULL; //默认值为NULL bi.lParam = NULL; //回调消息 LPITEMIDLIST pItemIDList = SHBrowseForFolder(&bi); //显示文件浏览对话框 if(pItemIDList) { if(SHGetPathFromIDList(pItemIDList,szPath)) //判断是否获得文件夹路径 ReturnPach = szPath; //获得文件夹路径 } else { ReturnPach = ""; //文件夹路径为空 } m_EDIT2.SetWindowText(ReturnPach); //显示文件夹路径 } void CHCFJ::OnButdaoru() { // TODO: Add your control notification handler code here CFileDialog hFileDlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"(*.avi)|*.avi||",AfxGetMainWnd()); if(hFileDlg.DoModal() == IDOK) { CString m_path = hFileDlg.GetPathName(); m_EDIT1.SetWindowText(m_path); } } void CHCFJ::OnButexit() { // TODO: Add your control notification handler code here CDialog::EndDialog(0); } void CHCFJ::OnButname() { // TODO: Add your control notification handler code here CFileDialog dlg(FALSE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, "(*.avi)|*.avi| |",AfxGetMainWnd()); CString strPath; if(dlg.DoModal() == IDOK) //显示对话框并使用户可以进行选择 { strPath = dlg.GetPathName(); //返回选定文件的完整路径 if(strPath.Right(4) != ".avi") strPath += ".avi"; } m_EDIT5.SetWindowText(strPath); } void CHCFJ::OnButscbmp() { // TODO: Add your control notification handler code here /*AVIFileInit(); PAVIFILE avi; CString mmm; m_EDIT1.GetWindowText(mmm); int res=AVIFileOpen(&avi, mmm, OF_READ, NULL); int n = GetLastError(); if (res!=AVIERR_OK) { //an error occures if (avi!=NULL) AVIFileRelease(avi); return ; } AVIFILEINFO avi_info; AVIFileInfo(avi, &avi_info, sizeof(AVIFILEINFO)); PAVISTREAM pStream; res=AVIFileGetStream(avi, &pStream, streamtypeVIDEO , 0 ); if (res!=AVIERR_OK) { if (pStream!=NULL) AVIStreamRelease(pStream); AVIFileExit(); return ; } //do some task with the stream int iNumFrames; int iFirstFrame; iFirstFrame=AVIStreamStart(pStream); if (iFirstFrame==-1) { //Error getteing the frame inside the stream if (pStream!=NULL) AVIStreamRelease(pStream); AVIFileExit(); return ; } iNumFrames=AVIStreamLength(pStream); if (iNumFrames==-1) { //Error getteing the number of frames inside the stream if (pStream!=NULL) AVIStreamRelease(pStream); AVIFileExit(); return ; } PGETFRAME pFrame; pFrame=AVIStreamGetFrameOpen(pStream, NULL ); AVISTREAMINFO streaminfo; AVIStreamInfo(pStream,&streaminfo,sizeof(AVISTREAMINFO)); //Get the first frame int index=0; for (int i=iFirstFrame; i<iNumFrames; i++) { index= i-iFirstFrame; BYTE* pDIB = (BYTE*) AVIStreamGetFrame(pFrame, index); // LPBITMAPINFOHEADER bih2; bih2 = (LPBITMAPINFOHEADER) AVIStreamGetFrame(pFrame, index); BITMAPINFOHEADER Header; memset(&Header,0,sizeof(BITMAPINFOHEADER)); Header.biBitCount=bih2->biBitCount ; Header.biSize = sizeof(BITMAPINFOHEADER); Header.biWidth = avi_info.dwWidth; Header.biHeight = avi_info.dwHeight; Header.biPlanes =bih2->biPlanes; Header.biCompression =BI_RGB; Header.biXPelsPerMeter = 0; Header.biYPelsPerMeter = 0; Header.biClrUsed =0; Header.biSizeImage=(((avi_info.dwWidth*Header.biBitCount)+31)/8)*avi_info.dwHeight; long lsize = sizeof(Header); AVIStreamReadFormat(pStream,index,&Header,&lsize); BITMAPFILEHEADER stFileHdr; BYTE* Bits=new BYTE[Header.biSizeImage]; AVIStreamRead(pStream,index,1,(LPBYTE)Bits,Header.biSizeImage,NULL,NULL); //RtlMoveMemory(Bits, pDIB + sizeof(BITMAPINFOHEADER), Header.biSizeImage); stFileHdr.bfOffBits=54; stFileHdr.bfSize=54+Header.biSizeImage; stFileHdr.bfType=((WORD)('M'<< 8)|'B'); CString FileName; FileName.Format("Frame-%05d.bmp", index); CString strtemp ; m_EDIT2.GetWindowText(strtemp); strtemp += "//"; strtemp += FileName; CFile file; if(file.Open(strtemp,CFile::modeCreate|CFile::modeWrite)) //成功则返回文件描述符,否则返回 -1 { file.WriteHuge(&stFileHdr,sizeof(BITMAPFILEHEADER)); //使用一次读写复制一个大型文件 file.WriteHuge(&Header,sizeof(BITMAPINFOHEADER)); file.WriteHuge(Bits,Header.biSizeImage); file.Close(); } / delete Bits; //CreateFromPackedDIBPointer(pDIB, index); } AVIStreamGetFrameClose(pFrame); //close the stream after finishing the task if (pStream!=NULL) AVIStreamRelease(pStream); AVIFileExit(); MessageBox("分解完成");*/ //************************************************************************ PAVIFILE pfile; AVIFILEINFO pfi; PAVISTREAM pavi; PGETFRAME pgf; AVIFileInit(); CString mmm; m_EDIT1.GetWindowText(mmm); AVISTREAMINFO psi; AVIFileOpen(&pfile,mmm,OF_READ|OF_SHARE_DENY_NONE,NULL); AVIFileInfo(pfile,&pfi,sizeof(AVIFILEINFO)); AVIFileGetStream(pfile,&pavi,streamtypeVIDEO,0); AVIStreamInfo(pavi,&psi,sizeof(AVISTREAMINFO)); pgf=AVIStreamGetFrameOpen(pavi,NULL); LPBITMAPINFOHEADER bmp1; bmp1=(LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf,0); BITMAPINFOHEADER bmih; memset(&bmih,0,sizeof(BITMAPINFOHEADER)); bmih.biBitCount=bmp1->biBitCount; bmih.biSize=sizeof(BITMAPINFOHEADER); bmih.biWidth=pfi.dwWidth; bmih.biHeight=pfi.dwHeight; bmih.biPlanes=bmp1->biPlanes; bmih.biCompression=BI_RGB; bmih.biXPelsPerMeter=0; bmih.biYPelsPerMeter=0; bmih.biSizeImage=(((pfi.dwWidth*bmih.biBitCount)+31)/8)*pfi.dwHeight; BITMAPFILEHEADER bmfh; bmfh.bfSize=54+bmih.biSizeImage; bmfh.bfOffBits=54; bmfh.bfType=0x4D42; bmfh.bfReserved1=0; bmfh.bfReserved2=0; BYTE* pDIB=new BYTE[(((pfi.dwWidth*bmih.biBitCount)+31)/8)*pfi.dwHeight]; BYTE* lpbuff; for(long i=1;i<(long)pfi.dwLength;i++) { lpbuff=pDIB; lpbuff=(BYTE *)AVIStreamGetFrame(pgf,i); lpbuff+=40; CString FileName; FileName.Format("Frame-%05ld.bmp", i); CString strtemp ; m_EDIT2.GetWindowText(strtemp); strtemp += "//"; strtemp += FileName; CFile file(strtemp,CFile::modeCreate|CFile::modeWrite); file.Write(&bmfh,sizeof(bmfh)); file.Write(&bmih,sizeof(BITMAPINFOHEADER)); file.Write(lpbuff,(((pfi.dwWidth*bmih.biBitCount)+31)/8)*pfi.dwHeight); file.Close(); Sleep(10); } delete[] pDIB; AVIStreamGetFrameClose(pgf); if (pavi!=NULL) AVIStreamRelease(pavi); AVIFileRelease(pfile); AVIFileExit(); MessageBox("分解完成"); //************************************************************************ } void CHCFJ::OnButselect() { // TODO: Add your control notification handler code here // TODO: Add your control notification handler code here CString ReturnPach; //字符串变量 TCHAR szPath[_MAX_PATH]; //保存路径变量 BROWSEINFO bi; // BROWSEINFO结构变量 bi.hwndOwner = NULL; //HWND句柄 bi.pidlRoot = NULL; //默认值为NULL bi.lpszTitle = _T("文件浏览对话框"); //对话框标题 bi.pszDisplayName = szPath; //选择文件夹路径 bi.ulFlags = BIF_RETURNONLYFSDIRS; //标记 bi.lpfn = NULL; //默认值为NULL bi.lParam = NULL; //回调消息 LPITEMIDLIST pItemIDList = SHBrowseForFolder(&bi); //显示文件浏览对话框 if(pItemIDList) { if(SHGetPathFromIDList(pItemIDList,szPath)) //判断是否获得文件夹路径 ReturnPach = szPath; //获得文件夹路径 } else { ReturnPach = ""; //文件夹路径为空 } m_EDIT3.SetWindowText(ReturnPach); //显示文件夹路径 }