DirectShowNet 使用摄像头录像+录音
http://www.cnblogs.com/endv/p/6052511.html
// ------------------------------------------------------------------
// CaptureTest.cs
// Sample application to show the DirectX.Capture class library.
//
// History:
// 2003-Jan-25 BL - created
//
// Copyright (c) 2003 Brian Low
// ------------------------------------------------------------------ using DirectShowLib;
using DirectX.Capture;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms; namespace CaptureTest
{
public class CaptureTest : System.Windows.Forms.Form
{
/// <summary>
/// 应用程序的主要入口点
/// </summary>
[STAThread]
static void Main()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
Application.Run(new CaptureTest());
GC.Collect();
GC.WaitForPendingFinalizers();
} // kernel32.dll是Windows9x/Me中非常重要的32位动态链接库文件,属于内核级文件。它控制着系统的内存管理、数据的输入输出操作和中断处理,
// 当Windows启动时,kernel32.dll就驻留在内存中特定的写保护区域,使别的程序无法占用这个内存区域
[DllImport("kernel32.dll")]
static extern uint GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, uint nSize, string lpFileName); [DllImport("kernel32.dll")]
static extern uint WritePrivateProfileString(string lpAppName, string lpKeyName, string lpString, string lpFileName); const int WM_GRAPHNOTIFY = 0x8000 + ;
private long iDroppedBefore = ;
private DateTime dtBefore;
private IMediaEventEx mediaEvent = null;
private int CaptureResult;
private 捕获 capture = null;
private Filters filters = new Filters();
private Size m_FrameSize; // Reading the value from capture.Framesize derenders the graph public CaptureTest()
{
InitializeComponent(); // 所需的窗体设计器支持 LoadDevices();//负载设备 if (capture != null)
{
LoadDeviceSettings();//加载设备设置
LoadCompressors();//加载压缩机
} // 更新主菜单中的许多有趣的工作,这个示例发生在这里
try { updateMenu(); } catch { } // 由于压缩机设置不在菜单上,不需要再做 updatemenu 。
// 已后要做的 updatemenu 由于其中一个调用重置这些。 if (capture != null)
{
LoadCompressorSettings();//加载压缩机设置
}
} #region 加载
//加载设备
protected void LoadDevices()
{
int x;
int iVideoDeviceIndex = -;
int iAudioDeviceIndex = -;
StringBuilder sbOut = new StringBuilder(); string sConfigFile = Application.LocalUserAppDataPath + "\\..\\Config.ini"; GetPrivateProfileString("Devices", "VideoDevice", "", sbOut, , sConfigFile); if (sbOut.Length > )
{
for (x = ; x < filters.VideoInputDevices.Count; x++)
{
if (filters.VideoInputDevices[x].Name == sbOut.ToString())
{
iVideoDeviceIndex = x;
break;
}
}
} GetPrivateProfileString("Devices", "AudioDevice", "", sbOut, , sConfigFile); if (sbOut.Length > )
{
for (x = ; x < filters.AudioInputDevices.Count; x++)
{
if (filters.AudioInputDevices[x].Name == sbOut.ToString())
{
iAudioDeviceIndex = x;
break;
}
}
} if ((iVideoDeviceIndex >= ) || (iAudioDeviceIndex >= ))
{
Filter i, j; if (iVideoDeviceIndex >= )
i = filters.VideoInputDevices[iVideoDeviceIndex];
else
i = null; if (iAudioDeviceIndex >= )
j = filters.AudioInputDevices[iAudioDeviceIndex];
else
j = null; capture = new 捕获(i, j); capture.CaptureComplete += new EventHandler(OnCaptureComplete); if (iVideoDeviceIndex >= )
{
GetPrivateProfileString("Devices", "VideoSource", "", sbOut, , sConfigFile); for (x = ; x < capture.VideoSources.Count; x++)
{
if (capture.VideoSources[x].Name == sbOut.ToString())
{
capture.VideoSource = capture.VideoSources[x];
break;
}
}
} if (iAudioDeviceIndex >= )
{
GetPrivateProfileString("Devices", "AudioSource", "", sbOut, , sConfigFile); for (x = ; x < capture.AudioSources.Count; x++)
{
if (capture.AudioSources[x].Name == sbOut.ToString())
{
capture.AudioSource = capture.AudioSources[x];
break;
}
}
}
}
} //加载设备设置
protected void LoadDeviceSettings()
{
StringBuilder sbOut = new StringBuilder();
string sConfigFile = Application.LocalUserAppDataPath + "\\..\\Config.ini"; if (capture.VideoDevice != null)
{
GetPrivateProfileString("DeviceSettings", "FrameRate", "", sbOut, , sConfigFile);
if (sbOut.Length > )
capture.FrameRate = Convert.ToDouble(sbOut.ToString()); GetPrivateProfileString("DeviceSettings", "VideoWidth", "", sbOut, , sConfigFile);
if (sbOut.Length > )
{
Size size = new Size(Convert.ToInt32(sbOut.ToString()), ); GetPrivateProfileString("DeviceSettings", "VideoHeight", "", sbOut, , sConfigFile);
if (sbOut.Length > )
{
size.Height = Convert.ToInt32(sbOut.ToString());
capture.FrameSize = size;
}
}
} if (capture.AudioDevice != null)
{
GetPrivateProfileString("DeviceSettings", "AudioChannel", "", sbOut, , sConfigFile);
if (sbOut.Length > )
{
capture.AudioChannels = Convert.ToInt16(sbOut.ToString());
} GetPrivateProfileString("DeviceSettings", "AudioRate", "", sbOut, , sConfigFile);
if (sbOut.Length > )
{
capture.AudioSamplingRate = Convert.ToInt32(sbOut.ToString());
} GetPrivateProfileString("DeviceSettings", "AudioSize", "", sbOut, , sConfigFile);
if (sbOut.Length > )
{
capture.AudioSampleSize = Convert.ToInt16(sbOut.ToString());
} GetPrivateProfileString("DeviceSettings", "AudioChannel", "", sbOut, , sConfigFile);
if (sbOut.Length > )
{
capture.AudioChannels = Convert.ToInt16(sbOut.ToString());
}
} }
//加载压缩机
protected void LoadCompressors()
{
int x;
StringBuilder sbOut = new StringBuilder();
string sConfigFile = Application.LocalUserAppDataPath + "\\..\\Config.ini"; if (capture.VideoDevice != null)
{
GetPrivateProfileString("Compressor", "VideoCompressor", "", sbOut, , sConfigFile); if (sbOut.Length > )
{
for (x = ; x < filters.VideoCompressors.Count; x++)
{
if (filters.VideoCompressors[x].Name == sbOut.ToString())
{
capture.VideoCompressor = filters.VideoCompressors[x];
break;
}
}
}
} if (capture.AudioDevice != null)
{
GetPrivateProfileString("Compressor", "AudioCompressor", "", sbOut, , sConfigFile); for (x = ; x < filters.AudioCompressors.Count; x++)
{
if (filters.AudioCompressors[x].Name == sbOut.ToString())
{
capture.AudioCompressor = filters.AudioCompressors[x];
break;
}
}
}
}
//加载压缩机设置
protected void LoadCompressorSettings()
{
StringBuilder sbOut = new StringBuilder();
string sConfigFile = Application.LocalUserAppDataPath + "\\..\\Config.ini"; if (capture.VideoCompressor != null)
{
try
{
VideoCompressorCaps i = capture.VideoCompressorCaps; GetPrivateProfileString("Compressor", "KeyFrameRate", "", sbOut, , sConfigFile);
if (sbOut.Length > )
i.KeyFrameRate = Convert.ToInt32(sbOut.ToString()); GetPrivateProfileString("Compressor", "PFrames", "", sbOut, , sConfigFile);
if (sbOut.Length > )
i.PFramesPerKeyFrame = Convert.ToInt32(sbOut.ToString()); GetPrivateProfileString("Compressor", "WindowSize", "", sbOut, , sConfigFile);
if (sbOut.Length > )
i.WindowSize = Convert.ToInt64(sbOut.ToString()); GetPrivateProfileString("Compressor", "Quality", "", sbOut, , sConfigFile);
if (sbOut.Length > )
i.Quality = Convert.ToInt32(sbOut.ToString());
}
catch { }
}
} //保存默认设置 "\\..\\Config.ini"
protected void SaveDefaults()
{
string sConfigFile = Application.LocalUserAppDataPath + "\\..\\Config.ini"; if (capture != null)
{
if (capture.VideoDevice != null)
{
WritePrivateProfileString("Devices", "VideoDevice", capture.VideoDevice.Name, sConfigFile);
WritePrivateProfileString("DeviceSettings", "FrameRate", capture.FrameRate.ToString(), sConfigFile);
WritePrivateProfileString("DeviceSettings", "VideoWidth", capture.FrameSize.Width.ToString(), sConfigFile);
WritePrivateProfileString("DeviceSettings", "VideoHeight", capture.FrameSize.Height.ToString(), sConfigFile);
}
else
{
WritePrivateProfileString("Devices", "VideoDevice", "", sConfigFile);
WritePrivateProfileString("DeviceSettings", "FrameRate", "", sConfigFile);
WritePrivateProfileString("DeviceSettings", "VideoWidth", "", sConfigFile);
WritePrivateProfileString("DeviceSettings", "VideoHeight", "", sConfigFile);
}
if (capture.AudioDevice != null)
{
WritePrivateProfileString("Devices", "AudioDevice", capture.AudioDevice.Name, sConfigFile);
WritePrivateProfileString("DeviceSettings", "AudioChannel", capture.AudioChannels.ToString(), sConfigFile);
WritePrivateProfileString("DeviceSettings", "AudioRate", capture.AudioSamplingRate.ToString(), sConfigFile);
WritePrivateProfileString("DeviceSettings", "AudioSize", capture.AudioSampleSize.ToString(), sConfigFile);
}
else
{
WritePrivateProfileString("Devices", "AudioDevice", "", sConfigFile);
WritePrivateProfileString("DeviceSettings", "AudioChannel", "", sConfigFile);
WritePrivateProfileString("DeviceSettings", "AudioRate", "", sConfigFile);
WritePrivateProfileString("DeviceSettings", "AudioSize", "", sConfigFile);
}
if (capture.VideoCompressor != null)
{
WritePrivateProfileString("Compressor", "VideoCompressor", capture.VideoCompressor.Name, sConfigFile); CompressionCaps i = CompressionCaps.None; try
{
i = capture.VideoCompressorCaps.GetCaps;
}
catch { } if ((i & CompressionCaps.CanKeyFrame) > )
WritePrivateProfileString("Compressor", "KeyFrameRate", capture.VideoCompressorCaps.KeyFrameRate.ToString(), sConfigFile); if ((i & CompressionCaps.CanBFrame) > )
WritePrivateProfileString("Compressor", "PFrames", capture.VideoCompressorCaps.PFramesPerKeyFrame.ToString(), sConfigFile); if ((i & CompressionCaps.CanWindow) > )
WritePrivateProfileString("Compressor", "WindowSize", capture.VideoCompressorCaps.WindowSize.ToString(), sConfigFile); if ((i & CompressionCaps.CanQuality) > )
WritePrivateProfileString("Compressor", "Quality", capture.VideoCompressorCaps.Quality.ToString(), sConfigFile); }
else
{
WritePrivateProfileString("Compressor", "VideoCompressor", "", sConfigFile);
WritePrivateProfileString("Compressor", "KeyFrameRate", "", sConfigFile);
WritePrivateProfileString("Compressor", "PFrames", "", sConfigFile);
WritePrivateProfileString("Compressor", "WindowSize", "", sConfigFile);
WritePrivateProfileString("Compressor", "Quality", "", sConfigFile);
}
if (capture.AudioCompressor != null)
{
WritePrivateProfileString("Compressor", "AudioCompressor", capture.AudioCompressor.Name, sConfigFile);
}
else
{
WritePrivateProfileString("Compressor", "AudioCompressor", "", sConfigFile);
}
if (capture.VideoSource != null)
{
WritePrivateProfileString("Devices", "VideoSource", capture.VideoSource.Name, sConfigFile);
}
else
{
WritePrivateProfileString("Devices", "VideoSource", "", sConfigFile);
}
if (capture.AudioSource != null)
{
WritePrivateProfileString("Devices", "AudioSource", capture.AudioSource.Name, sConfigFile);
}
else
{
WritePrivateProfileString("Devices", "AudioSource", "", sConfigFile);
} #if DEBUG
foreach (PropertyPage p in capture.PropertyPages)
{
if (p.SupportsPersisting)
{
// Doesn't seem to work right
Debug.WriteLine(p.Name);
}
}
#endif
}
} //更新主菜单中的许多有趣的工作,这个示例发生在这里
private void updateMenu()
{
MenuItem m;
Filter f;
Source s;
Source current;//当前
PropertyPage p;
Control oldPreviewWindow = null; // 正确的长宽比 Correct aspect ratio
if ((capture != null) && (capture.VideoDevice != null))
{
//帧大小
m_FrameSize = capture.FrameSize;
VideoWindowResize();
} // Give our window handle to the NotifyWindow so we'll get called about
// events of interest
if (capture != null)
{
mediaEvent = capture.MediaEventEx;
int hr = mediaEvent.SetNotifyWindow(this.Handle, WM_GRAPHNOTIFY, IntPtr.Zero);
} btnCue.Enabled = capture != null;
btnStart.Enabled = capture != null; // Disable preview to avoid additional flashes (optional)
if (capture != null)
{
oldPreviewWindow = capture.PreviewWindow;
capture.PreviewWindow = null;
} // Load video devices
Filter videoDevice = null;
if (capture != null)
videoDevice = capture.VideoDevice;
mnuVideoDevices.MenuItems.Clear();
m = new MenuItem("(None)", new EventHandler(mnuVideoDevices_Click));
m.Checked = (videoDevice == null);
mnuVideoDevices.MenuItems.Add(m);
for (int c = ; c < filters.VideoInputDevices.Count; c++)
{
f = filters.VideoInputDevices[c];
m = new MenuItem(f.Name, new EventHandler(mnuVideoDevices_Click));
m.Checked = (videoDevice == f);
mnuVideoDevices.MenuItems.Add(m);
}
mnuVideoDevices.Enabled = (filters.VideoInputDevices.Count > ); // Load audio devices
Filter audioDevice = null;
if (capture != null)
audioDevice = capture.AudioDevice;
mnuAudioDevices.MenuItems.Clear();
m = new MenuItem("(None)", new EventHandler(mnuAudioDevices_Click));
m.Checked = (audioDevice == null);
mnuAudioDevices.MenuItems.Add(m);
for (int c = ; c < filters.AudioInputDevices.Count; c++)
{
f = filters.AudioInputDevices[c];
m = new MenuItem(f.Name, new EventHandler(mnuAudioDevices_Click));
m.Checked = (audioDevice == f);
mnuAudioDevices.MenuItems.Add(m);
}
mnuAudioDevices.Enabled = (filters.AudioInputDevices.Count > ); // Load video compressors
try
{
mnuVideoCompressors.MenuItems.Clear();
m = new MenuItem("(None)", new EventHandler(mnuVideoCompressors_Click));
m.Checked = (capture.VideoCompressor == null);
mnuVideoCompressors.MenuItems.Add(m);
for (int c = ; c < filters.VideoCompressors.Count; c++)
{
f = filters.VideoCompressors[c];
m = new MenuItem(f.Name, new EventHandler(mnuVideoCompressors_Click));
m.Checked = (capture.VideoCompressor == f);
mnuVideoCompressors.MenuItems.Add(m);
}
mnuVideoCompressors.Enabled = ((capture.VideoDevice != null) && (filters.VideoCompressors.Count > ));
}
catch { mnuVideoCompressors.Enabled = false; } try
{
// Only enable the video compression menu option if the compressor
// supports at least one setting 如果选择菜单视频压缩压缩至少一个端口设置。允许
mnuCompressionProps.Enabled = (capture.VideoCompressorCaps.GetCaps &
(CompressionCaps.CanBFrame |
CompressionCaps.CanKeyFrame |
CompressionCaps.CanQuality |
CompressionCaps.CanWindow)) > ;
}
catch
{
mnuCompressionProps.Enabled = false;
} // Load audio 压缩机(compressors)
try
{
mnuAudioCompressors.MenuItems.Clear();
m = new MenuItem("(None)", new EventHandler(mnuAudioCompressors_Click));
m.Checked = (capture.AudioCompressor == null);
mnuAudioCompressors.MenuItems.Add(m);
for (int c = ; c < filters.AudioCompressors.Count; c++)
{
f = filters.AudioCompressors[c];
m = new MenuItem(f.Name, new EventHandler(mnuAudioCompressors_Click));
m.Checked = (capture.AudioCompressor == f);
mnuAudioCompressors.MenuItems.Add(m);
}
mnuAudioCompressors.Enabled = ((capture.AudioDevice != null) && (filters.AudioCompressors.Count > ));
}
catch { mnuAudioCompressors.Enabled = false; } // Load video sources
try
{
mnuVideoSources.MenuItems.Clear();
current = capture.VideoSource;
for (int c = ; c < capture.VideoSources.Count; c++)
{
s = capture.VideoSources[c];
m = new MenuItem(s.Name, new EventHandler(mnuVideoSources_Click));
m.Checked = (current == s);
mnuVideoSources.MenuItems.Add(m);
}
mnuVideoSources.Enabled = (capture.VideoSources.Count > );
}
catch { mnuVideoSources.Enabled = false; } // Load audio sources
try
{
mnuAudioSources.MenuItems.Clear();
current = capture.AudioSource;
for (int c = ; c < capture.AudioSources.Count; c++)
{
s = capture.AudioSources[c];
m = new MenuItem(s.Name, new EventHandler(mnuAudioSources_Click));
m.Checked = (current == s);
mnuAudioSources.MenuItems.Add(m);
}
mnuAudioSources.Enabled = (capture.AudioSources.Count > );
}
catch { mnuAudioSources.Enabled = false; } // Load frame rates
try
{
mnuFrameRates.MenuItems.Clear();
int frameRate = (int)(capture.FrameRate * );
m = new MenuItem("15 fps", new EventHandler(mnuFrameRates_Click));
m.Checked = (frameRate == );
mnuFrameRates.MenuItems.Add(m);
m = new MenuItem("24 fps (Film)", new EventHandler(mnuFrameRates_Click));
m.Checked = (frameRate == );
mnuFrameRates.MenuItems.Add(m);
m = new MenuItem("25 fps (PAL)", new EventHandler(mnuFrameRates_Click));
m.Checked = (frameRate == );
mnuFrameRates.MenuItems.Add(m);
m = new MenuItem("29.997 fps (NTSC)", new EventHandler(mnuFrameRates_Click));
m.Checked = (frameRate == ) || (frameRate == );
mnuFrameRates.MenuItems.Add(m);
m = new MenuItem("30 fps (~NTSC)", new EventHandler(mnuFrameRates_Click));
m.Checked = (frameRate == );
mnuFrameRates.MenuItems.Add(m);
m = new MenuItem("59.994 fps (2xNTSC)", new EventHandler(mnuFrameRates_Click));
m.Checked = (frameRate == );
mnuFrameRates.MenuItems.Add(m);
mnuFrameRates.Enabled = true;
}
catch { mnuFrameRates.Enabled = false; } // Load frame sizes
try
{
mnuFrameSizes.MenuItems.Clear();
Size frameSize = capture.FrameSize;
m = new MenuItem("160 x 120", new EventHandler(mnuFrameSizes_Click));
m.Checked = (frameSize == new Size(, ));
mnuFrameSizes.MenuItems.Add(m);
m = new MenuItem("320 x 240", new EventHandler(mnuFrameSizes_Click));
m.Checked = (frameSize == new Size(, ));
mnuFrameSizes.MenuItems.Add(m);
m = new MenuItem("640 x 480", new EventHandler(mnuFrameSizes_Click));
m.Checked = (frameSize == new Size(, ));
mnuFrameSizes.MenuItems.Add(m);
m = new MenuItem("1024 x 768", new EventHandler(mnuFrameSizes_Click));
m.Checked = (frameSize == new Size(, ));
mnuFrameSizes.MenuItems.Add(m);
mnuFrameSizes.Enabled = true;
}
catch { mnuFrameSizes.Enabled = false; } // Load audio channels
try
{
mnuAudioChannels.MenuItems.Clear();
short audioChannels = capture.AudioChannels;
m = new MenuItem("单声道 Mono", new EventHandler(mnuAudioChannels_Click));
m.Checked = (audioChannels == );
mnuAudioChannels.MenuItems.Add(m);
m = new MenuItem("立体声 Stereo", new EventHandler(mnuAudioChannels_Click));
m.Checked = (audioChannels == );
mnuAudioChannels.MenuItems.Add(m);
mnuAudioChannels.Enabled = true;
}
catch { mnuAudioChannels.Enabled = false; } // Load音频采样率 Load audio sampling rate
try
{
mnuAudioSamplingRate.MenuItems.Clear();
int samplingRate = capture.AudioSamplingRate;
m = new MenuItem("8 kHz", new EventHandler(mnuAudioSamplingRate_Click));
m.Checked = (samplingRate == );
mnuAudioSamplingRate.MenuItems.Add(m);
m = new MenuItem("11.025 kHz", new EventHandler(mnuAudioSamplingRate_Click));
m.Checked = (capture.AudioSamplingRate == );
mnuAudioSamplingRate.MenuItems.Add(m);
m = new MenuItem("22.05 kHz", new EventHandler(mnuAudioSamplingRate_Click));
m.Checked = (capture.AudioSamplingRate == );
mnuAudioSamplingRate.MenuItems.Add(m);
m = new MenuItem("44.1 kHz", new EventHandler(mnuAudioSamplingRate_Click));
m.Checked = (capture.AudioSamplingRate == );
mnuAudioSamplingRate.MenuItems.Add(m);
mnuAudioSamplingRate.Enabled = true;
}
catch { mnuAudioSamplingRate.Enabled = false; } // 加载音频样本大小 Load audio sample sizes
try
{
mnuAudioSampleSizes.MenuItems.Clear();
short sampleSize = capture.AudioSampleSize;
m = new MenuItem("8 bit", new EventHandler(mnuAudioSampleSizes_Click));
m.Checked = (sampleSize == );
mnuAudioSampleSizes.MenuItems.Add(m);
m = new MenuItem("16 bit", new EventHandler(mnuAudioSampleSizes_Click));
m.Checked = (sampleSize == );
mnuAudioSampleSizes.MenuItems.Add(m);
mnuAudioSampleSizes.Enabled = true;
}
catch { mnuAudioSampleSizes.Enabled = false; } // 加载属性页 Load property pages
try
{
mnuPropertyPages.MenuItems.Clear();
for (int c = ; c < capture.PropertyPages.Count; c++)
{
p = capture.PropertyPages[c];
m = new MenuItem(p.Name + "...", new EventHandler(mnuPropertyPages_Click));
mnuPropertyPages.MenuItems.Add(m);
}
mnuPropertyPages.Enabled = (capture.PropertyPages.Count > );
}
catch { mnuPropertyPages.Enabled = false; } // Load TV Tuner channels
try
{
mnuChannel.MenuItems.Clear();
int channel = capture.Tuner.Channel;
for (int c = ; c <= ; c++)
{
m = new MenuItem(c.ToString(), new EventHandler(mnuChannel_Click));
m.Checked = (channel == c);
mnuChannel.MenuItems.Add(m);
}
mnuChannel.Enabled = true;
}
catch { mnuChannel.Enabled = false; } // Load TV Tuner input types
try
{
mnuInputType.MenuItems.Clear();
m = new MenuItem(DirectX.Capture.TunerInputType.Cable.ToString(), new EventHandler(mnuInputType_Click));
m.Checked = (capture.Tuner.InputType == DirectX.Capture.TunerInputType.Cable);
mnuInputType.MenuItems.Add(m);
m = new MenuItem(DirectX.Capture.TunerInputType.Antenna.ToString(), new EventHandler(mnuInputType_Click));
m.Checked = (capture.Tuner.InputType == DirectX.Capture.TunerInputType.Antenna);
mnuInputType.MenuItems.Add(m);
mnuInputType.Enabled = true;
}
catch { mnuInputType.Enabled = false; } // Enable/disable caps
mnuVideoCaps.Enabled = ((capture != null) && (capture.VideoCaps != null));
mnuAudioCaps.Enabled = ((capture != null) && (capture.AudioCaps != null)); // Check Preview menu option
mnuPreview.Checked = (oldPreviewWindow != null);
mnuPreview.Enabled = (capture != null); // Reenable preview if it was enabled before
if (capture != null)
capture.PreviewWindow = oldPreviewWindow;
}
#endregion 加载 #region 方法 private void Stop()
{
try
{
ShowDropped();
capture.Stop();
btnCue.Enabled = true;
btnStart.Enabled = true;
btnStop.Enabled = false;
txtFilename.Enabled = true;
btnStart.Select();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void VideoWindowResize()
{
if ((capture != null) && (m_FrameSize.Width > ))
{
Size ns; int iMaxHeight = Math.Min(m_FrameSize.Height, groupBox1.Height - ); //不要践踏我们的分组框的边界 Don't trample the borders
int iMaxWidth = Math.Min(m_FrameSize.Width, groupBox1.Width - ); // of our GroupBox int t2 = (iMaxWidth * m_FrameSize.Height) / m_FrameSize.Width; // Which proportion do we need to limit?
if (t2 > iMaxHeight)
{
int t1 = (iMaxHeight * m_FrameSize.Width) / m_FrameSize.Height;
ns = new Size(t1, iMaxHeight);
}
else
{
ns = new Size(iMaxWidth, t2);
}
panelVideo.Size = ns;
}
} // 更新 捕获/下降/时间字段的查询捕获装置
//Update the Capture/Dropped/Duration fields by quering the capture device
private void ShowDropped()
{
TimeSpan duDuration;
long iCurDropped = capture.DroppedVideoFrames;
long iCaptured = capture.CapturedVideoFrames; if (iCurDropped >= )
txtDroppedFrames.Text = (iCurDropped - iDroppedBefore).ToString(); if (iCaptured > )
txtCapturedFrames.Text = iCaptured.ToString(); duDuration = DateTime.Now - dtBefore;
txtDuration.Text = duDuration.ToString();
} #endregion 方法 #region 菜单事件 private void mnuVideoDevices_Click(object sender, System.EventArgs e)
{
try
{
// 由于视频和音频设备只能通过创建一个新的捕获对象来改变,因此获取当前的设备和处理捕获对象。
// Get current devices and dispose of capture object
// because the video and audio device can only be changed
// by creating a new Capture object.
Filter videoDevice = null;
Filter audioDevice = null;
if (capture != null)
{
videoDevice = capture.VideoDevice;
audioDevice = capture.AudioDevice;
capture.Dispose();
capture = null;
} // Get new video device
MenuItem m = sender as MenuItem;
videoDevice = (m.Index > ? filters.VideoInputDevices[m.Index - ] : null); // Create capture object
if ((videoDevice != null) || (audioDevice != null))
{
capture = new 捕获(videoDevice, audioDevice);
capture.CaptureComplete += new EventHandler(OnCaptureComplete);
} // Update the menu
updateMenu();
}
catch (Exception ex)
{
MessageBox.Show("视频设备不支持.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void mnuAudioDevices_Click(object sender, System.EventArgs e)
{
try
{
// Get current devices and dispose of capture object
// because the video and audio device can only be changed
// by creating a new Capture object.
Filter videoDevice = null;
Filter audioDevice = null;
Filter videoCompressor = null;
if (capture != null)
{
videoDevice = capture.VideoDevice;
audioDevice = capture.AudioDevice;
videoCompressor = capture.VideoCompressor;
capture.Dispose();
capture = null;
} // Get new audio device
MenuItem m = sender as MenuItem;
audioDevice = (m.Index > ? filters.AudioInputDevices[m.Index - ] : null); // Create capture object
if ((videoDevice != null) || (audioDevice != null))
{
capture = new 捕获(videoDevice, audioDevice);
capture.CaptureComplete += new EventHandler(OnCaptureComplete);
} capture.VideoCompressor = videoCompressor; // Update the menu
updateMenu();
}
catch (Exception ex)
{
MessageBox.Show("音频设备不支持.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void mnuVideoCompressors_Click(object sender, System.EventArgs e)
{
try
{
// Change the video compressor
// We subtract 1 from m.Index beacuse the first item is (None)
MenuItem m = sender as MenuItem;
capture.VideoCompressor = (m.Index > ? filters.VideoCompressors[m.Index - ] : null);
updateMenu();
}
catch (Exception ex)
{
MessageBox.Show("视频压缩不支持.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
} } private void mnuAudioCompressors_Click(object sender, System.EventArgs e)
{
try
{
// Change the audio compressor
// We subtract 1 from m.Index beacuse the first item is (None)
MenuItem m = sender as MenuItem;
capture.AudioCompressor = (m.Index > ? filters.AudioCompressors[m.Index - ] : null);
updateMenu();
}
catch (Exception ex)
{
MessageBox.Show("音频压缩不支持.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void mnuVideoSources_Click(object sender, System.EventArgs e)
{
try
{
// Choose the video source
// If the device only has one source, this menu item will be disabled
MenuItem m = sender as MenuItem;
capture.VideoSource = capture.VideoSources[m.Index];
updateMenu();
}
catch (Exception ex)
{
MessageBox.Show("无法设置视频源。请提交错误报告.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void mnuAudioSources_Click(object sender, System.EventArgs e)
{
try
{
// Choose the audio source
// If the device only has one source, this menu item will be disabled
MenuItem m = sender as MenuItem;
capture.AudioSource = capture.AudioSources[m.Index];
updateMenu();
}
catch (Exception ex)
{
MessageBox.Show("无法设置音频源。请提交错误报告.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void mnuExit_Click(object sender, System.EventArgs e)
{
if (capture != null)
capture.Stop();
Application.Exit();
} private void mnuFrameSizes_Click(object sender, System.EventArgs e)
{
try
{
// Disable preview to avoid additional flashes (optional)
bool preview = (capture.PreviewWindow != null);
capture.PreviewWindow = null; // Update the frame size
MenuItem m = sender as MenuItem;
string[] s = m.Text.Split('x');
Size size = new Size(int.Parse(s[]), int.Parse(s[]));
capture.FrameSize = size; // Update the menu
updateMenu(); // Restore previous preview setting
capture.PreviewWindow = (preview ? panelVideo : null);
}
catch (Exception ex)
{
MessageBox.Show("帧大小不支持.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void mnuFrameRates_Click(object sender, System.EventArgs e)
{
try
{
MenuItem m = sender as MenuItem;
string[] s = m.Text.Split(' ');
capture.FrameRate = double.Parse(s[]);
updateMenu();
}
catch (Exception ex)
{
MessageBox.Show("不支持的帧速率.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void mnuAudioChannels_Click(object sender, System.EventArgs e)
{
try
{
MenuItem m = sender as MenuItem;
capture.AudioChannels = (short)Math.Pow(, m.Index);
updateMenu();
}
catch (Exception ex)
{
MessageBox.Show("不支持的音频信道数.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void mnuAudioSamplingRate_Click(object sender, System.EventArgs e)
{
try
{
MenuItem m = sender as MenuItem;
string[] s = m.Text.Split(' ');
int samplingRate = (int)(double.Parse(s[]) * );
capture.AudioSamplingRate = samplingRate;
updateMenu();
}
catch (Exception ex)
{
MessageBox.Show("不支持音频采样率.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void mnuAudioSampleSizes_Click(object sender, System.EventArgs e)
{
try
{
MenuItem m = sender as MenuItem;
string[] s = m.Text.Split(' ');
short sampleSize = short.Parse(s[]);
capture.AudioSampleSize = sampleSize;
updateMenu();
}
catch (Exception ex)
{
MessageBox.Show("音频样本大小不支持.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void mnuPreview_Click(object sender, System.EventArgs e)
{
try
{
if (capture.PreviewWindow == null)
{
capture.PreviewWindow = panelVideo;
mnuPreview.Checked = true;
}
else
{
capture.PreviewWindow = null;
mnuPreview.Checked = false;
}
}
catch (Exception ex)
{
MessageBox.Show("无法启用/禁用预览。请提交一个错误报告。\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void mnuPropertyPages_Click(object sender, System.EventArgs e)
{
try
{
MenuItem m = sender as MenuItem;
capture.PropertyPages[m.Index].Show(this);
updateMenu();
}
catch (Exception ex)
{
MessageBox.Show("无法显示属性页。请提交一个错误报告.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void mnuChannel_Click(object sender, System.EventArgs e)
{
try
{
MenuItem m = sender as MenuItem;
capture.Tuner.Channel = m.Index + ;
updateMenu();
}
catch (Exception ex)
{
MessageBox.Show("无法更改通道。请提交一个错误报告.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void mnuInputType_Click(object sender, System.EventArgs e)
{
try
{
MenuItem m = sender as MenuItem;
capture.Tuner.InputType = (DirectX.Capture.TunerInputType)m.Index;
updateMenu();
}
catch (Exception ex)
{
MessageBox.Show("无法更改调谐器输入类型。请提交一个错误报告.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void mnuVideoCaps_Click(object sender, System.EventArgs e)
{
try
{
string s;
s = String.Format(
"输入尺寸:\t\t{0} x {1}\n" +
"\n" +
"最小帧长度:\t\t{2} x {3}\n" +//最小帧长度
"最大帧长度:\t\t{4} x {5}\n" +//最大帧长度
"帧尺寸粒度 X:\t{6}\n" +//帧大小粒度
"帧尺寸粒度 Y:\t{7}\n" +
"\n" +
"最小帧速率:\t\t{8:0.000} fps\n" +//最小帧速率
"最大帧速率:\t\t{9:0.000} fps\n",
capture.VideoCaps.InputSize.Width, capture.VideoCaps.InputSize.Height,
capture.VideoCaps.MinFrameSize.Width, capture.VideoCaps.MinFrameSize.Height,
capture.VideoCaps.MaxFrameSize.Width, capture.VideoCaps.MaxFrameSize.Height,
capture.VideoCaps.FrameSizeGranularityX,
capture.VideoCaps.FrameSizeGranularityY,
capture.VideoCaps.MinFrameRate,
capture.VideoCaps.MaxFrameRate);
MessageBox.Show(s, "视频设备能力", MessageBoxButtons.OK, MessageBoxIcon.Information); }
catch (Exception ex)
{
MessageBox.Show("无法显示视频功能。请提交一个错误报告.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void mnuAudioCaps_Click(object sender, System.EventArgs e)
{
try
{
string s;
s = String.Format(
"Min Channels:\t\t{0}\n" +
"Max Channels:\t\t{1}\n" +
"Channels Granularity:\t{2}\n" +
"\n" +
"Min Sample Size:\t\t{3}\n" +
"Max Sample Size:\t\t{4}\n" +
"Sample Size Granularity:\t{5}\n" +
"\n" +
"Min Sampling Rate:\t\t{6}\n" +
"Max Sampling Rate:\t\t{7}\n" +
"Sampling Rate Granularity:\t{8}\n",
capture.AudioCaps.MinimumChannels,
capture.AudioCaps.MaximumChannels,
capture.AudioCaps.ChannelsGranularity,
capture.AudioCaps.MinimumSampleSize,
capture.AudioCaps.MaximumSampleSize,
capture.AudioCaps.SampleSizeGranularity,
capture.AudioCaps.MinimumSamplingRate,
capture.AudioCaps.MaximumSamplingRate,
capture.AudioCaps.SamplingRateGranularity);
MessageBox.Show(s, "音频设备能力", MessageBoxButtons.OK, MessageBoxIcon.Information); }
catch (Exception ex)
{
MessageBox.Show("Unable display audio capabilities. Please submit a bug report.\n\n" + ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} // 单击“菜单”选项显示压缩机属性 On clicking the menu option to display Compressor Properties
private void mnuCompressionProps_Click(object sender, System.EventArgs e)
{
// Prepare to show the form
CompressionProps m = new CompressionProps(); // Read what compression capabilities are available
CompressionCaps i = capture.VideoCompressorCaps.GetCaps; bool bSet = (i & CompressionCaps.CanKeyFrame) > ; // Enable the available keyframe controls
m.txtKeyFrame.Enabled = bSet;
m.labKeyFrame.Enabled = bSet;
m.chkKeyFrame.Enabled = bSet; // copy in the default values
if (bSet)
{
long v = capture.VideoCompressorCaps.KeyFrameRate; // Using default?
if (v < )
{
m.txtKeyFrame.Text = "";
m.chkKeyFrame.Checked = true;
m.txtKeyFrame.Enabled = false;
}
else
{
m.txtKeyFrame.Text = v.ToString();
m.chkKeyFrame.Checked = false;
}
} bSet = (i & CompressionCaps.CanBFrame) > ; // Enable the available PFrames controls
m.txtPFrames.Enabled = bSet;
m.labPFrames.Enabled = bSet;
m.chkPFrames.Enabled = bSet;
if (bSet)
{
long v = capture.VideoCompressorCaps.PFramesPerKeyFrame; // Using default?
if (v < )
{
m.txtPFrames.Text = "";
m.chkPFrames.Checked = true;
m.txtPFrames.Enabled = false;
}
else
{
m.txtPFrames.Text = v.ToString();
m.chkPFrames.Checked = false;
}
} bSet = (i & CompressionCaps.CanWindow) > ; // Enable the available WindowSize controls
m.txtWindowSize.Enabled = bSet;
m.labWindowSize.Enabled = bSet;
m.chkWindowSize.Enabled = bSet;
m.chkWindowSize.Checked = false; if (bSet)
{
m.txtWindowSize.Text = capture.VideoCompressorCaps.WindowSize.ToString();
} bSet = (i & CompressionCaps.CanQuality) > ; // Enable the available Quality controls
m.txtQuality.Enabled = bSet;
m.trkQuality.Enabled = bSet;
m.labQuality.Enabled = bSet;
m.chkQuality.Enabled = bSet;
if (bSet)
{
long v = capture.VideoCompressorCaps.Quality; // Using default?
if (v < )
{
m.txtQuality.Text = "";
m.chkQuality.Checked = true;
m.trkQuality.Value = ;
m.trkQuality.Enabled = false;
m.txtQuality.Enabled = false;
}
else
{
m.txtQuality.Text = v.ToString();
m.chkQuality.Checked = false;
m.trkQuality.Value = capture.VideoCompressorCaps.Quality;
}
} // Display the form
DialogResult a = m.ShowDialog(this); // If the user clicked OK, set the values they specified
if (DialogResult.OK == a)
{
if ((i & CompressionCaps.CanKeyFrame) > )
{
int v;
if (m.chkKeyFrame.Checked)
{
// Use default
v = -;
}
else
{
v = Convert.ToInt32(m.txtKeyFrame.Text);
}
capture.VideoCompressorCaps.KeyFrameRate = v;
} if ((i & CompressionCaps.CanBFrame) > )
{
int v;
if (m.chkPFrames.Checked)
{
// Use default
v = -;
}
else
{
v = Convert.ToInt32(m.txtPFrames.Text);
}
capture.VideoCompressorCaps.PFramesPerKeyFrame = v;
} if ((i & CompressionCaps.CanWindow) > )
{
long v;
if (m.chkWindowSize.Checked)
{
// Use default
v = ;
}
else
{
v = Convert.ToInt64(m.txtWindowSize.Text);
}
capture.VideoCompressorCaps.WindowSize = v;
} if ((i & CompressionCaps.CanQuality) > )
{
int v; if (m.chkQuality.Checked)
{
// Use default
v = -;
}
else
{
v = Convert.ToInt32(m.txtQuality.Text);
}
capture.VideoCompressorCaps.Quality = v;
}
}
} #endregion 菜单事件 #region 事件 private void btnExit_Click(object sender, System.EventArgs e)
{
if (capture != null)
{
capture.Stop();
SaveDefaults();
}
Application.Exit();
} private void btnCue_Click(object sender, System.EventArgs e)
{
try
{
if (capture == null)
throw new ApplicationException("请选择一个视频和/或音频设备.");
if (!capture.Cued)
capture.Filename = txtFilename.Text; CaptureResult = ;
txtDroppedFrames.Text = "";
txtCapturedFrames.Text = "";
txtDuration.Text = "";
txtFilename.Enabled = false; capture.Cue();
capture.PreSize(Convert.ToInt64(txtPreSize.Text) * ); btnCue.Enabled = false;
btnStop.Enabled = true;
//“使用cue() 先于 start() 做的所有准备工作,
//需要做的事开始捕捉。现在,当您单击“开始”时,
//捕获的速度将比您刚刚单击“启动”开始的速度更快。
//使用cue()完全是可选的。使用cue()坏处是预览被禁用,直到捕获开始。
MessageBox.Show("Use Cue() before Start() to " +
"do all the preparation work that needs to be done to start a " +
"capture. Now, when you click Start the capture will begin faster " +
"than if you had just clicked Start. Using Cue() is completely " +
"optional. The downside to using Cue() is the preview is disabled until " +
"the capture begins.", "Ready to Capture", MessageBoxButtons.OK, MessageBoxIcon.Information);
btnStart.Select();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void btnStart_Click(object sender, System.EventArgs e)
{
try
{
if (capture == null)
throw new ApplicationException("请选择一个视频和/或音频设备。");
if (!capture.Cued)
capture.Filename = txtFilename.Text; CaptureResult = ;
iDroppedBefore = capture.DroppedVideoFrames;
dtBefore = DateTime.Now;
txtDroppedFrames.Text = "";
txtCapturedFrames.Text = "";
txtDuration.Text = "";
txtFilename.Enabled = false;
capture.Start();
tmrTime1.Enabled = true;
btnCue.Enabled = false;
btnStart.Enabled = false;
btnStop.Enabled = true;
btnStop.Select();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void btnStop_Click(object sender, System.EventArgs e)
{
Stop();
} private void OnCaptureComplete(object sender, EventArgs e)
{
// 显示捕获捕获完成事件 Demonstrate the Capture.CaptureComplete event.
tmrTime1.Enabled = false; // 如果窗口消息处理程序中止了我们… If the windows message handler aborted us...
if (CaptureResult != )//捕获的结果
MessageBox.Show("Capture Error 0x" + CaptureResult.ToString("x"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
} // Update the Captured/Dropped fields while capturing
private void tmrTime1_Tick(Object myObject, EventArgs myEventArgs)
{
if (CaptureResult == )
{
ShowDropped();
}
else
{
Stop();
}
} private void groupBox1_Resize(object sender, System.EventArgs e)
{
VideoWindowResize();
} #endregion 事件
// http://www.cnblogs.com/endv/p/6052511.html #region private
private System.Windows.Forms.TextBox txtFilename;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnStart;
private System.Windows.Forms.Button btnStop;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MainMenu mainMenu;
private System.Windows.Forms.MenuItem mnuExit;
private System.Windows.Forms.MenuItem mnuDevices;
private System.Windows.Forms.MenuItem mnuVideoDevices;
private System.Windows.Forms.MenuItem mnuAudioDevices;
private System.Windows.Forms.MenuItem mnuVideoCompressors;
private System.Windows.Forms.MenuItem mnuAudioCompressors;
private System.Windows.Forms.MenuItem mnuVideoSources;
private System.Windows.Forms.MenuItem mnuAudioSources;
private System.Windows.Forms.Panel panelVideo;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem mnuAudioChannels;
private System.Windows.Forms.MenuItem mnuAudioSamplingRate;
private System.Windows.Forms.MenuItem mnuAudioSampleSizes;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem mnuFrameSizes;
private System.Windows.Forms.MenuItem mnuFrameRates;
private System.Windows.Forms.Button btnCue;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem mnuPreview;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.MenuItem mnuPropertyPages;
private System.Windows.Forms.MenuItem mnuVideoCaps;
private System.Windows.Forms.MenuItem mnuAudioCaps;
private System.Windows.Forms.MenuItem mnuChannel;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem mnuInputType;
private System.Windows.Forms.TextBox txtDroppedFrames;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Timer tmrTime1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txtDuration;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtCapturedFrames;
private System.Windows.Forms.MenuItem mnuCompressionProps;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox txtPreSize;
private System.ComponentModel.IContainer components;
#endregion private /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
// 媒体事件发送使用Windows消息 Media events are sent to use as windows messages
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
// If this is a windows media message
case WM_GRAPHNOTIFY:
EventCode eventCode;//捕获已中止?
IntPtr p1, p2;
int hr; hr = mediaEvent.GetEvent(out eventCode, out p1, out p2, );
while (hr == )
{
// 处理事件
// 捕获已中止 The capture has been aborted
if (eventCode == EventCode.ErrorAbort)
{
CaptureResult = p1.ToInt32();
} // 释放参数
mediaEvent.FreeEventParams(eventCode, p1, p2); //
// 检查附加事件 check for additional events
hr = mediaEvent.GetEvent(out eventCode, out p1, out p2, );
}
break; // 所有其它的消息 All other messages
default:
// 未经处理的窗口消息 unhandled window message
base.WndProc(ref m);
break;
}
} #region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{ // http://www.cnblogs.com/endv/p/6052511.html this.components = new System.ComponentModel.Container();
this.txtFilename = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.btnStart = new System.Windows.Forms.Button();
this.btnStop = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.mainMenu = new System.Windows.Forms.MainMenu(this.components);
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.mnuExit = new System.Windows.Forms.MenuItem();
this.mnuDevices = new System.Windows.Forms.MenuItem();
this.mnuVideoDevices = new System.Windows.Forms.MenuItem();
this.mnuAudioDevices = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.mnuVideoCompressors = new System.Windows.Forms.MenuItem();
this.mnuAudioCompressors = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.mnuVideoSources = new System.Windows.Forms.MenuItem();
this.mnuFrameSizes = new System.Windows.Forms.MenuItem();
this.mnuFrameRates = new System.Windows.Forms.MenuItem();
this.mnuVideoCaps = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.mnuAudioSources = new System.Windows.Forms.MenuItem();
this.mnuAudioChannels = new System.Windows.Forms.MenuItem();
this.mnuAudioSamplingRate = new System.Windows.Forms.MenuItem();
this.mnuAudioSampleSizes = new System.Windows.Forms.MenuItem();
this.mnuAudioCaps = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.mnuChannel = new System.Windows.Forms.MenuItem();
this.mnuInputType = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.mnuCompressionProps = new System.Windows.Forms.MenuItem();
this.mnuPropertyPages = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.mnuPreview = new System.Windows.Forms.MenuItem();
this.panelVideo = new System.Windows.Forms.Panel();
this.btnCue = new System.Windows.Forms.Button();
this.txtDroppedFrames = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.tmrTime1 = new System.Windows.Forms.Timer(this.components);
this.txtDuration = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.txtCapturedFrames = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.txtPreSize = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// txtFilename
//
this.txtFilename.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.txtFilename.Location = new System.Drawing.Point(, );
this.txtFilename.Name = "txtFilename";
this.txtFilename.Size = new System.Drawing.Size(, );
this.txtFilename.TabIndex = ;
this.txtFilename.Text = "test.avi";
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.label1.Location = new System.Drawing.Point(, );
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(, );
this.label1.TabIndex = ;
this.label1.Text = "文件名:";
//
// btnStart
//
this.btnStart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnStart.Location = new System.Drawing.Point(, );
this.btnStart.Name = "btnStart";
this.btnStart.Size = new System.Drawing.Size(, );
this.btnStart.TabIndex = ;
this.btnStart.Text = "开始";
this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
//
// btnStop
//
this.btnStop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnStop.Enabled = false;
this.btnStop.Location = new System.Drawing.Point(, );
this.btnStop.Name = "btnStop";
this.btnStop.Size = new System.Drawing.Size(, );
this.btnStop.TabIndex = ;
this.btnStop.Text = "停止";
this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
//
// btnExit
//
this.btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnExit.Location = new System.Drawing.Point(, );
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(, );
this.btnExit.TabIndex = ;
this.btnExit.Text = "退出";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// mainMenu
//
this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.mnuDevices,
this.menuItem7});
//
// menuItem1
//
this.menuItem1.Index = ;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuExit});
this.menuItem1.Text = "文件";
//
// mnuExit
//
this.mnuExit.Index = ;
this.mnuExit.Text = "E&xit";
this.mnuExit.Click += new System.EventHandler(this.mnuExit_Click);
//
// mnuDevices
//
this.mnuDevices.Index = ;
this.mnuDevices.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuVideoDevices,
this.mnuAudioDevices,
this.menuItem4,
this.mnuVideoCompressors,
this.mnuAudioCompressors});
this.mnuDevices.Text = "设备";
//
// mnuVideoDevices
//
this.mnuVideoDevices.Index = ;
this.mnuVideoDevices.Text = "视频设备";
//
// mnuAudioDevices
//
this.mnuAudioDevices.Index = ;
this.mnuAudioDevices.Text = "音频设备";
//
// menuItem4
//
this.menuItem4.Index = ;
this.menuItem4.Text = "-";
//
// mnuVideoCompressors
//
this.mnuVideoCompressors.Index = ;
this.mnuVideoCompressors.Text = "视频压缩";
//
// mnuAudioCompressors
//
this.mnuAudioCompressors.Index = ;
this.mnuAudioCompressors.Text = "音频压缩";
//
// menuItem7
//
this.menuItem7.Index = ;
this.menuItem7.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuVideoSources,
this.mnuFrameSizes,
this.mnuFrameRates,
this.mnuVideoCaps,
this.menuItem5,
this.mnuAudioSources,
this.mnuAudioChannels,
this.mnuAudioSamplingRate,
this.mnuAudioSampleSizes,
this.mnuAudioCaps,
this.menuItem3,
this.mnuChannel,
this.mnuInputType,
this.menuItem6,
this.mnuCompressionProps,
this.mnuPropertyPages,
this.menuItem8,
this.mnuPreview});
this.menuItem7.Text = "选项";
//
// mnuVideoSources
//
this.mnuVideoSources.Index = ;
this.mnuVideoSources.Text = "视频源";
//
// mnuFrameSizes
//
this.mnuFrameSizes.Index = ;
this.mnuFrameSizes.Text = "视频帧的大小";
//
// mnuFrameRates
//
this.mnuFrameRates.Index = ;
this.mnuFrameRates.Text = "视频的帧速率";
this.mnuFrameRates.Click += new System.EventHandler(this.mnuFrameRates_Click);
//
// mnuVideoCaps
//
this.mnuVideoCaps.Index = ;
this.mnuVideoCaps.Text = "视频特性";
this.mnuVideoCaps.Click += new System.EventHandler(this.mnuVideoCaps_Click);
//
// menuItem5
//
this.menuItem5.Index = ;
this.menuItem5.Text = "-";
//
// mnuAudioSources
//
this.mnuAudioSources.Index = ;
this.mnuAudioSources.Text = "音频源";
//
// mnuAudioChannels
//
this.mnuAudioChannels.Index = ;
this.mnuAudioChannels.Text = "音频通道";
//
// mnuAudioSamplingRate
//
this.mnuAudioSamplingRate.Index = ;
this.mnuAudioSamplingRate.Text = "音频采样率";
//
// mnuAudioSampleSizes
//
this.mnuAudioSampleSizes.Index = ;
this.mnuAudioSampleSizes.Text = "音频样本大小";
//
// mnuAudioCaps
//
this.mnuAudioCaps.Index = ;
this.mnuAudioCaps.Text = "音频功能...";
this.mnuAudioCaps.Click += new System.EventHandler(this.mnuAudioCaps_Click);
//
// menuItem3
//
this.menuItem3.Index = ;
this.menuItem3.Text = "-";
//
// mnuChannel
//
this.mnuChannel.Index = ;
this.mnuChannel.Text = "TV调谐器频道";
//
// mnuInputType
//
this.mnuInputType.Index = ;
this.mnuInputType.Text = "TV 调谐器输入类型";
this.mnuInputType.Click += new System.EventHandler(this.mnuInputType_Click);
//
// menuItem6
//
this.menuItem6.Index = ;
this.menuItem6.Text = "-";
//
// mnuCompressionProps
//
this.mnuCompressionProps.Index = ;
this.mnuCompressionProps.Text = "压缩道具...";
this.mnuCompressionProps.Click += new System.EventHandler(this.mnuCompressionProps_Click);
//
// mnuPropertyPages
//
this.mnuPropertyPages.Index = ;
this.mnuPropertyPages.Text = "属性页";
//
// menuItem8
//
this.menuItem8.Index = ;
this.menuItem8.Text = "-";
//
// mnuPreview
//
this.mnuPreview.Index = ;
this.mnuPreview.Text = "预览";
this.mnuPreview.Click += new System.EventHandler(this.mnuPreview_Click);
//
// panelVideo
//
this.panelVideo.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panelVideo.Location = new System.Drawing.Point(, );
this.panelVideo.Name = "panelVideo";
this.panelVideo.Size = new System.Drawing.Size(, );
this.panelVideo.TabIndex = ;
//
// btnCue
//
this.btnCue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnCue.Location = new System.Drawing.Point(, );
this.btnCue.Name = "btnCue";
this.btnCue.Size = new System.Drawing.Size(, );
this.btnCue.TabIndex = ;
this.btnCue.Text = "提示";
this.btnCue.Click += new System.EventHandler(this.btnCue_Click);
//
// txtDroppedFrames
//
this.txtDroppedFrames.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.txtDroppedFrames.CausesValidation = false;
this.txtDroppedFrames.Location = new System.Drawing.Point(, );
this.txtDroppedFrames.Name = "txtDroppedFrames";
this.txtDroppedFrames.ReadOnly = true;
this.txtDroppedFrames.Size = new System.Drawing.Size(, );
this.txtDroppedFrames.TabIndex = ;
this.txtDroppedFrames.TabStop = false;
this.txtDroppedFrames.Text = "";
//
// label2
//
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.label2.Location = new System.Drawing.Point(, );
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(, );
this.label2.TabIndex = ;
this.label2.Text = "丢帧";
//
// tmrTime1
//
this.tmrTime1.Interval = ;
this.tmrTime1.Tick += new System.EventHandler(this.tmrTime1_Tick);
//
// txtDuration
//
this.txtDuration.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.txtDuration.Location = new System.Drawing.Point(, );
this.txtDuration.Name = "txtDuration";
this.txtDuration.ReadOnly = true;
this.txtDuration.Size = new System.Drawing.Size(, );
this.txtDuration.TabIndex = ;
this.txtDuration.TabStop = false;
//
// label3
//
this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.label3.Location = new System.Drawing.Point(, );
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(, );
this.label3.TabIndex = ;
this.label3.Text = "持续时间";
//
// label4
//
this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.label4.Location = new System.Drawing.Point(, );
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(, );
this.label4.TabIndex = ;
this.label4.Text = "捕获帧";
//
// txtCapturedFrames
//
this.txtCapturedFrames.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.txtCapturedFrames.Location = new System.Drawing.Point(, );
this.txtCapturedFrames.Name = "txtCapturedFrames";
this.txtCapturedFrames.ReadOnly = true;
this.txtCapturedFrames.Size = new System.Drawing.Size(, );
this.txtCapturedFrames.TabIndex = ;
this.txtCapturedFrames.TabStop = false;
this.txtCapturedFrames.Text = "";
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.panelVideo);
this.groupBox1.Location = new System.Drawing.Point(, );
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(, );
this.groupBox1.TabIndex = ;
this.groupBox1.TabStop = false;
this.groupBox1.Resize += new System.EventHandler(this.groupBox1_Resize);
//
// txtPreSize
//
this.txtPreSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.txtPreSize.Location = new System.Drawing.Point(, );
this.txtPreSize.Name = "txtPreSize";
this.txtPreSize.Size = new System.Drawing.Size(, );
this.txtPreSize.TabIndex = ;
this.txtPreSize.Text = "";
this.txtPreSize.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// label5
//
this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.label5.Location = new System.Drawing.Point(, );
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(, );
this.label5.TabIndex = ;
this.label5.Text = "Pre-Size (Meg)";
this.label5.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// CaptureTest
//
this.AutoScaleBaseSize = new System.Drawing.Size(, );
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.label5);
this.Controls.Add(this.txtPreSize);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.txtCapturedFrames);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.txtDuration);
this.Controls.Add(this.label2);
this.Controls.Add(this.txtDroppedFrames);
this.Controls.Add(this.btnCue);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnStop);
this.Controls.Add(this.btnStart);
this.Controls.Add(this.txtFilename);
this.Controls.Add(this.label1);
this.Menu = this.mainMenu;
this.Name = "CaptureTest";
this.Text = "捕捉测试";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout(); }
#endregion }
}
DirectShowNet 使用摄像头录像+录音的更多相关文章
- android 随手记 摄像头录像
1 xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:androi ...
- C#调用AForge实现摄像头录像
1: 首先下载库文件>> 也可以去官网寻找>> 下载本教程全代码>> 输出为MP4需要用到ffmpeg相关的文件,我打包的库已经带了,去官网找的库可以在这个目录找到 ...
- WPF另类实现摄像头录像
WPF中使用第三方控件来直接进行录像的控件没有找到(aforgenet好像不维护了?WPFMediaKit好像只能实现摄像头拍照.收费的控件没有使用,不做评论.) 通过百度(感谢:https://ww ...
- cef开启摄像头和录音
参考资料:https://github.com/cztomczak/phpdesktop/wiki/Chrome-settings#command_line_switches CefSharp中文帮助 ...
- win8 metro 自己写摄像头录像项目
这是要求不适用CameraCaptureUI等使用系统自带的 camera UI界面.要求我们自己写调用摄像头摄像的方法,如今我把我的程序贴下: UI界面的程序: <Page x:Class= ...
- Android WebView 上传各种文件(包括拍照 录像 录音 文件 音乐 等,用到图片或拍照的,可以参考下)
我也是从网上扒下来的,经过多次实验,找到了个好用的.网上能搜到最多的也就是这个解决方案,我英文不好,也没仔细研究,但大多数都是出自这: http://stackoverflow.com/questio ...
- 怎么调用html5的摄像头,录音,视频?
调用image 即打开相册或调用系统相机: <input type="file" accept="image/*" capture="camer ...
- Google Chrome打开权限设置开关(摄像头,录音等)
在搜索框输入以下字符 chrome://flags/#unsafely-treat-insecure-origin-as-secure
- Android调用手机摄像头使用MediaRecorder录像并播放
最近在项目开发中需要调用系统的摄像头录像并播放. 在开发中遇到了两个问题,记录下: (1)开发过程中出现摄像头占用,启动失败,报错.但是我已经在onDestory()中关闭了资源. 报错原因:打开程序 ...
随机推荐
- objective-c(协议)
objective-c中不支持多重继承,其替代方案为Protocal(协议),下面给出一个基本实例: 定义一个协议 @protocol MyProtocal <NSObject> //协议 ...
- 程序员必须知道的几个Git代码托管平台
上一篇博客中2015继续任性——不会Git命令,照样玩转Git我们简单的介绍了在VS2013中使用Git,和GitHub客户端的使用.那么使用Git到底有什么好处呢?最为明显的是支持Git代码托管的平 ...
- Android 综合揭秘 —— 全面剖释 Service 服务
引言 Service 服务是 Android 系统最常用的四大部件之一,Android 支持 Service 服务的原因主要目的有两个,一是简化后台任务的实现,二是实现在同一台设备当中跨进程的远程信息 ...
- Fiddler实战深入研究(二)
Fiddler实战深入研究(二) 阅读目录 Fiddler不能捕获chrome的session的设置 理解数据包统计 请求重定向(AutoResponder) Composer选项卡 Filters选 ...
- Atitit.编译原理与概论
Atitit.编译原理与概论 编译原理 词法分析 Ast构建,语法分析 语意分析 6 数据结构 1. ▪ 记号 2. ▪ 语法树 3. ▪ 符号表 4. ▪ 常数表 5. ▪ 中间代码 1. ▪ 临 ...
- Atitti css3 新特性attilax总结
Atitti css3 新特性attilax总结 图片发光效果2 透明渐变效果2 文字描边2 背景拉伸2 CSS3 选择器(Selector)4 @Font-face 特性7 Word-wrap &a ...
- Atitit j2ee5 jee5 j2ee6 j2ee7 jee6 jee7 新特性
Atitit j2ee5 jee5 j2ee6 j2ee7 jee6 jee7 新特性 Keyword Java ee5 ,Java ee6,Java ee7 j2ee5 jee5 j2ee6 j2 ...
- iOS 和 Android 测试托管平台 FIR.im 的注册与常用功能
FIR.im 作为专业的 iOS 和 Android 测试包发布网站, 注册超简单,支持输入网址直接下载和二维码扫描下载.功能类似 TestFlight ,但又比它强大,支持游客访问密码,iOS 和 ...
- iOS开发——高级技术OC篇&运行时(Runtime)机制
运行时(Runtime)机制 本文将会以笔者个人的小小研究为例总结一下关于iOS开发中运行时的使用和常用方法的介绍,关于跟多运行时相关技术请查看笔者之前写的运行时高级用法及相关语法或者查看响应官方文档 ...
- Android 神兵利器—— Git 常用命令
总结的Android 工具类文章: Android 神兵利器-- Adb 常用命令 Android 神兵利器-- Git 常用命令 在项目研发时,经常使用Git,基本的命令有六个,通过下面的图片我们可 ...