1.用c#调用摄像头做录像功能
2.PJSIP源码探究 pjmedia-videodev模块
3.flv.js源码知识点(下) FLV格式解析
4.求一个控制摄像头小程序的源码源码,要求VC下编译运行
用c#调用摄像头做录像功能
前段时间刚做了个监控系统,源码有不明白+qq
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
using System;
namespace CamTest2
{
/// <summary>
/// 一个控制摄像头的源码类
/// </summary>
public class Pick
{
private const int WM_USER = 0x;
private const int WS_CHILD = 0x;
private const int WS_VISIBLE = 0x;
private const int WM_CAP_START = WM_USER;
private const int WM_CAP_STOP = WM_CAP_START + ;
private const int WM_CAP_DRIVER_CONNECT = WM_CAP_START + ;
private const int WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + ;
private const int WM_CAP_SAVEDIB = WM_CAP_START + ;
private const int WM_CAP_GRAB_FRAME = WM_CAP_START + ;
private const int WM_CAP_SEQUENCE = WM_CAP_START + ;
private const int WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + ;
private const int WM_CAP_SEQUENCE_NOFILE = WM_CAP_START + ;
private const int WM_CAP_SET_OVERLAY = WM_CAP_START + ;
private const int WM_CAP_SET_PREVIEW = WM_CAP_START + ;
private const int WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START + 6;
private const int WM_CAP_SET_CALLBACK_ERROR = WM_CAP_START + 2;
private const int WM_CAP_SET_CALLBACK_STATUSA = WM_CAP_START + 3;
private const int WM_CAP_SET_CALLBACK_FRAME = WM_CAP_START + 5;
private const int WM_CAP_SET_SCALE = WM_CAP_START + ;
private const int WM_CAP_SET_PREVIEWRATE = WM_CAP_START + ;
private const int WM_CAP_DLG_VIDEOFORMAT = WM_CAP_START + ;
private const int WM_CAP_DLG_VIDEOSOURCE = WM_CAP_START + ;
private const int WM_CAP_DLG_VIDEODISPLAY = WM_CAP_START + ;
private const int WM_CAP_DLG_VIDEOCOMPRESSION = WM_CAP_START + ;
private IntPtr hWndC;
private bool bStat = false;
private IntPtr mControlPtr;
private int mWidth;
private int mHeight;
private int mLeft;
private int mTop;
/// <summary>
/// 初始化摄像头
/// </summary>
/// <param name="handle">控件的句柄</param>
/// <param name="left">开始显示的左边距</param>
/// <param name="top">开始显示的上边距</param>
/// <param name="width">要显示的宽度</param>
/// <param name="height">要显示的长度</param>
public Pick(IntPtr handle, int left, int top, int width, int height)
{
mControlPtr = handle;
mWidth = width;
mHeight = height;
mLeft = left;
mTop = top;
}
[DllImport("avicap.dll")]
private static extern IntPtr capCreateCaptureWindowA(byte[] lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, int nID);
[DllImport("avicap.dll")]
private static extern int capGetVideoFormat(IntPtr hWnd, IntPtr psVideoFormat, int wSize);
[DllImport("User.dll")]
private static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, long lParam);
public void capDlgVideoFormat()
{
Boolean capDlgVideoFormat = SendMessage(hWndC, WM_CAP_DLG_VIDEOFORMAT, 0, 0);
}
public void capDlgVideoSource()
{
Boolean capDlgVideoSource = SendMessage(hWndC, WM_CAP_DLG_VIDEOSOURCE, 0, 0);
}
public void capDlgVideoDisplay()
{
Boolean capDlgVideoDisplay = SendMessage(hWndC, WM_CAP_DLG_VIDEODISPLAY, 0, 0);
}
public void capDlgVideoCompression()
{
Boolean capDlgVideoCompression = SendMessage(hWndC, WM_CAP_DLG_VIDEOCOMPRESSION, 0, 0);
}
/// <summary>
/// 开始显示图像
/// </summary>
public void Start()
{
if (bStat)
return;
bStat = true;
byte[] lpszName = new byte[];
hWndC = capCreateCaptureWindowA(lpszName, WS_CHILD | WS_VISIBLE, mLeft, mTop, mWidth, mHeight, mControlPtr, 0);
if (hWndC.ToInt() != 0)
{
SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);
SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0);
SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0);
SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);
SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0);
SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, , 0);
SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0);
SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0);
}
return;
}
/// <summary>
/// 停止显示
/// </summary>
public void Stop()
{
SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0);
bStat = false;
}
/// <summary>
/// 抓图
/// </summary>
/// <param name="path">要保存bmp文件的路径</param>
public void GrabImage(string path)
{
IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);
SendMessage(hWndC, WM_CAP_SAVEDIB, 0, hBmp.ToInt());
}
/// <summary>
/// 录像
/// </summary>
/// <param name="path">要保存avi文件的路径</param>
public void Kinescope(string path)
{
IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);
SendMessage(hWndC, WM_CAP_FILE_SET_CAPTURE_FILEA, 0, hBmp.ToInt());
SendMessage(hWndC, WM_CAP_SEQUENCE, 0, 0);
}
/// <summary>
/// 停止录像
/// </summary>
public void StopKinescope()
{
SendMessage(hWndC, WM_CAP_STOP, 0, 0);
}
/* public void cap()
{
CAPTUREPARMS s;
capCaptureGetSetup(m_caphwnd,&s,sizeof(CAPTUREPARMS));//取得采集参数
s.dwRequestMicroSecPerFrame = ;//采集一帧花费1/秒
s.fAbortLeftMouse = FALSE;//压下鼠标左键不终止采集
s.fAbortRightMouse = FALSE;//压下鼠标右键不终止采集
s.fCaptureAudio = TRUE;//c采集音频
s.fYield = TRUE;//使用一个独立的线程来采集视频,不使用View窗口线程
capCaptureSetSetup(m_caphwnd,源码&s,sizeof(CAPTUREPARMS));//设定采集参数
}*/
}
}
PJSIP源码探究 pjmedia-videodev模块
PJMEDIA-Videodev模块详解:在PJSIP中的视频捕获功能实现
PJSIP中,pjmedia-videodev模块扮演着关键角色,源码它负责视频捕获功能,源码空间说说秒赞源码让开发者能够在应用中集成自定义画面捕获设备。源码为了深入了解,源码首先需要理解pjsua2中的源码工作流程,包括Endpoint对象的源码使用和相关c++函数的调用,如pjsua_create、源码pjsua_start和pjsua_init等。源码
在pjsip的源码源码中,视频捕获设备的源码初始化过程始于pjsua_media_subsys_init,这个函数通过pjsua_media_config_default参数,源码初始化了媒体子系统,其中包括视频和音频子系统。opens论坛框架源码其中,pjmedia_vid_subsys_init在pjmedia-videodev模块的pjmedia_vid.c中被调用,用于初始化视频捕获设备子系统。
在Android环境下,pjmedia_and_factory是关键,它会在编译时根据平台特性注册到视频子系统中。当需要视频捕获时,会通过这个工厂创建具体设备,tomcat 源码分析 请求如摄像头,并获取画面。pjmedia-videodev-factory在android_dev.c文件中实现,包含了设备查找、参数设置和流创建等功能,如and_factory_init、and_factory_create_stream等。
视频流的丝瓜视频源码Aqq管理主要通过pjmedia_vid_dev_stream结构体和对应的stream_op函数,如and_stream_get_param、and_stream_set_cap等,它们控制摄像头的设置和画面捕获。在自定义捕获中,可以通过这些接口添加时间水印,创造出更为丰富的视频体验。
总之,pjmedia-videodev模块为PJSIP提供了灵活的flink提交offset源码视频捕获能力,开发者可以根据需求定制捕获设备和功能。理解并掌握这一模块的工作原理,将有助于在实际项目中实现个性化的视频通话体验。
flv.js源码知识点(下) FLV格式解析
在flv.js系列文章的最后篇章中,我们将深入探讨FLV格式解析。FLVDemuxer是flv.js中的关键组件,但理解它之前,必须先熟悉FLV文件的数据结构和JavaScript中处理二进制数据的方法。
FLV文件,Adobe的Flash Video格式,由固定的FLVHeader和可变的FLVBody构成。FLVHeader包括9字节的固定信息,如类型和大小,而FLVBody由多个Tag组成,每个Tag由Tag Header和Tag Data构成。理解这些结构对于解析至关重要。
要操作FLV数据,我们需要掌握如何使用JavaScript的ArrayBuffer和DataView。DataView类提供了读取不同字节类型的API,如getUint8和getUint,理解字节序(小字节序与大字节序)也很重要。此外,位操作技巧,如按位与、或、异或以及位移,能在处理多字节数据和特定位信息时派上用场。
总的来说,理解FLV格式的详细结构,熟练运用二进制数据读取技术,是解析flv.js源码的关键。接下来,就是根据FLV规范,逐个字段解析数据了。
求一个控制摄像头小程序的源码,要求VC下编译运行
VC-摄像头控制SDK源码
#include <windows.h>
#include <stdio.h>
#include <vfw.h>
#pragma comment(lib,"vfw.lib")
HWND ghWndCap ; //捕获窗的句柄
CAPDRIVERCAPS gCapDriverCaps ; //视频驱动器的能力
CAPSTATUS gCapStatus ; //捕获窗的状态
char szCaptureFile[] = "MYCAP.AVI";
char gachBuffer[];
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
LRESULT CALLBACK StatusCallbackProc(HWND hWnd,int nID,LPSTR lpStatusText)
{
if(!ghWndCap)return FALSE;//获得捕获窗的状态
capGetStatus(ghWndCap,&gCapStatus,sizeof(CAPSTATUS));//更新捕获窗的大小
SetWindowPos(ghWndCap,NULL,0,0,gCapStatus.uiImageWidth,gCapStatus.uiImageHeight,SWP_NOZORDER|SWP_NOMOVE);
if(nID==0){ //清除旧的状态信息
SetWindowText(ghWndCap,(LPSTR)"hello");
return (LRESULT)TRUE;
}//显示状态ID和状态文本
wsprintf(gachBuffer,"Status# %d: %s",nID,lpStatusText);
SetWindowText(ghWndCap,(LPSTR)gachBuffer);
return (LRESULT)TRUE;
}
LRESULT CALLBACK ErrorCallbackProc(HWND hWnd,int nErrID,LPSTR lpErrorText)
{
if(!ghWndCap)return FALSE;
if(nErrID==0)return TRUE;//清除旧的错误
wsprintf(gachBuffer,"Error# %d",nErrID);//显示错误标识和文本
MessageBox(hWnd, lpErrorText, gachBuffer,MB_OK | MB_ICONEXCLAMATION);
return (LRESULT) TRUE;
}
LRESULT CALLBACK FrameCallbackProc(HWND hWnd,LPVIDEOHDR lpVHdr)
{
FILE *fp;
fp=fopen("caram.dat","w");
if(!ghWndCap)return FALSE;//假设fp为一打开的.dat文件指针
fwrite(lpVHdr->lpData,1,lpVHdr->dwBufferLength,fp);
return (LRESULT)TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
static TCHAR szAppName[]=TEXT("HelloWin");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=szAppName;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("This program requires WindowsNT!"),szAppName,MB_ICONERROR);
return 0;
}
hwnd=CreateWindow(szAppName,TEXT("The Hello Program"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch(message)
{
case WM_CREATE:
{
ghWndCap=capCreateCaptureWindow((LPSTR)"Capture Window",WS_CHILD|WS_VISIBLE,0,0,,,(HWND)hwnd,(int)0);
capSetCallbackOnError(ghWndCap,(FARPROC)ErrorCallbackProc);
capSetCallbackOnStatus(ghWndCap,(FARPROC)StatusCallbackProc);
capSetCallbackOnFrame(ghWndCap,(FARPROC)FrameCallbackProc);
capDriverConnect(ghWndCap,0); // 将捕获窗同驱动器连接
//获得驱动器的能力,相关的信息放在结构变量gCapDriverCaps中
capDriverGetCaps(ghWndCap,&gCapDriverCaps,sizeof(CAPDRIVERCAPS));
capPreviewRate(ghWndCap, ); // 设置Preview模式的显示速率
capPreview(ghWndCap, TRUE); //启动Preview模式
if(gCapDriverCaps.fHasOverlay) //检查驱动器是否有叠加能力
capOverlay(ghWndCap,TRUE); //启动Overlay模式
if(gCapDriverCaps.fHasDlgVideoSource)capDlgVideoSource(ghWndCap); //Video source 对话框
if(gCapDriverCaps.fHasDlgVideoFormat)capDlgVideoFormat(ghWndCap); // Video format 对话框
if(gCapDriverCaps.fHasDlgVideoDisplay)capDlgVideoDisplay(ghWndCap); // Video display 对话框
capFileSetCaptureFile( ghWndCap, szCaptureFile); //指定捕获文件名
capFileAlloc(ghWndCap, (L * L * 5)); //为捕获文件分配存储空间
capCaptureSequence(ghWndCap); //开始捕获视频序列
capGrabFrame(ghWndCap); //捕获单帧图像
}
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
DrawText(hdc,TEXT("Hello,Windows!"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
{
capSetCallbackOnStatus(ghWndCap,NULL);
capSetCallbackOnError(ghWndCap,NULL);
capSetCallbackOnFrame(ghWndCap,NULL);
capCaptureAbort(ghWndCap);//停止捕获
capDriverDisconnect(ghWndCap); //将捕获窗同驱动器断开
PostQuitMessage(0);
}
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}