메뉴 건너뛰기

프로그래밍


VFW 에서 영상 압축을 위한 코덱을 코드상에서 선택하여 실시간 저장하는 방법입니다.

출처:

http://hi.baidu.com/paty/blog/item/2dcac3030841c681d43f7c21.html


#include "resource.h" #include #include #include #include DWORD m_Frame; COMPVARS m_Com; BITMAPINFO m_InInfo,m_OutInfo; PAVIFILE m_pFile; AVISTREAMINFO strhdr; PAVISTREAM ps; BOOL m_Captured=FALSE; NOTIFYICONDATA pnid; CAPDRIVERCAPS caps; CAPTUREPARMS params; HWND capwnd,camhwnd,hDlg; HINSTANCE Inst; char filename[20]; BOOL timeon=FALSE; void InitCompress(); void TimeToName(char *); void Cadd(char *,char*); void CALLBACK TimerProc(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime); LRESULT WINAPI EncodeCallback(HWND hWnd, LPVIDEOHDR lpVHdr); BOOL CALLBACK DlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam); int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // pointer to command line int nCmdShow // show state of window ) { MSG msg; Inst=hInstance; hDlg=CreateDialog(Inst,MAKEINTRESOURCE(IDD_DIALOG1), 0,(DLGPROC)DlgProc); capwnd=capCreateCaptureWindow(NULL,WS_POPUP,0,0,1,1,hDlg,0); if (!capDriverConnect(capwnd,0)) { MessageBox(NULL,"Error",NULL,MB_OK); EnableWindow(GetDlgItem(hDlg,IDC_START),FALSE); } camhwnd=GetDlgItem(hDlg,IDC_FRAM); SetParent(capwnd,camhwnd); SetWindowLong(capwnd,GWL_STYLE,WS_CHILD); RECT wndRC; GetClientRect(camhwnd,&wndRC); MapWindowPoints(capwnd,camhwnd,(POINT*)&wndRC,2); SetWindowPos(capwnd,NULL,wndRC.left+1,wndRC.top+1, wndRC.right-2,wndRC.bottom-2,SWP_NOZORDER); ShowWindow(capwnd,SW_SHOW); capDriverGetCaps(capwnd,sizeof(caps),&caps); if (caps.fHasOverlay) capOverlay(capwnd,TRUE); capCaptureGetSetup(capwnd,¶ms,sizeof(params)); params.fYield = TRUE; params.fAbortLeftMouse = FALSE; params.fAbortRightMouse = FALSE; params.fLimitEnabled = FALSE; params.vKeyAbort = FALSE; params.fCaptureAudio = FALSE; capCaptureSetSetup(capwnd,¶ms,sizeof(params)); capPreviewRate(capwnd,30); capPreview(capwnd,TRUE); capSetCallbackOnVideoStream(capwnd,EncodeCallback); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } BOOL CALLBACK DlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam) { switch (Msg) { case WM_CLOSE: pnid.cbSize=(DWORD)sizeof(NOTIFYICONDATA); pnid.hWnd=hDlg; pnid.uID=IDI_ICON1; pnid.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP ; pnid.uCallbackMessage=WM_SHOWTASK;//菱땍屢돨句口츰냔 pnid.hIcon=LoadIcon(Inst,MAKEINTRESOURCE(IDI_ICON1)); if (!m_Captured) strcpy(pnid.szTip,"Test"); else strcpy(pnid.szTip,"Test Shell_NotifyIcon(NIM_ADD,&pnid); ShowWindow(hDlg,SW_HIDE); break; case WM_SHOWTASK: switch(lParam) { case WM_LBUTTONDBLCLK: ShowWindow(hDlg,SW_SHOW); Shell_NotifyIcon(NIM_DELETE,&pnid); break; } case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_START: EnableWindow(GetDlgItem(hDlg,IDC_START),FALSE); SetTimer(hDlg,1,3600000,TimerProc); m_Captured = TRUE; capGetVideoFormat(capwnd,&m_InInfo,sizeof(m_InInfo)); TimeToName(filename); m_Frame = 0 ; AVIFileInit(); InitCompress(); ShowWindow(FindWindow(NULL,"Xvid Status"),SW_HIDE); AVIFileOpen(&m_pFile,filename,OF_WRITE | OF_CREATE,NULL);// memset(&strhdr, 0, sizeof(strhdr)) ; strhdr.fccType = streamtypeVIDEO; strhdr.fccHandler = 0 ; strhdr.dwScale = 1 ; strhdr.dwRate = 15 ; strhdr.dwSuggestedBufferSize = m_InInfo.bmiHeader.biSizeImage; SetRect(&strhdr.rcFrame, 0, 0, m_InInfo.bmiHeader.biWidth, m_InInfo.bmiHeader.biHeight); ps = NULL; AVIFileCreateStream(m_pFile,&ps,&strhdr); // capCaptureSequenceNoFile(capwnd); //capCaptureSequence(capwnd); break; case IDC_EXIT: if (m_Captured) { if (IDYES==MessageBox(NULL,"...","...", MB_YESNO+MB_DEFBUTTON2)) { capSetCallbackOnVideoStream(capwnd,NULL);// ICCompressEnd(m_Com.hic);// ICClose(m_Com.hic);// AVIStreamClose(ps);// if(m_pFile != NULL) AVIFileRelease(m_pFile); AVIFileExit(); capCaptureStop(capwnd);// capDriverDisconnect(capwnd);// DestroyWindow(capwnd); DestroyWindow(camhwnd); PostQuitMessage(0); return 1; } else return 0; } DestroyWindow(capwnd); DestroyWindow(camhwnd); PostQuitMessage(0); break; case IDC_ABOUT: break; } }; return 0; } LRESULT WINAPI EncodeCallback(HWND hWnd, LPVIDEOHDR lpVHdr) { if (m_Captured&& (lpVHdr->dwFlags&VHDR_DONE)) { if(timeon) { AVIStreamClose(ps);// if(m_pFile != NULL) AVIFileRelease(m_pFile); AVIFileExit(); Sleep(5000); ps = NULL; m_Frame=0; AVIFileInit(); ZeroMemory(filename,20); TimeToName(filename); AVIFileOpen(&m_pFile,filename,OF_WRITE | OF_CREATE,NULL);// AVIFileCreateStream(m_pFile,&ps,&strhdr); timeon=FALSE; } char* buffer = new char [lpVHdr->dwBytesUsed+1]; memset(buffer,0,lpVHdr->dwBytesUsed+1); DWORD dwCkID ; DWORD dwCompFlags ; DWORD dwQuality = 100; if (ICCompress(m_Com.hic, 0,&m_OutInfo.bmiHeader, buffer, &m_InInfo.bmiHeader, (unsigned char *)lpVHdr->lpData, &dwCkID, &dwCompFlags, m_Frame++,0, dwQuality, NULL, NULL) == ICERR_OK) { AVIStreamSetFormat(ps,m_Frame,&m_OutInfo,sizeof(m_OutInfo)); AVIStreamWrite(ps,m_Frame ,1, (LPBYTE) buffer, m_OutInfo.bmiHeader.biSizeImage ,AVIIF_KEYFRAME,NULL,NULL); } delete []buffer; } return 1; } void InitCompress() { capGetVideoFormat(capwnd,&m_InInfo ,sizeof(BITMAPINFO)); capGetVideoFormat(capwnd,&m_OutInfo,sizeof(BITMAPINFO)); memset(&m_Com,0,sizeof(COMPVARS)); m_Com.cbSize=sizeof(m_Com); m_Com.dwFlags=ICMF_COMPVARS_VALID; m_Com.fccHandler=mmioFOURCC('x','v','i','d'); m_Com.fccType=ICTYPE_VIDEO; m_Com.lFrame=0; m_Com.lKey=15; m_Com.lKeyCount=0; m_Com.lDataRate = 780; m_Com.lpbiOut=(BITMAPINFO*)&m_OutInfo; m_Com.hic= ICOpen(ICTYPE_VIDEO,mmioFOURCC('x','v','i','d'),ICMODE_COMPRESS); m_Com.cbState = 1180; // ICCompressorChoose(NULL,ICMF_CHOOSE_ALLCOMPRESSORS , //(LPVOID)&m_InInfo,NULL,&m_Com,"...."); ICCompressGetFormat(m_Com.hic,&m_InInfo.bmiHeader,&m_OutInfo.bmiHeader); int ret = ICCompressBegin(m_Com.hic,(BITMAPINFO*)&m_InInfo, (BITMAPINFO*)&m_OutInfo); if (ret!=ICERR_OK ) MessageBox(NULL,"...",NULL,MB_OK); } void CALLBACK TimerProc(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime) { timeon=TRUE; } void TimeToName(char* name) { SYSTEMTIME systime; GetLocalTime(&systime); char buffer[5]; ZeroMemory(buffer,5); ltoa(systime.wYear,buffer,10); Cadd(name,buffer); ltoa(systime.wMonth,buffer,10); Cadd(name,buffer); ltoa(systime.wDay,buffer,10); Cadd(name,buffer); ltoa(systime.wHour,buffer,10); Cadd(name,buffer); ltoa(systime.wMinute,buffer,10); Cadd(name,buffer); Cadd(name,".avi"); } void Cadd(char * in,char * ad) { int lin=strlen(in); int lad=strlen(ad); for (int i=0;i



