public int StartRecord(IntPtr CardHandle, string SaveName, string CodecName, DxMediaApi.TVidCodecX264Para dwH264CodecPara, Boolean AudioRec) { DxMediaApi.TDEVICE_TAG[] VidCodecInfo = new DxMediaApi.TDEVICE_TAG[125]; DxMediaApi.TDEVICE_TAG[] AuCodecInfo = new DxMediaApi.TDEVICE_TAG[125]; int CodecNum = 32; int CurCodec = 0; int AuCodecNum = 32; int AuCurCodec = 0; int Size = Marshal.SizeOf(typeof(DxMediaApi.TDEVICE_TAG)) * 32; IntPtr VideoCodecBuf = Marshal.AllocHGlobal(Size); IntPtr AudioCodecBuf = Marshal.AllocHGlobal(Size); //enum the video Codec DxMediaApi.DXEnumVideoCodecs(VideoCodecBuf, ref CodecNum); //enum the audio Codec DxMediaApi.DXEnumVideoCodecs(AudioCodecBuf, ref AuCodecNum); //set the video codec for (int i = 0; i < CodecNum; i++) { IntPtr VidCodecBuf = new IntPtr(VideoCodecBuf.ToInt64() + Marshal.SizeOf(typeof(DxMediaApi.TDEVICE_TAG)) * i); VidCodecInfo[i] = (DxMediaApi.TDEVICE_TAG)Marshal.PtrToStructure(VidCodecBuf, typeof(DxMediaApi.TDEVICE_TAG)); //set video codec if (VidCodecInfo[i].Name.ToLower() == CodecName.ToLower()) { CurCodec = i; break; } } //set the audio codec for (int i = 0; i < AuCodecNum; i++) { IntPtr AudCodecBuf = new IntPtr(AudioCodecBuf.ToInt64() + Marshal.SizeOf(typeof(DxMediaApi.TDEVICE_TAG)) * i); AuCodecInfo[i] = (DxMediaApi.TDEVICE_TAG)Marshal.PtrToStructure(AudCodecBuf, typeof(DxMediaApi.TDEVICE_TAG)); //set video codec if (AuCodecInfo[i].Name.ToLower() == CodecName.ToLower()) { AuCurCodec = i; break; } } //set the video codec DxMediaApi.DXSetVideoCodec(CardHandle, ref VidCodecInfo[CurCodec]); if (AudioRec == true) { DxMediaApi.DXSetAudioCodec(CardHandle, ref AuCodecInfo[AuCurCodec]); } //////////////////set the x264 video codec parameter string X264Name = "x264 Codec"; string XvidName = "xvid Codec"; if (VidCodecInfo[CurCodec].Name.ToLower() == X264Name.ToLower() || VidCodecInfo[CurCodec].Name.ToLower() == XvidName.ToLower()) { DxMediaApi.DXSetVideoCodecPara(CardHandle, 1, ref dwH264CodecPara); } Marshal.FreeHGlobal(VideoCodecBuf); Marshal.FreeHGlobal(AudioCodecBuf); // Marshal.FreeHGlobal(AudCodecBuf); // Marshal.FreeHGlobal(VidCodecBuf); int ok = 1; Point Notify; int nTimeValue = 0; int nSizeValue = 0; Notify = new Point(); ok = DxMediaApi.DXStartCapture(CardHandle, SaveName, AudioRec, ref nTimeValue, ref nSizeValue, Notify); return(ok); }
private void CodecSetFrm_Load(object sender, EventArgs e) { if (DxMediaFunction.DeviceInfo[Form1.nCard].dwVideoCodecStr == "DivX? 5.1.1 Codec") { rdDivx.Checked = true; } if (DxMediaFunction.DeviceInfo[Form1.nCard].dwVideoCodecStr == "XviD MPEG-4 Codec") { rdXvid.Checked = true; } if (DxMediaFunction.DeviceInfo[Form1.nCard].dwVideoCodecStr == "x264 Codec") { rdX264.Checked = true; } VideoCodecNum = 32; AudioCodecNum = 32; VideoCurCodec = 0; AudioCurCodec = 0; int i; for (i = 0; i < 125; i++) { VideoCodecInfo[i].idx = 0; VideoCodecInfo[i].Name = ""; AudioCodecInfo[i].idx = 0; AudioCodecInfo[i].Name = ""; } int Size = Marshal.SizeOf(typeof(DxMediaApi.TDEVICE_TAG)) * 32; IntPtr VideoCodecBuf = Marshal.AllocHGlobal(Size); IntPtr AudioCodecBuf = Marshal.AllocHGlobal(Size); //enum the video and the audio codec DxMediaApi.DXEnumVideoCodecs(VideoCodecBuf, ref VideoCodecNum); DxMediaApi.DXEnumAudioCodecs(AudioCodecBuf, ref AudioCodecNum); for (int j = 0; j < 32; j++) { IntPtr VidCodecBuf = new IntPtr(VideoCodecBuf.ToInt64() + Marshal.SizeOf(typeof(DxMediaApi.TDEVICE_TAG)) * j); VideoCodecInfo[j] = (DxMediaApi.TDEVICE_TAG)Marshal.PtrToStructure(VidCodecBuf, typeof(DxMediaApi.TDEVICE_TAG)); IntPtr AudCodecBuf = new IntPtr(AudioCodecBuf.ToInt64() + Marshal.SizeOf(typeof(DxMediaApi.TDEVICE_TAG)) * j); AudioCodecInfo[j] = (DxMediaApi.TDEVICE_TAG)Marshal.PtrToStructure(AudCodecBuf, typeof(DxMediaApi.TDEVICE_TAG)); } Marshal.FreeHGlobal(VideoCodecBuf); Marshal.FreeHGlobal(AudioCodecBuf); for (i = 0; i < VideoCodecNum; i++) { VideoCodecStr[i] = VideoCodecInfo[i].Name; comboBoxVidCodec.Items.Add(VideoCodecStr[i]); if ((VideoCodecStr[i] == "XviD MPEG-4 Codec") || (VideoCodecStr[i] == "Xvid MPEG-4 Codec")) { VideoCurCodec = i; } comboBoxVidCodec.SelectedIndex = VideoCurCodec; } for (i = 0; i < AudioCodecNum; i++) { AudioCodecStr[i] = AudioCodecInfo[i].Name; comboBoxAudCodec.Items.Add(AudioCodecStr[i]); if (AudioCodecStr[i] == "Microsoft ADPCM") { AudioCurCodec = i; } comboBoxAudCodec.SelectedIndex = AudioCurCodec; } }