码迷,mamicode.com
首页 > Web开发 > 详细

DirectShowNet 使用摄像头录像+录音

时间:2016-11-11 00:00:56      阅读:495      评论:0      收藏:0      [点我收藏+]

标签:tun   library   initial   mode   runtime   curd   putty   rar   .text   

http://www.cnblogs.com/endv/p/6052511.html

   1 // ------------------------------------------------------------------
   2 // CaptureTest.cs
   3 // Sample application to show the DirectX.Capture class library.
   4 //
   5 // History:
   6 //    2003-Jan-25        BL        - created
   7 //
   8 // Copyright (c) 2003 Brian Low
   9 // ------------------------------------------------------------------
  10 
  11 using DirectShowLib;
  12 using DirectX.Capture;
  13 using System;
  14 using System.Diagnostics;
  15 using System.Drawing;
  16 using System.Runtime.InteropServices;
  17 using System.Text;
  18 using System.Windows.Forms;
  19 
  20 namespace CaptureTest
  21 {
  22     public class CaptureTest : System.Windows.Forms.Form
  23     {
  24         /// <summary>
  25         /// 应用程序的主要入口点 
  26         /// </summary>
  27         [STAThread]
  28         static void Main()
  29         {
  30             AppDomain currentDomain = AppDomain.CurrentDomain;
  31             Application.Run(new CaptureTest());
  32             GC.Collect();
  33             GC.WaitForPendingFinalizers();
  34         }
  35 
  36         // kernel32.dll是Windows9x/Me中非常重要的32位动态链接库文件,属于内核级文件。它控制着系统的内存管理、数据的输入输出操作和中断处理,
  37         // 当Windows启动时,kernel32.dll就驻留在内存中特定的写保护区域,使别的程序无法占用这个内存区域
  38         [DllImport("kernel32.dll")]
  39         static extern uint GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, uint nSize, string lpFileName);
  40 
  41         [DllImport("kernel32.dll")]
  42         static extern uint WritePrivateProfileString(string lpAppName, string lpKeyName, string lpString, string lpFileName);
  43 
  44         const int WM_GRAPHNOTIFY = 0x8000 + 1;
  45         private long iDroppedBefore = 0;
  46         private DateTime dtBefore;
  47         private IMediaEventEx mediaEvent = null;
  48         private int CaptureResult;
  49         private 捕获 capture = null;
  50         private Filters filters = new Filters();
  51         private Size m_FrameSize; // Reading the value from capture.Framesize derenders the graph
  52 
  53         public CaptureTest()
  54         {
  55             InitializeComponent(); // 所需的窗体设计器支持
  56 
  57             LoadDevices();//负载设备
  58 
  59             if (capture != null)
  60             {
  61                 LoadDeviceSettings();//加载设备设置
  62                 LoadCompressors();//加载压缩机
  63             }
  64 
  65             // 更新主菜单中的许多有趣的工作,这个示例发生在这里
  66             try { updateMenu(); } catch { }
  67 
  68             // 由于压缩机设置不在菜单上,不需要再做 updatemenu 。
  69             // 已后要做的 updatemenu 由于其中一个调用重置这些。
  70 
  71             if (capture != null)
  72             {
  73                 LoadCompressorSettings();//加载压缩机设置
  74             }
  75         }
  76 
  77 
  78         #region 加载
  79         //加载设备
  80         protected void LoadDevices()
  81         {
  82             int x;
  83             int iVideoDeviceIndex = -1;
  84             int iAudioDeviceIndex = -1;
  85             StringBuilder sbOut = new StringBuilder(500);
  86 
  87             string sConfigFile = Application.LocalUserAppDataPath + "\\..\\Config.ini";
  88 
  89             GetPrivateProfileString("Devices", "VideoDevice", "", sbOut, 500, sConfigFile);
  90 
  91             if (sbOut.Length > 0)
  92             {
  93                 for (x = 0; x < filters.VideoInputDevices.Count; x++)
  94                 {
  95                     if (filters.VideoInputDevices[x].Name == sbOut.ToString())
  96                     {
  97                         iVideoDeviceIndex = x;
  98                         break;
  99                     }
 100                 }
 101             }
 102 
 103             GetPrivateProfileString("Devices", "AudioDevice", "", sbOut, 500, sConfigFile);
 104 
 105 
 106             if (sbOut.Length > 0)
 107             {
 108                 for (x = 0; x < filters.AudioInputDevices.Count; x++)
 109                 {
 110                     if (filters.AudioInputDevices[x].Name == sbOut.ToString())
 111                     {
 112                         iAudioDeviceIndex = x;
 113                         break;
 114                     }
 115                 }
 116             }
 117 
 118             if ((iVideoDeviceIndex >= 0) || (iAudioDeviceIndex >= 0))
 119             {
 120                 Filter i, j;
 121 
 122                 if (iVideoDeviceIndex >= 0)
 123                     i = filters.VideoInputDevices[iVideoDeviceIndex];
 124                 else
 125                     i = null;
 126 
 127                 if (iAudioDeviceIndex >= 0)
 128                     j = filters.AudioInputDevices[iAudioDeviceIndex];
 129                 else
 130                     j = null;
 131 
 132                 capture = new 捕获(i, j);
 133 
 134                 capture.CaptureComplete += new EventHandler(OnCaptureComplete);
 135 
 136                 if (iVideoDeviceIndex >= 0)
 137                 {
 138                     GetPrivateProfileString("Devices", "VideoSource", "", sbOut, 500, sConfigFile);
 139 
 140                     for (x = 0; x < capture.VideoSources.Count; x++)
 141                     {
 142                         if (capture.VideoSources[x].Name == sbOut.ToString())
 143                         {
 144                             capture.VideoSource = capture.VideoSources[x];
 145                             break;
 146                         }
 147                     }
 148                 }
 149 
 150                 if (iAudioDeviceIndex >= 0)
 151                 {
 152                     GetPrivateProfileString("Devices", "AudioSource", "", sbOut, 500, sConfigFile);
 153 
 154                     for (x = 0; x < capture.AudioSources.Count; x++)
 155                     {
 156                         if (capture.AudioSources[x].Name == sbOut.ToString())
 157                         {
 158                             capture.AudioSource = capture.AudioSources[x];
 159                             break;
 160                         }
 161                     }
 162                 }
 163             }
 164         }
 165 
 166         //加载设备设置
 167         protected void LoadDeviceSettings()
 168         {
 169             StringBuilder sbOut = new StringBuilder(500);
 170             string sConfigFile = Application.LocalUserAppDataPath + "\\..\\Config.ini";
 171 
 172             if (capture.VideoDevice != null)
 173             {
 174                 GetPrivateProfileString("DeviceSettings", "FrameRate", "", sbOut, 500, sConfigFile);
 175                 if (sbOut.Length > 0)
 176                     capture.FrameRate = Convert.ToDouble(sbOut.ToString());
 177 
 178                 GetPrivateProfileString("DeviceSettings", "VideoWidth", "", sbOut, 500, sConfigFile);
 179                 if (sbOut.Length > 0)
 180                 {
 181                     Size size = new Size(Convert.ToInt32(sbOut.ToString()), 0);
 182 
 183                     GetPrivateProfileString("DeviceSettings", "VideoHeight", "", sbOut, 500, sConfigFile);
 184                     if (sbOut.Length > 0)
 185                     {
 186                         size.Height = Convert.ToInt32(sbOut.ToString());
 187                         capture.FrameSize = size;
 188                     }
 189                 }
 190             }
 191 
 192             if (capture.AudioDevice != null)
 193             {
 194                 GetPrivateProfileString("DeviceSettings", "AudioChannel", "", sbOut, 500, sConfigFile);
 195                 if (sbOut.Length > 0)
 196                 {
 197                     capture.AudioChannels = Convert.ToInt16(sbOut.ToString());
 198                 }
 199 
 200                 GetPrivateProfileString("DeviceSettings", "AudioRate", "", sbOut, 500, sConfigFile);
 201                 if (sbOut.Length > 0)
 202                 {
 203                     capture.AudioSamplingRate = Convert.ToInt32(sbOut.ToString());
 204                 }
 205 
 206                 GetPrivateProfileString("DeviceSettings", "AudioSize", "", sbOut, 500, sConfigFile);
 207                 if (sbOut.Length > 0)
 208                 {
 209                     capture.AudioSampleSize = Convert.ToInt16(sbOut.ToString());
 210                 }
 211 
 212                 GetPrivateProfileString("DeviceSettings", "AudioChannel", "", sbOut, 500, sConfigFile);
 213                 if (sbOut.Length > 0)
 214                 {
 215                     capture.AudioChannels = Convert.ToInt16(sbOut.ToString());
 216                 }
 217             }
 218 
 219         }
 220         //加载压缩机
 221         protected void LoadCompressors()
 222         {
 223             int x;
 224             StringBuilder sbOut = new StringBuilder(500);
 225             string sConfigFile = Application.LocalUserAppDataPath + "\\..\\Config.ini";
 226 
 227             if (capture.VideoDevice != null)
 228             {
 229                 GetPrivateProfileString("Compressor", "VideoCompressor", "", sbOut, 500, sConfigFile);
 230 
 231                 if (sbOut.Length > 0)
 232                 {
 233                     for (x = 0; x < filters.VideoCompressors.Count; x++)
 234                     {
 235                         if (filters.VideoCompressors[x].Name == sbOut.ToString())
 236                         {
 237                             capture.VideoCompressor = filters.VideoCompressors[x];
 238                             break;
 239                         }
 240                     }
 241                 }
 242             }
 243 
 244             if (capture.AudioDevice != null)
 245             {
 246                 GetPrivateProfileString("Compressor", "AudioCompressor", "", sbOut, 500, sConfigFile);
 247 
 248                 for (x = 0; x < filters.AudioCompressors.Count; x++)
 249                 {
 250                     if (filters.AudioCompressors[x].Name == sbOut.ToString())
 251                     {
 252                         capture.AudioCompressor = filters.AudioCompressors[x];
 253                         break;
 254                     }
 255                 }
 256             }
 257         }
 258         //加载压缩机设置
 259         protected void LoadCompressorSettings()
 260         {
 261             StringBuilder sbOut = new StringBuilder(500);
 262             string sConfigFile = Application.LocalUserAppDataPath + "\\..\\Config.ini";
 263 
 264             if (capture.VideoCompressor != null)
 265             {
 266                 try
 267                 {
 268                     VideoCompressorCaps i = capture.VideoCompressorCaps;
 269 
 270                     GetPrivateProfileString("Compressor", "KeyFrameRate", "", sbOut, 500, sConfigFile);
 271                     if (sbOut.Length > 0)
 272                         i.KeyFrameRate = Convert.ToInt32(sbOut.ToString());
 273 
 274                     GetPrivateProfileString("Compressor", "PFrames", "", sbOut, 500, sConfigFile);
 275                     if (sbOut.Length > 0)
 276                         i.PFramesPerKeyFrame = Convert.ToInt32(sbOut.ToString());
 277 
 278                     GetPrivateProfileString("Compressor", "WindowSize", "", sbOut, 500, sConfigFile);
 279                     if (sbOut.Length > 0)
 280                         i.WindowSize = Convert.ToInt64(sbOut.ToString());
 281 
 282                     GetPrivateProfileString("Compressor", "Quality", "", sbOut, 500, sConfigFile);
 283                     if (sbOut.Length > 0)
 284                         i.Quality = Convert.ToInt32(sbOut.ToString());
 285                 }
 286                 catch { }
 287             }
 288         }
 289 
 290         //保存默认设置  "\\..\\Config.ini"
 291         protected void SaveDefaults()
 292         {
 293             string sConfigFile = Application.LocalUserAppDataPath + "\\..\\Config.ini";
 294 
 295             if (capture != null)
 296             {
 297                 if (capture.VideoDevice != null)
 298                 {
 299                     WritePrivateProfileString("Devices", "VideoDevice", capture.VideoDevice.Name, sConfigFile);
 300                     WritePrivateProfileString("DeviceSettings", "FrameRate", capture.FrameRate.ToString(), sConfigFile);
 301                     WritePrivateProfileString("DeviceSettings", "VideoWidth", capture.FrameSize.Width.ToString(), sConfigFile);
 302                     WritePrivateProfileString("DeviceSettings", "VideoHeight", capture.FrameSize.Height.ToString(), sConfigFile);
 303                 }
 304                 else
 305                 {
 306                     WritePrivateProfileString("Devices", "VideoDevice", "", sConfigFile);
 307                     WritePrivateProfileString("DeviceSettings", "FrameRate", "", sConfigFile);
 308                     WritePrivateProfileString("DeviceSettings", "VideoWidth", "", sConfigFile);
 309                     WritePrivateProfileString("DeviceSettings", "VideoHeight", "", sConfigFile);
 310                 }
 311                 if (capture.AudioDevice != null)
 312                 {
 313                     WritePrivateProfileString("Devices", "AudioDevice", capture.AudioDevice.Name, sConfigFile);
 314                     WritePrivateProfileString("DeviceSettings", "AudioChannel", capture.AudioChannels.ToString(), sConfigFile);
 315                     WritePrivateProfileString("DeviceSettings", "AudioRate", capture.AudioSamplingRate.ToString(), sConfigFile);
 316                     WritePrivateProfileString("DeviceSettings", "AudioSize", capture.AudioSampleSize.ToString(), sConfigFile);
 317                 }
 318                 else
 319                 {
 320                     WritePrivateProfileString("Devices", "AudioDevice", "", sConfigFile);
 321                     WritePrivateProfileString("DeviceSettings", "AudioChannel", "", sConfigFile);
 322                     WritePrivateProfileString("DeviceSettings", "AudioRate", "", sConfigFile);
 323                     WritePrivateProfileString("DeviceSettings", "AudioSize", "", sConfigFile);
 324                 }
 325                 if (capture.VideoCompressor != null)
 326                 {
 327                     WritePrivateProfileString("Compressor", "VideoCompressor", capture.VideoCompressor.Name, sConfigFile);
 328 
 329                     CompressionCaps i = CompressionCaps.None;
 330 
 331                     try
 332                     {
 333                         i = capture.VideoCompressorCaps.GetCaps;
 334                     }
 335                     catch { }
 336 
 337                     if ((i & CompressionCaps.CanKeyFrame) > 0)
 338                         WritePrivateProfileString("Compressor", "KeyFrameRate", capture.VideoCompressorCaps.KeyFrameRate.ToString(), sConfigFile);
 339 
 340                     if ((i & CompressionCaps.CanBFrame) > 0)
 341                         WritePrivateProfileString("Compressor", "PFrames", capture.VideoCompressorCaps.PFramesPerKeyFrame.ToString(), sConfigFile);
 342 
 343                     if ((i & CompressionCaps.CanWindow) > 0)
 344                         WritePrivateProfileString("Compressor", "WindowSize", capture.VideoCompressorCaps.WindowSize.ToString(), sConfigFile);
 345 
 346                     if ((i & CompressionCaps.CanQuality) > 0)
 347                         WritePrivateProfileString("Compressor", "Quality", capture.VideoCompressorCaps.Quality.ToString(), sConfigFile);
 348 
 349                 }
 350                 else
 351                 {
 352                     WritePrivateProfileString("Compressor", "VideoCompressor", "", sConfigFile);
 353                     WritePrivateProfileString("Compressor", "KeyFrameRate", "", sConfigFile);
 354                     WritePrivateProfileString("Compressor", "PFrames", "", sConfigFile);
 355                     WritePrivateProfileString("Compressor", "WindowSize", "", sConfigFile);
 356                     WritePrivateProfileString("Compressor", "Quality", "", sConfigFile);
 357                 }
 358                 if (capture.AudioCompressor != null)
 359                 {
 360                     WritePrivateProfileString("Compressor", "AudioCompressor", capture.AudioCompressor.Name, sConfigFile);
 361                 }
 362                 else
 363                 {
 364                     WritePrivateProfileString("Compressor", "AudioCompressor", "", sConfigFile);
 365                 }
 366                 if (capture.VideoSource != null)
 367                 {
 368                     WritePrivateProfileString("Devices", "VideoSource", capture.VideoSource.Name, sConfigFile);
 369                 }
 370                 else
 371                 {
 372                     WritePrivateProfileString("Devices", "VideoSource", "", sConfigFile);
 373                 }
 374                 if (capture.AudioSource != null)
 375                 {
 376                     WritePrivateProfileString("Devices", "AudioSource", capture.AudioSource.Name, sConfigFile);
 377                 }
 378                 else
 379                 {
 380                     WritePrivateProfileString("Devices", "AudioSource", "", sConfigFile);
 381                 }
 382 
 383 #if DEBUG
 384                 foreach (PropertyPage p in capture.PropertyPages)
 385                 {
 386                     if (p.SupportsPersisting)
 387                     {
 388                         // Doesn‘t seem to work right
 389                         Debug.WriteLine(p.Name);
 390                     }
 391                 }
 392 #endif
 393             }
 394         }
 395 
 396 
 397         //更新主菜单中的许多有趣的工作,这个示例发生在这里
 398         private void updateMenu()
 399         {
 400             MenuItem m;
 401             Filter f;
 402             Source s;
 403             Source current;//当前
 404             PropertyPage p;
 405             Control oldPreviewWindow = null;
 406 
 407             // 正确的长宽比 Correct aspect ratio
 408             if ((capture != null) && (capture.VideoDevice != null))
 409             {
 410                 //帧大小
 411                 m_FrameSize = capture.FrameSize;
 412                 VideoWindowResize();
 413             }
 414 
 415             // Give our window handle to the NotifyWindow so we‘ll get called about
 416             // events of interest
 417             if (capture != null)
 418             {
 419                 mediaEvent = capture.MediaEventEx;
 420                 int hr = mediaEvent.SetNotifyWindow(this.Handle, WM_GRAPHNOTIFY, IntPtr.Zero);
 421             }
 422 
 423             btnCue.Enabled = capture != null;
 424             btnStart.Enabled = capture != null;
 425 
 426             // Disable preview to avoid additional flashes (optional)
 427             if (capture != null)
 428             {
 429                 oldPreviewWindow = capture.PreviewWindow;
 430                 capture.PreviewWindow = null;
 431             }
 432 
 433             // Load video devices
 434             Filter videoDevice = null;
 435             if (capture != null)
 436                 videoDevice = capture.VideoDevice;
 437             mnuVideoDevices.MenuItems.Clear();
 438             m = new MenuItem("(None)", new EventHandler(mnuVideoDevices_Click));
 439             m.Checked = (videoDevice == null);
 440             mnuVideoDevices.MenuItems.Add(m);
 441             for (int c = 0; c < filters.VideoInputDevices.Count; c++)
 442             {
 443                 f = filters.VideoInputDevices[c];
 444                 m = new MenuItem(f.Name, new EventHandler(mnuVideoDevices_Click));
 445                 m.Checked = (videoDevice == f);
 446                 mnuVideoDevices.MenuItems.Add(m);
 447             }
 448             mnuVideoDevices.Enabled = (filters.VideoInputDevices.Count > 0);
 449 
 450             // Load audio devices
 451             Filter audioDevice = null;
 452             if (capture != null)
 453                 audioDevice = capture.AudioDevice;
 454             mnuAudioDevices.MenuItems.Clear();
 455             m = new MenuItem("(None)", new EventHandler(mnuAudioDevices_Click));
 456             m.Checked = (audioDevice == null);
 457             mnuAudioDevices.MenuItems.Add(m);
 458             for (int c = 0; c < filters.AudioInputDevices.Count; c++)
 459             {
 460                 f = filters.AudioInputDevices[c];
 461                 m = new MenuItem(f.Name, new EventHandler(mnuAudioDevices_Click));
 462                 m.Checked = (audioDevice == f);
 463                 mnuAudioDevices.MenuItems.Add(m);
 464             }
 465             mnuAudioDevices.Enabled = (filters.AudioInputDevices.Count > 0);
 466 
 467 
 468             // Load video compressors
 469             try
 470             {
 471                 mnuVideoCompressors.MenuItems.Clear();
 472                 m = new MenuItem("(None)", new EventHandler(mnuVideoCompressors_Click));
 473                 m.Checked = (capture.VideoCompressor == null);
 474                 mnuVideoCompressors.MenuItems.Add(m);
 475                 for (int c = 0; c < filters.VideoCompressors.Count; c++)
 476                 {
 477                     f = filters.VideoCompressors[c];
 478                     m = new MenuItem(f.Name, new EventHandler(mnuVideoCompressors_Click));
 479                     m.Checked = (capture.VideoCompressor == f);
 480                     mnuVideoCompressors.MenuItems.Add(m);
 481                 }
 482                 mnuVideoCompressors.Enabled = ((capture.VideoDevice != null) && (filters.VideoCompressors.Count > 0));
 483             }
 484             catch { mnuVideoCompressors.Enabled = false; }
 485 
 486             try
 487             {
 488                 // Only enable the video compression menu option if the compressor
 489                 // supports at least one setting 如果选择菜单视频压缩压缩至少一个端口设置。允许
 490                 mnuCompressionProps.Enabled = (capture.VideoCompressorCaps.GetCaps &
 491                     (CompressionCaps.CanBFrame |
 492                     CompressionCaps.CanKeyFrame |
 493                     CompressionCaps.CanQuality |
 494                     CompressionCaps.CanWindow)) > 0;
 495             }
 496             catch
 497             {
 498                 mnuCompressionProps.Enabled = false;
 499             }
 500 
 501             // Load audio 压缩机(compressors)
 502             try
 503             {
 504                 mnuAudioCompressors.MenuItems.Clear();
 505                 m = new MenuItem("(None)", new EventHandler(mnuAudioCompressors_Click));
 506                 m.Checked = (capture.AudioCompressor == null);
 507                 mnuAudioCompressors.MenuItems.Add(m);
 508                 for (int c = 0; c < filters.AudioCompressors.Count; c++)
 509                 {
 510                     f = filters.AudioCompressors[c];
 511                     m = new MenuItem(f.Name, new EventHandler(mnuAudioCompressors_Click));
 512                     m.Checked = (capture.AudioCompressor == f);
 513                     mnuAudioCompressors.MenuItems.Add(m);
 514                 }
 515                 mnuAudioCompressors.Enabled = ((capture.AudioDevice != null) && (filters.AudioCompressors.Count > 0));
 516             }
 517             catch { mnuAudioCompressors.Enabled = false; }
 518 
 519             // Load video sources
 520             try
 521             {
 522                 mnuVideoSources.MenuItems.Clear();
 523                 current = capture.VideoSource;
 524                 for (int c = 0; c < capture.VideoSources.Count; c++)
 525                 {
 526                     s = capture.VideoSources[c];
 527                     m = new MenuItem(s.Name, new EventHandler(mnuVideoSources_Click));
 528                     m.Checked = (current == s);
 529                     mnuVideoSources.MenuItems.Add(m);
 530                 }
 531                 mnuVideoSources.Enabled = (capture.VideoSources.Count > 0);
 532             }
 533             catch { mnuVideoSources.Enabled = false; }
 534 
 535             // Load audio sources
 536             try
 537             {
 538                 mnuAudioSources.MenuItems.Clear();
 539                 current = capture.AudioSource;
 540                 for (int c = 0; c < capture.AudioSources.Count; c++)
 541                 {
 542                     s = capture.AudioSources[c];
 543                     m = new MenuItem(s.Name, new EventHandler(mnuAudioSources_Click));
 544                     m.Checked = (current == s);
 545                     mnuAudioSources.MenuItems.Add(m);
 546                 }
 547                 mnuAudioSources.Enabled = (capture.AudioSources.Count > 0);
 548             }
 549             catch { mnuAudioSources.Enabled = false; }
 550 
 551             // Load frame rates
 552             try
 553             {
 554                 mnuFrameRates.MenuItems.Clear();
 555                 int frameRate = (int)(capture.FrameRate * 1000);
 556                 m = new MenuItem("15 fps", new EventHandler(mnuFrameRates_Click));
 557                 m.Checked = (frameRate == 15000);
 558                 mnuFrameRates.MenuItems.Add(m);
 559                 m = new MenuItem("24 fps (Film)", new EventHandler(mnuFrameRates_Click));
 560                 m.Checked = (frameRate == 24000);
 561                 mnuFrameRates.MenuItems.Add(m);
 562                 m = new MenuItem("25 fps (PAL)", new EventHandler(mnuFrameRates_Click));
 563                 m.Checked = (frameRate == 25000);
 564                 mnuFrameRates.MenuItems.Add(m);
 565                 m = new MenuItem("29.997 fps (NTSC)", new EventHandler(mnuFrameRates_Click));
 566                 m.Checked = (frameRate == 29997) || (frameRate == 29970);
 567                 mnuFrameRates.MenuItems.Add(m);
 568                 m = new MenuItem("30 fps (~NTSC)", new EventHandler(mnuFrameRates_Click));
 569                 m.Checked = (frameRate == 30000);
 570                 mnuFrameRates.MenuItems.Add(m);
 571                 m = new MenuItem("59.994 fps (2xNTSC)", new EventHandler(mnuFrameRates_Click));
 572                 m.Checked = (frameRate == 59994);
 573                 mnuFrameRates.MenuItems.Add(m);
 574                 mnuFrameRates.Enabled = true;
 575             }
 576             catch { mnuFrameRates.Enabled = false; }
 577 
 578             // Load frame sizes
 579             try
 580             {
 581                 mnuFrameSizes.MenuItems.Clear();
 582                 Size frameSize = capture.FrameSize;
 583                 m = new MenuItem("160 x 120", new EventHandler(mnuFrameSizes_Click));
 584                 m.Checked = (frameSize == new Size(160, 120));
 585                 mnuFrameSizes.MenuItems.Add(m);
 586                 m = new MenuItem("320 x 240", new EventHandler(mnuFrameSizes_Click));
 587                 m.Checked = (frameSize == new Size(320, 240));
 588                 mnuFrameSizes.MenuItems.Add(m);
 589                 m = new MenuItem("640 x 480", new EventHandler(mnuFrameSizes_Click));
 590                 m.Checked = (frameSize == new Size(640, 480));
 591                 mnuFrameSizes.MenuItems.Add(m);
 592                 m = new MenuItem("1024 x 768", new EventHandler(mnuFrameSizes_Click));
 593                 m.Checked = (frameSize == new Size(1024, 768));
 594                 mnuFrameSizes.MenuItems.Add(m);
 595                 mnuFrameSizes.Enabled = true;
 596             }
 597             catch { mnuFrameSizes.Enabled = false; }
 598 
 599             // Load audio channels
 600             try
 601             {
 602                 mnuAudioChannels.MenuItems.Clear();
 603                 short audioChannels = capture.AudioChannels;
 604                 m = new MenuItem("单声道 Mono", new EventHandler(mnuAudioChannels_Click));
 605                 m.Checked = (audioChannels == 1);
 606                 mnuAudioChannels.MenuItems.Add(m);
 607                 m = new MenuItem("立体声 Stereo", new EventHandler(mnuAudioChannels_Click));
 608                 m.Checked = (audioChannels == 2);
 609                 mnuAudioChannels.MenuItems.Add(m);
 610                 mnuAudioChannels.Enabled = true;
 611             }
 612             catch { mnuAudioChannels.Enabled = false; }
 613 
 614             // Load音频采样率 Load audio sampling rate
 615             try
 616             {
 617                 mnuAudioSamplingRate.MenuItems.Clear();
 618                 int samplingRate = capture.AudioSamplingRate;
 619                 m = new MenuItem("8 kHz", new EventHandler(mnuAudioSamplingRate_Click));
 620                 m.Checked = (samplingRate == 8000);
 621                 mnuAudioSamplingRate.MenuItems.Add(m);
 622                 m = new MenuItem("11.025 kHz", new EventHandler(mnuAudioSamplingRate_Click));
 623                 m.Checked = (capture.AudioSamplingRate == 11025);
 624                 mnuAudioSamplingRate.MenuItems.Add(m);
 625                 m = new MenuItem("22.05 kHz", new EventHandler(mnuAudioSamplingRate_Click));
 626                 m.Checked = (capture.AudioSamplingRate == 22050);
 627                 mnuAudioSamplingRate.MenuItems.Add(m);
 628                 m = new MenuItem("44.1 kHz", new EventHandler(mnuAudioSamplingRate_Click));
 629                 m.Checked = (capture.AudioSamplingRate == 44100);
 630                 mnuAudioSamplingRate.MenuItems.Add(m);
 631                 mnuAudioSamplingRate.Enabled = true;
 632             }
 633             catch { mnuAudioSamplingRate.Enabled = false; }
 634 
 635             // 加载音频样本大小 Load audio sample sizes
 636             try
 637             {
 638                 mnuAudioSampleSizes.MenuItems.Clear();
 639                 short sampleSize = capture.AudioSampleSize;
 640                 m = new MenuItem("8 bit", new EventHandler(mnuAudioSampleSizes_Click));
 641                 m.Checked = (sampleSize == 8);
 642                 mnuAudioSampleSizes.MenuItems.Add(m);
 643                 m = new MenuItem("16 bit", new EventHandler(mnuAudioSampleSizes_Click));
 644                 m.Checked = (sampleSize == 16);
 645                 mnuAudioSampleSizes.MenuItems.Add(m);
 646                 mnuAudioSampleSizes.Enabled = true;
 647             }
 648             catch { mnuAudioSampleSizes.Enabled = false; }
 649 
 650             // 加载属性页 Load property pages
 651             try
 652             {
 653                 mnuPropertyPages.MenuItems.Clear();
 654                 for (int c = 0; c < capture.PropertyPages.Count; c++)
 655                 {
 656                     p = capture.PropertyPages[c];
 657                     m = new MenuItem(p.Name + "...", new EventHandler(mnuPropertyPages_Click));
 658                     mnuPropertyPages.MenuItems.Add(m);
 659                 }
 660                 mnuPropertyPages.Enabled = (capture.PropertyPages.Count > 0);
 661             }
 662             catch { mnuPropertyPages.Enabled = false; }
 663 
 664             // Load TV Tuner channels
 665             try
 666             {
 667                 mnuChannel.MenuItems.Clear();
 668                 int channel = capture.Tuner.Channel;
 669                 for (int c = 1; c <= 31; c++)
 670                 {
 671                     m = new MenuItem(c.ToString(), new EventHandler(mnuChannel_Click));
 672                     m.Checked = (channel == c);
 673                     mnuChannel.MenuItems.Add(m);
 674                 }
 675                 mnuChannel.Enabled = true;
 676             }
 677             catch { mnuChannel.Enabled = false; }
 678 
 679             // Load TV Tuner input types
 680             try
 681             {
 682                 mnuInputType.MenuItems.Clear();
 683                 m = new MenuItem(DirectX.Capture.TunerInputType.Cable.ToString(), new EventHandler(mnuInputType_Click));
 684                 m.Checked = (capture.Tuner.InputType == DirectX.Capture.TunerInputType.Cable);
 685                 mnuInputType.MenuItems.Add(m);
 686                 m = new MenuItem(DirectX.Capture.TunerInputType.Antenna.ToString(), new EventHandler(mnuInputType_Click));
 687                 m.Checked = (capture.Tuner.InputType == DirectX.Capture.TunerInputType.Antenna);
 688                 mnuInputType.MenuItems.Add(m);
 689                 mnuInputType.Enabled = true;
 690             }
 691             catch { mnuInputType.Enabled = false; }
 692 
 693             // Enable/disable caps
 694             mnuVideoCaps.Enabled = ((capture != null) && (capture.VideoCaps != null));
 695             mnuAudioCaps.Enabled = ((capture != null) && (capture.AudioCaps != null));
 696 
 697             // Check Preview menu option
 698             mnuPreview.Checked = (oldPreviewWindow != null);
 699             mnuPreview.Enabled = (capture != null);
 700 
 701             // Reenable preview if it was enabled before
 702             if (capture != null)
 703                 capture.PreviewWindow = oldPreviewWindow;
 704         }
 705         #endregion 加载
 706 
 707         #region 方法
 708 
 709         private void Stop()
 710         {
 711             try
 712             {
 713                 ShowDropped();
 714                 capture.Stop();
 715                 btnCue.Enabled = true;
 716                 btnStart.Enabled = true;
 717                 btnStop.Enabled = false;
 718                 txtFilename.Enabled = true;
 719                 btnStart.Select();
 720             }
 721             catch (Exception ex)
 722             {
 723                 MessageBox.Show(ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
 724             }
 725         }
 726 
 727         private void VideoWindowResize()
 728         {
 729             if ((capture != null) && (m_FrameSize.Width > 0))
 730             {
 731                 Size ns;
 732 
 733                 int iMaxHeight = Math.Min(m_FrameSize.Height, groupBox1.Height - 9); //不要践踏我们的分组框的边界 Don‘t trample the borders
 734                 int iMaxWidth = Math.Min(m_FrameSize.Width, groupBox1.Width - 4);   // of our GroupBox
 735 
 736                 int t2 = (iMaxWidth * m_FrameSize.Height) / m_FrameSize.Width;
 737 
 738                 // Which proportion do we need to limit?
 739                 if (t2 > iMaxHeight)
 740                 {
 741                     int t1 = (iMaxHeight * m_FrameSize.Width) / m_FrameSize.Height;
 742                     ns = new Size(t1, iMaxHeight);
 743                 }
 744                 else
 745                 {
 746                     ns = new Size(iMaxWidth, t2);
 747                 }
 748                 panelVideo.Size = ns;
 749             }
 750         }
 751 
 752         // 更新 捕获/下降/时间字段的查询捕获装置 
 753         //Update the Capture/Dropped/Duration fields by quering the capture device
 754         private void ShowDropped()
 755         {
 756             TimeSpan duDuration;
 757             long iCurDropped = capture.DroppedVideoFrames;
 758             long iCaptured = capture.CapturedVideoFrames;
 759 
 760             if (iCurDropped >= 0)
 761                 txtDroppedFrames.Text = (iCurDropped - iDroppedBefore).ToString();
 762 
 763             if (iCaptured > 0)
 764                 txtCapturedFrames.Text = iCaptured.ToString();
 765 
 766             duDuration = DateTime.Now - dtBefore;
 767             txtDuration.Text = duDuration.ToString();
 768         }
 769 
 770         #endregion 方法
 771 
 772         #region 菜单事件
 773 
 774 
 775         private void mnuVideoDevices_Click(object sender, System.EventArgs e)
 776         {
 777             try
 778             {
 779                 // 由于视频和音频设备只能通过创建一个新的捕获对象来改变,因此获取当前的设备和处理捕获对象。
 780                 // Get current devices and dispose of capture object
 781                 // because the video and audio device can only be changed
 782                 // by creating a new Capture object.
 783                 Filter videoDevice = null;
 784                 Filter audioDevice = null;
 785                 if (capture != null)
 786                 {
 787                     videoDevice = capture.VideoDevice;
 788                     audioDevice = capture.AudioDevice;
 789                     capture.Dispose();
 790                     capture = null;
 791                 }
 792 
 793                 // Get new video device
 794                 MenuItem m = sender as MenuItem;
 795                 videoDevice = (m.Index > 0 ? filters.VideoInputDevices[m.Index - 1] : null);
 796 
 797                 // Create capture object
 798                 if ((videoDevice != null) || (audioDevice != null))
 799                 {
 800                     capture = new 捕获(videoDevice, audioDevice);
 801                     capture.CaptureComplete += new EventHandler(OnCaptureComplete);
 802                 }
 803 
 804                 // Update the menu
 805                 updateMenu();
 806             }
 807             catch (Exception ex)
 808             {
 809                 MessageBox.Show("视频设备不支持.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
 810             }
 811         }
 812 
 813         private void mnuAudioDevices_Click(object sender, System.EventArgs e)
 814         {
 815             try
 816             {
 817                 // Get current devices and dispose of capture object
 818                 // because the video and audio device can only be changed
 819                 // by creating a new Capture object.
 820                 Filter videoDevice = null;
 821                 Filter audioDevice = null;
 822                 Filter videoCompressor = null;
 823                 if (capture != null)
 824                 {
 825                     videoDevice = capture.VideoDevice;
 826                     audioDevice = capture.AudioDevice;
 827                     videoCompressor = capture.VideoCompressor;
 828                     capture.Dispose();
 829                     capture = null;
 830                 }
 831 
 832                 // Get new audio device
 833                 MenuItem m = sender as MenuItem;
 834                 audioDevice = (m.Index > 0 ? filters.AudioInputDevices[m.Index - 1] : null);
 835 
 836                 // Create capture object
 837                 if ((videoDevice != null) || (audioDevice != null))
 838                 {
 839                     capture = new 捕获(videoDevice, audioDevice);
 840                     capture.CaptureComplete += new EventHandler(OnCaptureComplete);
 841                 }
 842 
 843                 capture.VideoCompressor = videoCompressor;
 844 
 845                 // Update the menu
 846                 updateMenu();
 847             }
 848             catch (Exception ex)
 849             {
 850                 MessageBox.Show("音频设备不支持.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
 851             }
 852         }
 853 
 854         private void mnuVideoCompressors_Click(object sender, System.EventArgs e)
 855         {
 856             try
 857             {
 858                 // Change the video compressor
 859                 // We subtract 1 from m.Index beacuse the first item is (None)
 860                 MenuItem m = sender as MenuItem;
 861                 capture.VideoCompressor = (m.Index > 0 ? filters.VideoCompressors[m.Index - 1] : null);
 862                 updateMenu();
 863             }
 864             catch (Exception ex)
 865             {
 866                 MessageBox.Show("视频压缩不支持.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
 867             }
 868 
 869         }
 870 
 871         private void mnuAudioCompressors_Click(object sender, System.EventArgs e)
 872         {
 873             try
 874             {
 875                 // Change the audio compressor
 876                 // We subtract 1 from m.Index beacuse the first item is (None)
 877                 MenuItem m = sender as MenuItem;
 878                 capture.AudioCompressor = (m.Index > 0 ? filters.AudioCompressors[m.Index - 1] : null);
 879                 updateMenu();
 880             }
 881             catch (Exception ex)
 882             {
 883                 MessageBox.Show("音频压缩不支持.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
 884             }
 885         }
 886 
 887         private void mnuVideoSources_Click(object sender, System.EventArgs e)
 888         {
 889             try
 890             {
 891                 // Choose the video source
 892                 // If the device only has one source, this menu item will be disabled
 893                 MenuItem m = sender as MenuItem;
 894                 capture.VideoSource = capture.VideoSources[m.Index];
 895                 updateMenu();
 896             }
 897             catch (Exception ex)
 898             {
 899                 MessageBox.Show("无法设置视频源。请提交错误报告.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
 900             }
 901         }
 902 
 903         private void mnuAudioSources_Click(object sender, System.EventArgs e)
 904         {
 905             try
 906             {
 907                 // Choose the audio source
 908                 // If the device only has one source, this menu item will be disabled
 909                 MenuItem m = sender as MenuItem;
 910                 capture.AudioSource = capture.AudioSources[m.Index];
 911                 updateMenu();
 912             }
 913             catch (Exception ex)
 914             {
 915                 MessageBox.Show("无法设置音频源。请提交错误报告.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
 916             }
 917         }
 918 
 919 
 920         private void mnuExit_Click(object sender, System.EventArgs e)
 921         {
 922             if (capture != null)
 923                 capture.Stop();
 924             Application.Exit();
 925         }
 926 
 927         private void mnuFrameSizes_Click(object sender, System.EventArgs e)
 928         {
 929             try
 930             {
 931                 // Disable preview to avoid additional flashes (optional)
 932                 bool preview = (capture.PreviewWindow != null);
 933                 capture.PreviewWindow = null;
 934 
 935                 // Update the frame size
 936                 MenuItem m = sender as MenuItem;
 937                 string[] s = m.Text.Split(x);
 938                 Size size = new Size(int.Parse(s[0]), int.Parse(s[1]));
 939                 capture.FrameSize = size;
 940 
 941                 // Update the menu
 942                 updateMenu();
 943 
 944                 // Restore previous preview setting
 945                 capture.PreviewWindow = (preview ? panelVideo : null);
 946             }
 947             catch (Exception ex)
 948             {
 949                 MessageBox.Show("帧大小不支持.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
 950             }
 951         }
 952 
 953         private void mnuFrameRates_Click(object sender, System.EventArgs e)
 954         {
 955             try
 956             {
 957                 MenuItem m = sender as MenuItem;
 958                 string[] s = m.Text.Split( );
 959                 capture.FrameRate = double.Parse(s[0]);
 960                 updateMenu();
 961             }
 962             catch (Exception ex)
 963             {
 964                 MessageBox.Show("不支持的帧速率.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
 965             }
 966         }
 967 
 968         private void mnuAudioChannels_Click(object sender, System.EventArgs e)
 969         {
 970             try
 971             {
 972                 MenuItem m = sender as MenuItem;
 973                 capture.AudioChannels = (short)Math.Pow(2, m.Index);
 974                 updateMenu();
 975             }
 976             catch (Exception ex)
 977             {
 978                 MessageBox.Show("不支持的音频信道数.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
 979             }
 980         }
 981 
 982         private void mnuAudioSamplingRate_Click(object sender, System.EventArgs e)
 983         {
 984             try
 985             {
 986                 MenuItem m = sender as MenuItem;
 987                 string[] s = m.Text.Split( );
 988                 int samplingRate = (int)(double.Parse(s[0]) * 1000);
 989                 capture.AudioSamplingRate = samplingRate;
 990                 updateMenu();
 991             }
 992             catch (Exception ex)
 993             {
 994                 MessageBox.Show("不支持音频采样率.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
 995             }
 996         }
 997 
 998         private void mnuAudioSampleSizes_Click(object sender, System.EventArgs e)
 999         {
1000             try
1001             {
1002                 MenuItem m = sender as MenuItem;
1003                 string[] s = m.Text.Split( );
1004                 short sampleSize = short.Parse(s[0]);
1005                 capture.AudioSampleSize = sampleSize;
1006                 updateMenu();
1007             }
1008             catch (Exception ex)
1009             {
1010                 MessageBox.Show("音频样本大小不支持.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
1011             }
1012         }
1013 
1014         private void mnuPreview_Click(object sender, System.EventArgs e)
1015         {
1016             try
1017             {
1018                 if (capture.PreviewWindow == null)
1019                 {
1020                     capture.PreviewWindow = panelVideo;
1021                     mnuPreview.Checked = true;
1022                 }
1023                 else
1024                 {
1025                     capture.PreviewWindow = null;
1026                     mnuPreview.Checked = false;
1027                 }
1028             }
1029             catch (Exception ex)
1030             {
1031                 MessageBox.Show("无法启用/禁用预览。请提交一个错误报告。\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
1032             }
1033         }
1034 
1035         private void mnuPropertyPages_Click(object sender, System.EventArgs e)
1036         {
1037             try
1038             {
1039                 MenuItem m = sender as MenuItem;
1040                 capture.PropertyPages[m.Index].Show(this);
1041                 updateMenu();
1042             }
1043             catch (Exception ex)
1044             {
1045                 MessageBox.Show("无法显示属性页。请提交一个错误报告.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
1046             }
1047         }
1048 
1049         private void mnuChannel_Click(object sender, System.EventArgs e)
1050         {
1051             try
1052             {
1053                 MenuItem m = sender as MenuItem;
1054                 capture.Tuner.Channel = m.Index + 1;
1055                 updateMenu();
1056             }
1057             catch (Exception ex)
1058             {
1059                 MessageBox.Show("无法更改通道。请提交一个错误报告.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
1060             }
1061         }
1062 
1063         private void mnuInputType_Click(object sender, System.EventArgs e)
1064         {
1065             try
1066             {
1067                 MenuItem m = sender as MenuItem;
1068                 capture.Tuner.InputType = (DirectX.Capture.TunerInputType)m.Index;
1069                 updateMenu();
1070             }
1071             catch (Exception ex)
1072             {
1073                 MessageBox.Show("无法更改调谐器输入类型。请提交一个错误报告.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
1074             }
1075         }
1076 
1077         private void mnuVideoCaps_Click(object sender, System.EventArgs e)
1078         {
1079             try
1080             {
1081                 string s;
1082                 s = String.Format(
1083                     "输入尺寸:\t\t{0} x {1}\n" +
1084                     "\n" +
1085                     "最小帧长度:\t\t{2} x {3}\n" +//最小帧长度
1086                     "最大帧长度:\t\t{4} x {5}\n" +//最大帧长度
1087                     "帧尺寸粒度 X:\t{6}\n" +//帧大小粒度
1088                     "帧尺寸粒度 Y:\t{7}\n" +
1089                     "\n" +
1090                     "最小帧速率:\t\t{8:0.000} fps\n" +//最小帧速率
1091                     "最大帧速率:\t\t{9:0.000} fps\n",
1092                     capture.VideoCaps.InputSize.Width, capture.VideoCaps.InputSize.Height,
1093                     capture.VideoCaps.MinFrameSize.Width, capture.VideoCaps.MinFrameSize.Height,
1094                     capture.VideoCaps.MaxFrameSize.Width, capture.VideoCaps.MaxFrameSize.Height,
1095                     capture.VideoCaps.FrameSizeGranularityX,
1096                     capture.VideoCaps.FrameSizeGranularityY,
1097                     capture.VideoCaps.MinFrameRate,
1098                     capture.VideoCaps.MaxFrameRate);
1099                 MessageBox.Show(s, "视频设备能力", MessageBoxButtons.OK, MessageBoxIcon.Information);
1100 
1101             }
1102             catch (Exception ex)
1103             {
1104                 MessageBox.Show("无法显示视频功能。请提交一个错误报告.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
1105             }
1106         }
1107 
1108         private void mnuAudioCaps_Click(object sender, System.EventArgs e)
1109         {
1110             try
1111             {
1112                 string s;
1113                 s = String.Format(
1114                     "Min Channels:\t\t{0}\n" +
1115                     "Max Channels:\t\t{1}\n" +
1116                     "Channels Granularity:\t{2}\n" +
1117                     "\n" +
1118                     "Min Sample Size:\t\t{3}\n" +
1119                     "Max Sample Size:\t\t{4}\n" +
1120                     "Sample Size Granularity:\t{5}\n" +
1121                     "\n" +
1122                     "Min Sampling Rate:\t\t{6}\n" +
1123                     "Max Sampling Rate:\t\t{7}\n" +
1124                     "Sampling Rate Granularity:\t{8}\n",
1125                     capture.AudioCaps.MinimumChannels,
1126                     capture.AudioCaps.MaximumChannels,
1127                     capture.AudioCaps.ChannelsGranularity,
1128                     capture.AudioCaps.MinimumSampleSize,
1129                     capture.AudioCaps.MaximumSampleSize,
1130                     capture.AudioCaps.SampleSizeGranularity,
1131                     capture.AudioCaps.MinimumSamplingRate,
1132                     capture.AudioCaps.MaximumSamplingRate,
1133                     capture.AudioCaps.SamplingRateGranularity);
1134                 MessageBox.Show(s, "音频设备能力", MessageBoxButtons.OK, MessageBoxIcon.Information);
1135 
1136             }
1137             catch (Exception ex)
1138             {
1139                 MessageBox.Show("Unable display audio capabilities. Please submit a bug report.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
1140             }
1141         }
1142 
1143         // 单击“菜单”选项显示压缩机属性 On clicking the menu option to display Compressor Properties
1144         private void mnuCompressionProps_Click(object sender, System.EventArgs e)
1145         {
1146             // Prepare to show the form
1147             CompressionProps m = new CompressionProps();
1148 
1149             // Read what compression capabilities are available
1150             CompressionCaps i = capture.VideoCompressorCaps.GetCaps;
1151 
1152             bool bSet = (i & CompressionCaps.CanKeyFrame) > 0;
1153 
1154             // Enable the available keyframe controls
1155             m.txtKeyFrame.Enabled = bSet;
1156             m.labKeyFrame.Enabled = bSet;
1157             m.chkKeyFrame.Enabled = bSet;
1158 
1159             // copy in the default values
1160             if (bSet)
1161             {
1162                 long v = capture.VideoCompressorCaps.KeyFrameRate;
1163 
1164                 // Using default?
1165                 if (v < 0)
1166                 {
1167                     m.txtKeyFrame.Text = "";
1168                     m.chkKeyFrame.Checked = true;
1169                     m.txtKeyFrame.Enabled = false;
1170                 }
1171                 else
1172                 {
1173                     m.txtKeyFrame.Text = v.ToString();
1174                     m.chkKeyFrame.Checked = false;
1175                 }
1176             }
1177 
1178             bSet = (i & CompressionCaps.CanBFrame) > 0;
1179 
1180             // Enable the available PFrames controls
1181             m.txtPFrames.Enabled = bSet;
1182             m.labPFrames.Enabled = bSet;
1183             m.chkPFrames.Enabled = bSet;
1184             if (bSet)
1185             {
1186                 long v = capture.VideoCompressorCaps.PFramesPerKeyFrame;
1187 
1188                 // Using default?
1189                 if (v < 0)
1190                 {
1191                     m.txtPFrames.Text = "";
1192                     m.chkPFrames.Checked = true;
1193                     m.txtPFrames.Enabled = false;
1194                 }
1195                 else
1196                 {
1197                     m.txtPFrames.Text = v.ToString();
1198                     m.chkPFrames.Checked = false;
1199                 }
1200             }
1201 
1202             bSet = (i & CompressionCaps.CanWindow) > 0;
1203 
1204             // Enable the available WindowSize controls
1205             m.txtWindowSize.Enabled = bSet;
1206             m.labWindowSize.Enabled = bSet;
1207             m.chkWindowSize.Enabled = bSet;
1208             m.chkWindowSize.Checked = false;
1209 
1210             if (bSet)
1211             {
1212                 m.txtWindowSize.Text = capture.VideoCompressorCaps.WindowSize.ToString();
1213             }
1214 
1215             bSet = (i & CompressionCaps.CanQuality) > 0;
1216 
1217             // Enable the available Quality controls
1218             m.txtQuality.Enabled = bSet;
1219             m.trkQuality.Enabled = bSet;
1220             m.labQuality.Enabled = bSet;
1221             m.chkQuality.Enabled = bSet;
1222             if (bSet)
1223             {
1224                 long v = capture.VideoCompressorCaps.Quality;
1225 
1226                 // Using default?
1227                 if (v < 0)
1228                 {
1229                     m.txtQuality.Text = "";
1230                     m.chkQuality.Checked = true;
1231                     m.trkQuality.Value = 0;
1232                     m.trkQuality.Enabled = false;
1233                     m.txtQuality.Enabled = false;
1234                 }
1235                 else
1236                 {
1237                     m.txtQuality.Text = v.ToString();
1238                     m.chkQuality.Checked = false;
1239                     m.trkQuality.Value = capture.VideoCompressorCaps.Quality;
1240                 }
1241             }
1242 
1243             // Display the form
1244             DialogResult a = m.ShowDialog(this);
1245 
1246             // If the user clicked OK, set the values they specified
1247             if (DialogResult.OK == a)
1248             {
1249                 if ((i & CompressionCaps.CanKeyFrame) > 0)
1250                 {
1251                     int v;
1252                     if (m.chkKeyFrame.Checked)
1253                     {
1254                         // Use default
1255                         v = -1;
1256                     }
1257                     else
1258                     {
1259                         v = Convert.ToInt32(m.txtKeyFrame.Text);
1260                     }
1261                     capture.VideoCompressorCaps.KeyFrameRate = v;
1262                 }
1263 
1264                 if ((i & CompressionCaps.CanBFrame) > 0)
1265                 {
1266                     int v;
1267                     if (m.chkPFrames.Checked)
1268                     {
1269                         // Use default
1270                         v = -1;
1271                     }
1272                     else
1273                     {
1274                         v = Convert.ToInt32(m.txtPFrames.Text);
1275                     }
1276                     capture.VideoCompressorCaps.PFramesPerKeyFrame = v;
1277                 }
1278 
1279                 if ((i & CompressionCaps.CanWindow) > 0)
1280                 {
1281                     long v;
1282                     if (m.chkWindowSize.Checked)
1283                     {
1284                         // Use default
1285                         v = 1;
1286                     }
1287                     else
1288                     {
1289                         v = Convert.ToInt64(m.txtWindowSize.Text);
1290                     }
1291                     capture.VideoCompressorCaps.WindowSize = v;
1292                 }
1293 
1294                 if ((i & CompressionCaps.CanQuality) > 0)
1295                 {
1296                     int v;
1297 
1298                     if (m.chkQuality.Checked)
1299                     {
1300                         // Use default
1301                         v = -1;
1302                     }
1303                     else
1304                     {
1305                         v = Convert.ToInt32(m.txtQuality.Text);
1306                     }
1307                     capture.VideoCompressorCaps.Quality = v;
1308                 }
1309             }
1310         }
1311 
1312         #endregion 菜单事件
1313 
1314         #region 事件
1315 
1316 
1317         private void btnExit_Click(object sender, System.EventArgs e)
1318         {
1319             if (capture != null)
1320             {
1321                 capture.Stop();
1322                 SaveDefaults();
1323             }
1324             Application.Exit();
1325         }
1326 
1327         private void btnCue_Click(object sender, System.EventArgs e)
1328         {
1329             try
1330             {
1331                 if (capture == null)
1332                     throw new ApplicationException("请选择一个视频和/或音频设备.");
1333                 if (!capture.Cued)
1334                     capture.Filename = txtFilename.Text;
1335 
1336                 CaptureResult = 0;
1337                 txtDroppedFrames.Text = "0";
1338                 txtCapturedFrames.Text = "0";
1339                 txtDuration.Text = "";
1340                 txtFilename.Enabled = false;
1341 
1342                 capture.Cue();
1343                 capture.PreSize(Convert.ToInt64(txtPreSize.Text) * 1024000);
1344 
1345                 btnCue.Enabled = false;
1346                 btnStop.Enabled = true;
1347                 //“使用cue() 先于 start() 做的所有准备工作,
1348                 //需要做的事开始捕捉。现在,当您单击“开始”时,
1349                 //捕获的速度将比您刚刚单击“启动”开始的速度更快。
1350                 //使用cue()完全是可选的。使用cue()坏处是预览被禁用,直到捕获开始。
1351                 MessageBox.Show("Use Cue() before Start() to " +
1352                     "do all the preparation work that needs to be done to start a " +
1353                     "capture. Now, when you click Start the capture will begin faster " +
1354                     "than if you had just clicked Start. Using Cue() is completely " +
1355                     "optional. The downside to using Cue() is the preview is disabled until " +
1356                     "the capture begins.", "Ready to Capture", MessageBoxButtons.OK, MessageBoxIcon.Information);
1357                 btnStart.Select();
1358             }
1359             catch (Exception ex)
1360             {
1361                 MessageBox.Show(ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
1362             }
1363         }
1364 
1365         private void btnStart_Click(object sender, System.EventArgs e)
1366         {
1367             try
1368             {
1369                 if (capture == null)
1370                     throw new ApplicationException("请选择一个视频和/或音频设备。");
1371                 if (!capture.Cued)
1372                     capture.Filename = txtFilename.Text;
1373 
1374                 CaptureResult = 0;
1375                 iDroppedBefore = capture.DroppedVideoFrames;
1376                 dtBefore = DateTime.Now;
1377                 txtDroppedFrames.Text = "0";
1378                 txtCapturedFrames.Text = "0";
1379                 txtDuration.Text = "";
1380                 txtFilename.Enabled = false;
1381                 capture.Start();
1382                 tmrTime1.Enabled = true;
1383                 btnCue.Enabled = false;
1384                 btnStart.Enabled = false;
1385                 btnStop.Enabled = true;
1386                 btnStop.Select();
1387             }
1388             catch (Exception ex)
1389             {
1390                 MessageBox.Show(ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
1391             }
1392         }
1393 
1394         private void btnStop_Click(object sender, System.EventArgs e)
1395         {
1396             Stop();
1397         }
1398 
1399 
1400         private void OnCaptureComplete(object sender, EventArgs e)
1401         {
1402             // 显示捕获捕获完成事件 Demonstrate the Capture.CaptureComplete event.
1403             tmrTime1.Enabled = false;
1404 
1405             // 如果窗口消息处理程序中止了我们… If the windows message handler aborted us...
1406             if (CaptureResult != 0)//捕获的结果
1407                 MessageBox.Show("Capture Error 0x" + CaptureResult.ToString("x"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
1408         }
1409 
1410         // Update the Captured/Dropped fields while capturing
1411         private void tmrTime1_Tick(Object myObject, EventArgs myEventArgs)
1412         {
1413             if (CaptureResult == 0)
1414             {
1415                 ShowDropped();
1416             }
1417             else
1418             {
1419                 Stop();
1420             }
1421         }
1422 
1423 
1424         private void groupBox1_Resize(object sender, System.EventArgs e)
1425         {
1426             VideoWindowResize();
1427         }
1428 
1429         #endregion 事件
1430         // http://www.cnblogs.com/endv/p/6052511.html
1431 
1432         #region private
1433         private System.Windows.Forms.TextBox txtFilename;
1434         private System.Windows.Forms.Label label1;
1435         private System.Windows.Forms.Button btnStart;
1436         private System.Windows.Forms.Button btnStop;
1437         private System.Windows.Forms.Button btnExit;
1438         private System.Windows.Forms.MenuItem menuItem1;
1439         private System.Windows.Forms.MenuItem menuItem7;
1440         private System.Windows.Forms.MainMenu mainMenu;
1441         private System.Windows.Forms.MenuItem mnuExit;
1442         private System.Windows.Forms.MenuItem mnuDevices;
1443         private System.Windows.Forms.MenuItem mnuVideoDevices;
1444         private System.Windows.Forms.MenuItem mnuAudioDevices;
1445         private System.Windows.Forms.MenuItem mnuVideoCompressors;
1446         private System.Windows.Forms.MenuItem mnuAudioCompressors;
1447         private System.Windows.Forms.MenuItem mnuVideoSources;
1448         private System.Windows.Forms.MenuItem mnuAudioSources;
1449         private System.Windows.Forms.Panel panelVideo;
1450         private System.Windows.Forms.MenuItem menuItem4;
1451         private System.Windows.Forms.MenuItem mnuAudioChannels;
1452         private System.Windows.Forms.MenuItem mnuAudioSamplingRate;
1453         private System.Windows.Forms.MenuItem mnuAudioSampleSizes;
1454         private System.Windows.Forms.MenuItem menuItem5;
1455         private System.Windows.Forms.MenuItem mnuFrameSizes;
1456         private System.Windows.Forms.MenuItem mnuFrameRates;
1457         private System.Windows.Forms.Button btnCue;
1458         private System.Windows.Forms.MenuItem menuItem6;
1459         private System.Windows.Forms.MenuItem mnuPreview;
1460         private System.Windows.Forms.MenuItem menuItem8;
1461         private System.Windows.Forms.MenuItem mnuPropertyPages;
1462         private System.Windows.Forms.MenuItem mnuVideoCaps;
1463         private System.Windows.Forms.MenuItem mnuAudioCaps;
1464         private System.Windows.Forms.MenuItem mnuChannel;
1465         private System.Windows.Forms.MenuItem menuItem3;
1466         private System.Windows.Forms.MenuItem mnuInputType;
1467         private System.Windows.Forms.TextBox txtDroppedFrames;
1468         private System.Windows.Forms.Label label2;
1469         private System.Windows.Forms.Timer tmrTime1;
1470         private System.Windows.Forms.Label label3;
1471         private System.Windows.Forms.TextBox txtDuration;
1472         private System.Windows.Forms.Label label4;
1473         private System.Windows.Forms.TextBox txtCapturedFrames;
1474         private System.Windows.Forms.MenuItem mnuCompressionProps;
1475         private System.Windows.Forms.GroupBox groupBox1;
1476         private System.Windows.Forms.Label label5;
1477         private System.Windows.Forms.TextBox txtPreSize;
1478         private System.ComponentModel.IContainer components;
1479         #endregion private
1480 
1481         /// <summary>
1482         /// Clean up any resources being used.
1483         /// </summary>
1484         protected override void Dispose(bool disposing)
1485         {
1486             if (disposing)
1487             {
1488                 if (components != null)
1489                 {
1490                     components.Dispose();
1491                 }
1492             }
1493             base.Dispose(disposing);
1494         }
1495         // 媒体事件发送使用Windows消息 Media events are sent to use as windows messages
1496         protected override void WndProc(ref Message m)
1497         {
1498             switch (m.Msg)
1499             {
1500                 // If this is a windows media message
1501                 case WM_GRAPHNOTIFY:
1502                     EventCode eventCode;//捕获已中止?
1503                     IntPtr p1, p2;
1504                     int hr;
1505 
1506                     hr = mediaEvent.GetEvent(out eventCode, out p1, out p2, 0);
1507                     while (hr == 0)
1508                     {
1509                         // 处理事件 
1510                         // 捕获已中止 The capture has been aborted
1511                         if (eventCode == EventCode.ErrorAbort)
1512                         {
1513                             CaptureResult = p1.ToInt32();
1514                         }
1515 
1516                         // 释放参数  
1517                         mediaEvent.FreeEventParams(eventCode, p1, p2);
1518 
1519                         // 
1520                         // 检查附加事件 check for additional events
1521                         hr = mediaEvent.GetEvent(out eventCode, out p1, out p2, 0);
1522                     }
1523                     break;
1524 
1525                 // 所有其它的消息 All other messages
1526                 default:
1527                     // 未经处理的窗口消息 unhandled window message
1528                     base.WndProc(ref m);
1529                     break;
1530             }
1531         }
1532 
1533 
1534         #region Windows Form Designer generated code
1535         /// <summary>
1536         /// Required method for Designer support - do not modify
1537         /// the contents of this method with the code editor.
1538         /// </summary>
1539         private void InitializeComponent()
1540         { // http://www.cnblogs.com/endv/p/6052511.html
1541 
1542             this.components = new System.ComponentModel.Container();
1543             this.txtFilename = new System.Windows.Forms.TextBox();
1544             this.label1 = new System.Windows.Forms.Label();
1545             this.btnStart = new System.Windows.Forms.Button();
1546             this.btnStop = new System.Windows.Forms.Button();
1547             this.btnExit = new System.Windows.Forms.Button();
1548             this.mainMenu = new System.Windows.Forms.MainMenu(this.components);
1549             this.menuItem1 = new System.Windows.Forms.MenuItem();
1550             this.mnuExit = new System.Windows.Forms.MenuItem();
1551             this.mnuDevices = new System.Windows.Forms.MenuItem();
1552             this.mnuVideoDevices = new System.Windows.Forms.MenuItem();
1553             this.mnuAudioDevices = new System.Windows.Forms.MenuItem();
1554             this.menuItem4 = new System.Windows.Forms.MenuItem();
1555             this.mnuVideoCompressors = new System.Windows.Forms.MenuItem();
1556             this.mnuAudioCompressors = new System.Windows.Forms.MenuItem();
1557             this.menuItem7 = new System.Windows.Forms.MenuItem();
1558             this.mnuVideoSources = new System.Windows.Forms.MenuItem();
1559             this.mnuFrameSizes = new System.Windows.Forms.MenuItem();
1560             this.mnuFrameRates = new System.Windows.Forms.MenuItem();
1561             this.mnuVideoCaps = new System.Windows.Forms.MenuItem();
1562             this.menuItem5 = new System.Windows.Forms.MenuItem();
1563             this.mnuAudioSources = new System.Windows.Forms.MenuItem();
1564             this.mnuAudioChannels = new System.Windows.Forms.MenuItem();
1565             this.mnuAudioSamplingRate = new System.Windows.Forms.MenuItem();
1566             this.mnuAudioSampleSizes = new System.Windows.Forms.MenuItem();
1567             this.mnuAudioCaps = new System.Windows.Forms.MenuItem();
1568             this.menuItem3 = new System.Windows.Forms.MenuItem();
1569             this.mnuChannel = new System.Windows.Forms.MenuItem();
1570             this.mnuInputType = new System.Windows.Forms.MenuItem();
1571             this.menuItem6 = new System.Windows.Forms.MenuItem();
1572             this.mnuCompressionProps = new System.Windows.Forms.MenuItem();
1573             this.mnuPropertyPages = new System.Windows.Forms.MenuItem();
1574             this.menuItem8 = new System.Windows.Forms.MenuItem();
1575             this.mnuPreview = new System.Windows.Forms.MenuItem();
1576             this.panelVideo = new System.Windows.Forms.Panel();
1577             this.btnCue = new System.Windows.Forms.Button();
1578             this.txtDroppedFrames = new System.Windows.Forms.TextBox();
1579             this.label2 = new System.Windows.Forms.Label();
1580             this.tmrTime1 = new System.Windows.Forms.Timer(this.components);
1581             this.txtDuration = new System.Windows.Forms.TextBox();
1582             this.label3 = new System.Windows.Forms.Label();
1583             this.label4 = new System.Windows.Forms.Label();
1584             this.txtCapturedFrames = new System.Windows.Forms.TextBox();
1585             this.groupBox1 = new System.Windows.Forms.GroupBox();
1586             this.txtPreSize = new System.Windows.Forms.TextBox();
1587             this.label5 = new System.Windows.Forms.Label();
1588             this.groupBox1.SuspendLayout();
1589             this.SuspendLayout();
1590             // 
1591             // txtFilename
1592             // 
1593             this.txtFilename.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
1594             this.txtFilename.Location = new System.Drawing.Point(239, 330);
1595             this.txtFilename.Name = "txtFilename";
1596             this.txtFilename.Size = new System.Drawing.Size(182, 21);
1597             this.txtFilename.TabIndex = 0;
1598             this.txtFilename.Text = "test.avi";
1599             // 
1600             // label1
1601             // 
1602             this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
1603             this.label1.Location = new System.Drawing.Point(172, 330);
1604             this.label1.Name = "label1";
1605             this.label1.Size = new System.Drawing.Size(76, 17);
1606             this.label1.TabIndex = 1;
1607             this.label1.Text = "文件名:";
1608             // 
1609             // btnStart
1610             // 
1611             this.btnStart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
1612             this.btnStart.Location = new System.Drawing.Point(258, 364);
1613             this.btnStart.Name = "btnStart";
1614             this.btnStart.Size = new System.Drawing.Size(77, 26);
1615             this.btnStart.TabIndex = 2;
1616             this.btnStart.Text = "开始";
1617             this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
1618             // 
1619             // btnStop
1620             // 
1621             this.btnStop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
1622             this.btnStop.Enabled = false;
1623             this.btnStop.Location = new System.Drawing.Point(344, 364);
1624             this.btnStop.Name = "btnStop";
1625             this.btnStop.Size = new System.Drawing.Size(77, 26);
1626             this.btnStop.TabIndex = 3;
1627             this.btnStop.Text = "停止";
1628             this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
1629             // 
1630             // btnExit
1631             // 
1632             this.btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
1633             this.btnExit.Location = new System.Drawing.Point(440, 364);
1634             this.btnExit.Name = "btnExit";
1635             this.btnExit.Size = new System.Drawing.Size(87, 26);
1636             this.btnExit.TabIndex = 4;
1637             this.btnExit.Text = "退出";
1638             this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
1639             // 
1640             // mainMenu
1641             // 
1642             this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
1643             this.menuItem1,
1644             this.mnuDevices,
1645             this.menuItem7});
1646             // 
1647             // menuItem1
1648             // 
1649             this.menuItem1.Index = 0;
1650             this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
1651             this.mnuExit});
1652             this.menuItem1.Text = "文件";
1653             // 
1654             // mnuExit
1655             // 
1656             this.mnuExit.Index = 0;
1657             this.mnuExit.Text = "E&xit";
1658             this.mnuExit.Click += new System.EventHandler(this.mnuExit_Click);
1659             // 
1660             // mnuDevices
1661             // 
1662             this.mnuDevices.Index = 1;
1663             this.mnuDevices.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
1664             this.mnuVideoDevices,
1665             this.mnuAudioDevices,
1666             this.menuItem4,
1667             this.mnuVideoCompressors,
1668             this.mnuAudioCompressors});
1669             this.mnuDevices.Text = "设备";
1670             // 
1671             // mnuVideoDevices
1672             // 
1673             this.mnuVideoDevices.Index = 0;
1674             this.mnuVideoDevices.Text = "视频设备";
1675             // 
1676             // mnuAudioDevices
1677             // 
1678             this.mnuAudioDevices.Index = 1;
1679             this.mnuAudioDevices.Text = "音频设备";
1680             // 
1681             // menuItem4
1682             // 
1683             this.menuItem4.Index = 2;
1684             this.menuItem4.Text = "-";
1685             // 
1686             // mnuVideoCompressors
1687             // 
1688             this.mnuVideoCompressors.Index = 3;
1689             this.mnuVideoCompressors.Text = "视频压缩";
1690             // 
1691             // mnuAudioCompressors
1692             // 
1693             this.mnuAudioCompressors.Index = 4;
1694             this.mnuAudioCompressors.Text = "音频压缩";
1695             // 
1696             // menuItem7
1697             // 
1698             this.menuItem7.Index = 2;
1699             this.menuItem7.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
1700             this.mnuVideoSources,
1701             this.mnuFrameSizes,
1702             this.mnuFrameRates,
1703             this.mnuVideoCaps,
1704             this.menuItem5,
1705             this.mnuAudioSources,
1706             this.mnuAudioChannels,
1707             this.mnuAudioSamplingRate,
1708             this.mnuAudioSampleSizes,
1709             this.mnuAudioCaps,
1710             this.menuItem3,
1711             this.mnuChannel,
1712             this.mnuInputType,
1713             this.menuItem6,
1714             this.mnuCompressionProps,
1715             this.mnuPropertyPages,
1716             this.menuItem8,
1717             this.mnuPreview});
1718             this.menuItem7.Text = "选项";
1719             // 
1720             // mnuVideoSources
1721             // 
1722             this.mnuVideoSources.Index = 0;
1723             this.mnuVideoSources.Text = "视频源";
1724             // 
1725             // mnuFrameSizes
1726             // 
1727             this.mnuFrameSizes.Index = 1;
1728             this.mnuFrameSizes.Text = "视频帧的大小";
1729             // 
1730             // mnuFrameRates
1731             // 
1732             this.mnuFrameRates.Index = 2;
1733             this.mnuFrameRates.Text = "视频的帧速率";
1734             this.mnuFrameRates.Click += new System.EventHandler(this.mnuFrameRates_Click);
1735             // 
1736             // mnuVideoCaps
1737             // 
1738             this.mnuVideoCaps.Index = 3;
1739             this.mnuVideoCaps.Text = "视频特性";
1740             this.mnuVideoCaps.Click += new System.EventHandler(this.mnuVideoCaps_Click);
1741             // 
1742             // menuItem5
1743             // 
1744             this.menuItem5.Index = 4;
1745             this.menuItem5.Text = "-";
1746             // 
1747             // mnuAudioSources
1748             // 
1749             this.mnuAudioSources.Index = 5;
1750             this.mnuAudioSources.Text = "音频源";
1751             // 
1752             // mnuAudioChannels
1753             // 
1754             this.mnuAudioChannels.Index = 6;
1755             this.mnuAudioChannels.Text = "音频通道";
1756             // 
1757             // mnuAudioSamplingRate
1758             // 
1759             this.mnuAudioSamplingRate.Index = 7;
1760             this.mnuAudioSamplingRate.Text = "音频采样率";
1761             // 
1762             // mnuAudioSampleSizes
1763             // 
1764             this.mnuAudioSampleSizes.Index = 8;
1765             this.mnuAudioSampleSizes.Text = "音频样本大小";
1766             // 
1767             // mnuAudioCaps
1768             // 
1769             this.mnuAudioCaps.Index = 9;
1770             this.mnuAudioCaps.Text = "音频功能...";
1771             this.mnuAudioCaps.Click += new System.EventHandler(this.mnuAudioCaps_Click);
1772             // 
1773             // menuItem3
1774             // 
1775             this.menuItem3.Index = 10;
1776             this.menuItem3.Text = "-";
1777             // 
1778             // mnuChannel
1779             // 
1780             this.mnuChannel.Index = 11;
1781             this.mnuChannel.Text = "TV调谐器频道";
1782             // 
1783             // mnuInputType
1784             // 
1785             this.mnuInputType.Index = 12;
1786             this.mnuInputType.Text = "TV 调谐器输入类型";
1787             this.mnuInputType.Click += new System.EventHandler(this.mnuInputType_Click);
1788             // 
1789             // menuItem6
1790             // 
1791             this.menuItem6.Index = 13;
1792             this.menuItem6.Text = "-";
1793             // 
1794             // mnuCompressionProps
1795             // 
1796             this.mnuCompressionProps.Index = 14;
1797             this.mnuCompressionProps.Text = "压缩道具...";
1798             this.mnuCompressionProps.Click += new System.EventHandler(this.mnuCompressionProps_Click);
1799             // 
1800             // mnuPropertyPages
1801             // 
1802             this.mnuPropertyPages.Index = 15;
1803             this.mnuPropertyPages.Text = "属性页";
1804             // 
1805             // menuItem8
1806             // 
1807             this.menuItem8.Index = 16;
1808             this.menuItem8.Text = "-";
1809             // 
1810             // mnuPreview
1811             // 
1812             this.mnuPreview.Index = 17;
1813             this.mnuPreview.Text = "预览";
1814             this.mnuPreview.Click += new System.EventHandler(this.mnuPreview_Click);
1815             // 
1816             // panelVideo
1817             // 
1818             this.panelVideo.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
1819             | System.Windows.Forms.AnchorStyles.Left)
1820             | System.Windows.Forms.AnchorStyles.Right)));
1821             this.panelVideo.Location = new System.Drawing.Point(2, 8);
1822             this.panelVideo.Name = "panelVideo";
1823             this.panelVideo.Size = new System.Drawing.Size(735, 303);
1824             this.panelVideo.TabIndex = 6;
1825             // 
1826             // btnCue
1827             // 
1828             this.btnCue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
1829             this.btnCue.Location = new System.Drawing.Point(172, 364);
1830             this.btnCue.Name = "btnCue";
1831             this.btnCue.Size = new System.Drawing.Size(76, 26);
1832             this.btnCue.TabIndex = 1;
1833             this.btnCue.Text = "提示";
1834             this.btnCue.Click += new System.EventHandler(this.btnCue_Click);
1835             // 
1836             // txtDroppedFrames
1837             // 
1838             this.txtDroppedFrames.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
1839             this.txtDroppedFrames.CausesValidation = false;
1840             this.txtDroppedFrames.Location = new System.Drawing.Point(680, 330);
1841             this.txtDroppedFrames.Name = "txtDroppedFrames";
1842             this.txtDroppedFrames.ReadOnly = true;
1843             this.txtDroppedFrames.Size = new System.Drawing.Size(68, 21);
1844             this.txtDroppedFrames.TabIndex = 9;
1845             this.txtDroppedFrames.TabStop = false;
1846             this.txtDroppedFrames.Text = "0";
1847             // 
1848             // label2
1849             // 
1850             this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
1851             this.label2.Location = new System.Drawing.Point(613, 330);
1852             this.label2.Name = "label2";
1853             this.label2.Size = new System.Drawing.Size(58, 25);
1854             this.label2.TabIndex = 10;
1855             this.label2.Text = "丢帧";
1856             // 
1857             // tmrTime1
1858             // 
1859             this.tmrTime1.Interval = 999;
1860             this.tmrTime1.Tick += new System.EventHandler(this.tmrTime1_Tick);
1861             // 
1862             // txtDuration
1863             // 
1864             this.txtDuration.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
1865             this.txtDuration.Location = new System.Drawing.Point(527, 338);
1866             this.txtDuration.Name = "txtDuration";
1867             this.txtDuration.ReadOnly = true;
1868             this.txtDuration.Size = new System.Drawing.Size(77, 21);
1869             this.txtDuration.TabIndex = 11;
1870             this.txtDuration.TabStop = false;
1871             // 
1872             // label3
1873             // 
1874             this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
1875             this.label3.Location = new System.Drawing.Point(536, 321);
1876             this.label3.Name = "label3";
1877             this.label3.Size = new System.Drawing.Size(58, 17);
1878             this.label3.TabIndex = 12;
1879             this.label3.Text = "持续时间";
1880             // 
1881             // label4
1882             // 
1883             this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
1884             this.label4.Location = new System.Drawing.Point(604, 364);
1885             this.label4.Name = "label4";
1886             this.label4.Size = new System.Drawing.Size(67, 26);
1887             this.label4.TabIndex = 13;
1888             this.label4.Text = "捕获帧";
1889             // 
1890             // txtCapturedFrames
1891             // 
1892             this.txtCapturedFrames.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
1893             this.txtCapturedFrames.Location = new System.Drawing.Point(680, 364);
1894             this.txtCapturedFrames.Name = "txtCapturedFrames";
1895             this.txtCapturedFrames.ReadOnly = true;
1896             this.txtCapturedFrames.Size = new System.Drawing.Size(68, 21);
1897             this.txtCapturedFrames.TabIndex = 14;
1898             this.txtCapturedFrames.TabStop = false;
1899             this.txtCapturedFrames.Text = "0";
1900             // 
1901             // groupBox1
1902             // 
1903             this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
1904             | System.Windows.Forms.AnchorStyles.Left)
1905             | System.Windows.Forms.AnchorStyles.Right)));
1906             this.groupBox1.Controls.Add(this.panelVideo);
1907             this.groupBox1.Location = new System.Drawing.Point(10, 9);
1908             this.groupBox1.Name = "groupBox1";
1909             this.groupBox1.Size = new System.Drawing.Size(738, 312);
1910             this.groupBox1.TabIndex = 15;
1911             this.groupBox1.TabStop = false;
1912             this.groupBox1.Resize += new System.EventHandler(this.groupBox1_Resize);
1913             // 
1914             // txtPreSize
1915             // 
1916             this.txtPreSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
1917             this.txtPreSize.Location = new System.Drawing.Point(440, 338);
1918             this.txtPreSize.Name = "txtPreSize";
1919             this.txtPreSize.Size = new System.Drawing.Size(77, 21);
1920             this.txtPreSize.TabIndex = 16;
1921             this.txtPreSize.Text = "0";
1922             this.txtPreSize.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
1923             // 
1924             // label5
1925             // 
1926             this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
1927             this.label5.Location = new System.Drawing.Point(431, 321);
1928             this.label5.Name = "label5";
1929             this.label5.Size = new System.Drawing.Size(96, 17);
1930             this.label5.TabIndex = 17;
1931             this.label5.Text = "Pre-Size (Meg)";
1932             this.label5.TextAlign = System.Drawing.ContentAlignment.TopCenter;
1933             // 
1934             // CaptureTest
1935             // 
1936             this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
1937             this.ClientSize = new System.Drawing.Size(757, 404);
1938             this.Controls.Add(this.label5);
1939             this.Controls.Add(this.txtPreSize);
1940             this.Controls.Add(this.groupBox1);
1941             this.Controls.Add(this.txtCapturedFrames);
1942             this.Controls.Add(this.label4);
1943             this.Controls.Add(this.label3);
1944             this.Controls.Add(this.txtDuration);
1945             this.Controls.Add(this.label2);
1946             this.Controls.Add(this.txtDroppedFrames);
1947             this.Controls.Add(this.btnCue);
1948             this.Controls.Add(this.btnExit);
1949             this.Controls.Add(this.btnStop);
1950             this.Controls.Add(this.btnStart);
1951             this.Controls.Add(this.txtFilename);
1952             this.Controls.Add(this.label1);
1953             this.Menu = this.mainMenu;
1954             this.Name = "CaptureTest";
1955             this.Text = "捕捉测试";
1956             this.groupBox1.ResumeLayout(false);
1957             this.ResumeLayout(false);
1958             this.PerformLayout();
1959 
1960         }
1961         #endregion
1962 
1963     }
1964 }

 

DirectShowNet 使用摄像头录像+录音

标签:tun   library   initial   mode   runtime   curd   putty   rar   .text   

原文地址:http://www.cnblogs.com/endv/p/6052511.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!