效果图:
DirectShow採集核心代码:
创建线程调用该函数,採集图像通过x264解码封装rtmp协议包。推送至FMSserver,可实现视频直播
UINT __stdcall StartVideo(void *c) { CVideoConf *conf = (CVideoConf *)c; int vid = conf->code; CString strurl(conf->rtmpurl); CWnd *pW = conf->pW; CCameraDS camera; if (!camera.OpenCamera(0,false)); { TRACE("OpenCamera error....."); } while(true) { CvvImage cimg; CRect rect; IplImage *m_Frame ; BYTE *data1 = camera.QueryFrame(); m_Frame = cvCreateImageHeader(cvSize(320,240),IPL_DEPTH_8U,3); m_Frame->origin = 1; cvSetData(m_Frame,data1,320*3); CDC *pDC = pW->GetDC(); HDC hDC = pDC->GetSafeHdc(); pW->GetClientRect(&rect); cimg.CopyOf((IplImage *)m_Frame); //复制图片 cimg.DrawToHDC(hDC, &rect); //显示指定区域 HWND hWnd = pW->GetSafeHwnd(); ReleaseDC(hWnd,hDC); } return 0; }
Opencv採集核心代码:
UINT __stdcall StartVideo(void *c) { CVideoConf *conf = (CVideoConf *)c; int vid = conf->code; CString strurl(conf->rtmpurl); CWnd *pW = conf->pW; CCameraDS camera; if (!camera.OpenCamera(0,false)); { TRACE("OpenCamera error....."); } CvCapture* pCapture = cvCreateCameraCapture(0); //opencv打开视频 while(true) { CvvImage cimg; CRect rect; IplImage *m_Frame=cvQueryFrame( pCapture );//opencv捕获帧 CDC *pDC = pW->GetDC(); HDC hDC = pDC->GetSafeHdc(); pW->GetClientRect(&rect); cimg.CopyOf((IplImage *)m_Frame); //复制图片 cimg.DrawToHDC(hDC, &rect); //显示指定区域 HWND hWnd = pW->GetSafeHwnd(); ReleaseDC(hWnd,hDC); }
本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5125392.html,如需转载请自行联系原作者