profile
제목 날짜
[TIP] PYTHON 에서 "UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 6987: illegal multibyte sequence" 오류 날때... 4 2016.02.20
[TIP] JQuery와 PHP로 이미지 파일을 업로드 하는 간단한 소스 (How to upload image file on PHP server by using JQuery) 2015.04.03
[TIP] TensorFlow를 윈도우에서 사용하기 (A way to use TensorFlow on Windows) 3 2016.04.16
[TIP] TensorFlow를 윈도우에서 사용하기 (A way to use TensorFlow on Windows) 3 2016.04.16
[TIP] 파이선으로 TED에서 가장많이 사용된 단어들 줄세우기 2016.04.03
[TIP] 파이선에서 구글 스프레드시트 사용하기 5 2016.03.27
[TIP] 파이선에서 리스트를 사용하는 재미있는 예제 2016.03.15
[TIP] PYTHON 에서 "UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 6987: illegal multibyte sequence" 오류 날때... 4 2016.02.20
[TIP] 퍼포먼스를 높여주는 몇가지 코딩 예 2016.01.22
[TIP] JQuery와 PHP로 이미지 파일을 업로드 하는 간단한 소스 (How to upload image file on PHP server by using JQuery) 2015.04.03
자작 커널을 위한 인터럽트 벡터 수정 (EZ-2410보드 대상) 2013.05.04
위치추적 1 2013.04.06
[TIP] MySQL - NaviCat 사용시 에러 확인방법 2010.02.23
[TIP] 설치된 코덱 리스트 얻어오기 2010.02.18
[TIP] VFW 에서 영상 압축을 위한 코덱을 코드상에서 선택하여 실시간 저장하는 방법입니다. 2010.02.04
[TIP] Visual Studio App Wizard 만들기 관련 2009.12.17
[TIP] C# 에서 Win32 DLL 을 사용하기 위한 방법 2009.07.16
[TIP] WMI 이용, 사용가능한 모뎀 포트 알아내기 2009.07.05
[TIP] Excel Ole 를 사용시 Hidden 열 혹은 행인지 알아내는 방법 2009.05.17
[TIP] Win32 API를 사용하여 응용 프로그램 열거하기 2009.01.15
[TIP] 홈페이지 자동 클릭하기 소스 2009.10.25
[TIP] (MSDN) VS2005 에서 BHO 만드는 방법 링크 2009.01.06
[TIP] Windows 에서 COM10 이상을 여는 방법 2 2008.05.26
태그 목록
위로