1.4.4 VideoOperate類
VideoOperate類主要封裝了操作視頻采集卡的各種枚舉及方法,由于要調(diào)用Sa7134Capture.dll動態(tài)鏈接庫,所以首先要引用命名空間using System.Runtime.InteropServices。封裝Sa7134Capture.dll動態(tài)鏈接庫中各種枚舉及方法的關鍵代碼如下:
例程09 代碼位置:光盤\TM\01\VWMS\VWMS\CommonClass\VideoOperate.cs
#region 視頻采集卡中的枚舉
public enum DISPLAYTRANSTYPE
{
NOT_DISPLAY = 0,
PCI_VIEDOMEMORY = 1,
PCI_MEMORY_VIDEOMEMORY = 2
}
//視頻預覽和視頻捕捉數(shù)據(jù)流格式,目前版本只支持UUY2格式
public enum COLORFORMAT
{
RGB32 = 0x0,
RGB24 = 0x1,
RGB16 = 0x2,
RGB15 = 0x3,
YUY2 = 0x4,
TYUV = 0x5,
8 = 0x6,
GB8 = 0x7,
L422 = 0x8,
L411 = 0x9,
UV12 = 0xA,
UV9 = 0xB,
AW = 0xE
}
/*視頻預覽及視頻捕獲的顯示屬性,其中:
BRIGHTNESS為亮度,value范圍:0~255,最佳:80
CONTRAST為對比度,value范圍:-128~127,最佳:x44
SATURATION為飽和度,value范圍:-128~127,最佳:x40
HUE為色度,value范圍:-128~127,最佳:x0
只有當COLORDEVICETYPE等于COLOR_DECODER時才有效
SHARPNESS為銳度,value范圍:-8~7,最佳:x0
只有當COLORDEVICETYPE等于COLOR_DECODER時才有效
*/
public enum COLORCONTROL
{
BRIGHTNESS = 0,
CONTRAST = 1,
SATURATION = 2,
HUE = 3,
SHARPNESS = 4
}
/*顯示設備的顯示屬性,其中:
COLOR_DECODER為解碼器的顯示屬性,它會影響視頻預覽和視頻捕獲的顯示屬性
COLOR_PREVIEW為視頻預覽的顯示屬性
COLOR_CAPTURE為視頻捕獲的顯示屬性
*/
pblic enum COLORDEVICETYPE
{
COLOR_DECODER = 0,
COLOR_PREVIEW = 1,
COLOR_CAPTURE = 2,
}
/*視頻捕獲方式,其中:
CAP_NULL_STREAM 捕獲無效
CAP_ORIGIN_STREAM 捕獲為原始流回調(diào)
CAP_MPEG4_STREAM 捕獲為MPEG4
*/
public enum CAPMODEL
{
CAP_NULL_STREAM = 0,
CAP_ORIGIN_STREAM = 1,
CAP_MPEG4_STREAM = 2,
}
/*音視頻MPEG4捕獲方式,只有CAPMODEL等于CAP_MPEG4_STREAM時有效,其中:
MPEG4_AVIFILE_ONLY 存為MPEG4文件
MPEG4_CALLBACK_ONLY MPEG數(shù)據(jù)回調(diào)
MPEG4_AVIFILE_CALLBACK 存為MPEG文件并回調(diào)
*/
public enum MP4MODEL
{
MPEG4_AVIFILE_ONLY = 0,
MPEG4_CALLBACK_ONLY = 1,
MPEG4_AVIFILE_CALLBACK = 2,
}
/*MPEG4_XVID壓縮模式,其中:
XVID_CBR_MODE (固定碼率模式)
XVID_VBR_MODE (動態(tài)碼率模式)
*/
public enum COMPRESSMODE
{
XVID_CBR_MODE = 0,
XVID_VBR_MODE = 1,
}
/*視頻源的輸入頻率,其中:
FIELD_FREQ_50HZ 50HZ,絕對多數(shù)為PAL制式
FIELD_FREQ_60HZ 60HZ,絕對多數(shù)為NTSC制式
FIELD_FREQ_0HZ,無信號
*/
public enum eFieldFrequency
{
FIELD_FREQ_50HZ = 0,
FIELD_FREQ_60HZ = 1,
FIELD_FREQ_0HZ = 2,
}
/*電平狀態(tài),其中:
HIGH_VOLTAGE為高電平
LOW_VOLTAGE為低電平
*/
public enum eVOLTAGELEVEL
{
HIGH_VOLTAGE = 0,
LOW_VOLTAGE = 1,
}
#endregion
#region 視頻采集卡中的API函數(shù)
//初始化系統(tǒng)資源
[DllImport("Sa7134Capture.dll", EntryPoint = "VCAInitSdk")]
public extern static bool VCAInitSdk(IntPtr hWndMain, DISPLAYTRANSTYPE eDispTransType, bool bLnitAuDev);
//釋放系統(tǒng)資源
[DllImport("Sa7134Capture.dll", EntryPoint = "VCAUnInitSdk")]
public extern static void VCAUnInitSdk();
//打開指定卡號的設備,分配相應系統(tǒng)資源
[DllImport("Sa7134Capture.dll", EntryPoint = "VCAOpenDevice")]
public extern static bool VCAOpenDevice(Int32 dwCard, IntPtr hPreviewWnd);
//關閉指定卡號的設備,釋放相應系統(tǒng)資源
[DllImport("Sa7134Capture.dll", EntryPoint = "VCACloseDevice")]
public extern static bool VCACloseDevice(Int32 dwCard);
//返回系統(tǒng)當中卡號數(shù)量,即為SAA7134硬件數(shù)目,為0時表示沒有設備存在
[DllImport("Sa7134Capture.dll", EntryPoint = "VCAGetDevNum")]
public extern static int VCAGetDevNum();
//開始視頻預覽
[DllImport("Sa7134Capture.dll", EntryPoint = "VCAStartVideoPreview")]
public extern static bool VCAStartVideoPreview(Int32 dwCard);
//停止視頻預覽
[DllImport("Sa7134Capture.dll", EntryPoint = "VCAStopVideoPreview")]
public extern static bool VCAStopVideoPreview(Int32 dwCard);
//更新視頻預覽
[DllImport("Sa7134Capture.dll", EntryPoint = "VCAUpdateVideoPreview")]
public extern static bool VCAUpdateVideoPreview(Int32 dwCard, IntPtr hPreviewWnd);
//更新overlay窗口,當overlay窗口句柄改變或尺寸、位置改變時調(diào)用,overlay窗口就是包含
//多路顯示小窗口的大窗口,overlay窗口必須有一個,多路顯示小窗口必須包含在其內(nèi)部
[DllImport("Sa7134Capture.dll", EntryPoint = "VCAUpdateOverlayWnd")]
public extern static bool VCAUpdateOverlayWnd(IntPtr hOverlayWnd);
//保存快照為JPEG文件
[DllImport("Sa7134Capture.dll", EntryPoint = "VCASaveAsJpegFile")]
public extern static bool VCASaveAsJpegFile(Int32 dwCard, string lpFileName, Int32 dwQuality);
//保存快照為BMP文件
[DllImport("Sa7134Capture.dll", EntryPoint = "VCASaveAsBmpFile")]
public extern static bool VCASaveAsBmpFile(Int32 dwCard, string lpFileName);
//開始視頻捕獲
[DllImport("Sa7134Capture.dll", EntryPoint = "VCAStartVideoCapture")]
public extern static bool VCAStartVideoCapture(Int32 dwCard, CAPMODEL enCapMode, MP4MODEL enMp4Mode, string lpFileName);
//停止視頻捕獲
[DllImport("Sa7134Capture.dll", EntryPoint = "VCAStopVideoCapture")]
public extern static bool VCAStopVideoCapture(Int32 dwCard);
//設置視頻捕獲尺寸,dwWidth和dwHeight最好為16的倍數(shù),否則,動態(tài)檢測為16×16的一個檢測小塊,檢測將會不準確
[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetVidCapSize")]
public extern static bool VCASetVidCapSize(Int32 dwCard, Int32 dwWidth, Int32 dwHeight);
//得到視頻捕獲尺寸
[DllImport("Sa7134Capture.dll", EntryPoint = "VCAGetVidCapSize")]
public extern static bool VCAGetVidCapSize(Int32 dwCard, Int32 dwWidth, Int32 dwHeight);
//設置視頻捕獲頻率
[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetVidCapFrameRate")]
public extern static bool VCASetVidCapFrameRate(Int32 dwCard, Int32 dwFrameRate, bool bFrameRateReduction);
//設置MPEG壓縮的位率
[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetBitRate")]
public extern static bool VCASetBitRate(Int32 dwCard, Int32 dwBitRate);
//設置MPEG壓縮的關鍵幀間隔,必須大于等于幀率
[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetKeyFrmInterval")]
public extern static bool VCASetKeyFrmInterval(Int32 dwCard, Int32 dwKeyFrmInterval);
//設置MPEG4_XVID壓縮的質(zhì)量
[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetXVIDQuality")]
public extern static bool VCASetXVIDQuality(Int32 dwCard, Int32 dwQuantizer, Int32 dwMotionPrecision);
//設置MPEG4_XVID壓縮的模式
[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetXVIDCompressMode")]
public extern static bool VCASetXVIDCompressMode(Int32 dwCard, COMPRESSMODE enCompessMode);
//設置視頻顏色屬性,它將影響視頻預覽和視頻捕獲的顯示屬性
[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetVidDeviceColor")]
public extern static bool VCASetVidDeviceColor(Int32 dwCard, COLORCONTROL enCtlType, Int32 dwValue);
//得到視頻源輸入頻率,即可得到視頻源輸入制式
[DllImport("Sa7134Capture.dll", EntryPoint = "VCAGetVidFieldFrq")]
public extern static bool VCAGetVidFieldFrq(Int32 dwCard, eFieldFrequency eVidSourceFieldRate);
//初始化視頻設備,當視頻不顯示,只需視頻錄像獲得音頻處理時,或通過VCAInitSdk()函數(shù)已經(jīng)初始化完成,
//可以不初始化
[DllImport("Sa7134Capture.dll", EntryPoint = "VCAInitVidDev")]
public extern static bool VCAInitVidDev();
#endregion