以下来自:[url]http://www.codeproject.com/cs/media/directxcapture.asp[/url]
我简单翻译下,帮助以下英文不太好的朋友
[url]http://files.cnblogs.com/mgod/DirectXCapture_src.zip[/url]
[url]http://files.cnblogs.com/mgod/DirectXCapture_demo.zip[/url]
该类库的主要特点:
- 可以列举和选择所有音视频的硬件设备
- 可以设置音频和视频相关属性,例如帧速率,大小,采样频率等
- 支持音视频压缩编码
- 支持视频预览
- 支持电视接口
- 支持混音
- 可以显示硬件驱动的属性
- 包含了标准的MSDN式的帮助文档
DirectX.Capture.dll和
DShowNET.dll
,到你的项目里。例程1:
using DirectX.Capture
// 此时使用默认的音视频的首选设备进行捕获
Capture capture = new Capture( Filters.VideoInputDevices[0],
Filters.AudioInputDevices[0] );
// Start capturing
capture.Start();
// Stop capturing
capture.Stop();
例程2:
Capture capture = new Capture( Filters.VideoInputDevices[0],
Filters.AudioInputDevices[1] );
//这里可以设置使用哪种压缩编码方式
capture.VideoCompressor = Filters.VideoCompressors[0];
capture.AudioCompressor = Filters.AudioCompressors[0];
capture.FrameRate = 29.997; // NTSC
capture.FrameSize = new Size( 640, 480 ); // 640x480
capture.AudioSamplingRate = 44100; // 44.1 kHz
capture.AudioSampleSize = 16; // 16-bit
capture.AudioChannels = 1; // Mono
capture.Filename = "C:MyVideo.avi";
capture.Start();
...
capture.Stop();
例程3:关于预览
// Start preview
capture.PreviewWindow = myPanelControl;
// Stop preview
capture.PreviewWindow = null;
该类库每次都会从设备的驱动程序中更新最新支持的属性,因此你完全没有必要理会,设备到底是不是支持特定属性,只要从支持的属性中选择即可
当然该类库,也有一些问题,比如说关于电视卡的支持并不是很好,但是如果你不用的话,仅仅操作普通的视频和音频设备,该类库还是非常好用的,
---------------------原文如下------------------------------
Introduction
- List and select hardware devices
- Access to common audio and video settings (e.g. frame rate, size)
- Support audio and video compression codecs
- Support video preview
- Support TV tuners
- Support crossbars and audio mixers
- Retrieve device capabilities
- Show property pages exposed by drivers
- MSDN-style documentation included
Using the Code
Capture
class is the core of this library. Here is a simple example:// Remember to add a reference to DirectX.Capture.dll
using DirectX.Capture
// Capture using the first video
// and audio devices available
Capture capture = new Capture( Filters.VideoInputDevices[0],
Filters.AudioInputDevices[0] );
// Start capturing
capture.Start();
// Stop capturing
capture.Stop();
null
as the second parameter to the constructor. Capture.Filename
property before you begin capturing. A Second Example
Capture.FrameRate
and Capture.AudioSampleSize
allow you to programmatically adjust the capture. Use Capture.VideoCaps
and Capture.AudioCaps
to determine valid values for these properties.Capture capture = new Capture( Filters.VideoInputDevices[0],
Filters.AudioInputDevices[1] );
capture.VideoCompressor = Filters.VideoCompressors[0];
capture.AudioCompressor = Filters.AudioCompressors[0];
capture.FrameRate = 29.997; // NTSC
capture.FrameSize = new Size( 640, 480 ); // 640x480
capture.AudioSamplingRate = 44100; // 44.1 kHz
capture.AudioSampleSize = 16; // 16-bit
capture.AudioChannels = 1; // Mono
capture.Filename = "C:\MyVideo.avi";
capture.Start();
...
capture.Stop();
Capture.VideoCompressor
and Capture.AudioCompressor
properties as early as possible. Changing them requires the internal filter graph to be rebuilt which often causes most of the other properties to be reset to default values. Behind the Scenes
Capture
library uses DShowNET for the interop layer with only a few extensions. This is the DShowNET.dll mentioned earlier.Capture
class library. The center of any DirectShow app is the filter graph and the filter graph manager. For a good overview, see The Filter Graph and Its Components from the MSDN. The Least Work Possible
// Start preview
capture.PreviewWindow = myPanelControl;
// Stop preview
capture.PreviewWindow = null;
PreviewWindow
property is set. Performance Tips
Capture
class are retrieved directly from the underlying DirectShow COM components. If you need to refer to the property repeatedly in a block of code, take a copy of the value and use your copy.// AudioSampleSize is retrieved from DirectShow each iteration
for ( int c = 0; c < 32; c++ )
{
if ( c == capture.AudioSampleSize )
MessageBox.Show( "Found!" );
}
// A faster solution
int x = capture.AudioSampleSize;
for ( int c = 0; c < 32; c++ )
{
if ( c == x )
MessageBox.Show( "Found!" );
}
Credits
Troubleshooting
User Enhancements
- Frequency Overrides for the Tuner class by fdaupias
- Radio Tuning for the Tuner class by dauboro