Directx.capture

zhaozj2021-02-12  171

Directx.capture

.

Minimum Number of Audio Channels.

Maximum Number of Audio Channels.

Gran Guity of the Channels. For Example, Channels 2 THROUGH 4, IN Steps of 2.

Minimum Number of Bits Per Sample.

Maximum Number of Bits Per Sample.

Granularity of The Bits Per Sample. For Example, 8 Bits Per Sample Through 32 Bits Per Sample, IN Steps of 8.

Minimum Sample Frequency.

Maximum Sample Frequency.

Granular ified, 11025 Hz to 44100 Hz, in Steps of 11025 Hz.

Retrieve Capabilities of An Audio Device

....................... ..

Represents a Physical Connector Or Source on an Audio / Video Device.

Obtains the string representation of this installation.

Release unmanaged resources.

Release unmanaged resources.

The name of the source. Read-only.

IS this source enabled.

Constructor. This class cannot be create Directly.

Retrieve The Friendly Name of a connectortype.

Release unmanaged resources.

ENABLE SOURCES IT ITER SOLALLY POSIBLE TOEABLE, SET Enabled = false on all Other Audio Sources.

Use the capture class to capture audio and video to avi files.

This is the core class of the capture class introduce the capture class and how to use this library.

Basic usage

The Capture Class Only Requires a Video Device and / OR Audio Device To Begin Capturing. The

Class Provides Lists of the Installed Video and Audio Devices.

// Remember to add a reference to DirectX.Capture.dll using DirectX.Capture ... Capture capture = new Capture (Filters.VideoInputDevices [0], Filters.AudioInputDevices [0]); capture.Start (); ... Capture.stop (); this will Capture Video and Andio Using The First Video and Andio Devices Installed on The System. To Capture Video Only, Pass A Null As The Second Parameter of The Constructor.

THE CLASS INTILALIZED TO A Valid Temporary File In The Windows Temp Folder. To Capture To a Different File, SET THE

Property Before You Begin Capturing. Remember to Add Directx.capture.dll To your project References.

Setting Common Properties

The Example Below Shows How To Change Video and Audio Settings. Properties Such As

and

Allow you to programmatically adjust the capture. us

and

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; capture .Framesize = new size (640, 480); capture.audiosamplingrate = 44100; capture.audiosamplesize = 16; Capture.FileName = "c: /myvideo.avi"; capture.start (); ... capture.stop () ;

The example above also shows the use of video and audio compressors. In most cases you will want to use compressors. Uncompressed video can easily consume over a 1GB of disk space per minute. Whenever possible, set the

and

Properties As Early As Possible. Changing The Requires The Internal Filter Graph To Be Rebuilt Which often Causes Most of The Other Properties To Be Reset To Default Values.

Listing Devices

Use the

Collection to List Video Capture Devices Installed on The System.Fore (Filter F IN Filters.VideoInputDevices) {debug.writeline (f.name);}

THE

Class Also Provides Collections for Audio Capture Devices, Video Compressors and Audio Compressors.

Preview

Video Preview Is Controled with The

Property. Setting this Property TO A Visible Control Will Immediately Begin Preview. Set to Null To Stop The Preview.

// enable preview Capture.PreviewWindow = MyPanel; // disable preview Capture.PreviewWindow = NULL;

THE Control Used Must Have A Window Handle (HWND), Good Controls To Use Are The Panel or The Form Itself.

Retrieving or changing video / audio settings such as FrameRate, FrameSize, AudioSamplingRate, and AudioSampleSize will cause the preview window to flash. This is beacuse the preview must be temporarily stopped. Disable the preview if you need to access several properties at the same time.

Property Pages

Property Pages Exposed by The Devices and Compressors Are Available Through The

COLLECTION.

// Display the first property page capture.propertypages [0] .show ();

The property pages will often expose more settings than the Capture class does directly. Some examples are brightness, color space, audio balance and bass boost. The disadvantage to using the property pages is the user's choices can not be saved and later restored. The exception to This Is The Video and Audio Compressor Property Pages. Most Compressors Support The Saving and Restoring State, See The THE

Property for more information.

Changes made in the property page will be reflected immediately in the Capture class properties (eg Capture.FrameSize). However, the reverse is not always true. A change made directly to FrameSize, for example, may not be reflected in the associated property page Fortunately, The Filter Will Use Requested Framesize Even Though The Property Page Shows Otherwise.saving and resting settings

To save the user's choice of devices and strengths, save

And User it Later to recreate the filter object.

To Save a User's Choices from a Property Page USE

, ONLY The Audio and Video Compressor Property Pages Support this.

............... ..

// Disable preview capture.PreviewWindow = null; // Save settings string videoDevice = capture.VideoDevice.MonikerString; string audioDevice = capture.AudioDevice.MonikerString; string videoCompressor = capture.VideoCompressor.MonikerString; string audioCompressor = capture.AudioCompressor.MonikerString; double frameRate = capture.FrameRate; Size frameSize = capture.FrameSize; short audioChannels = capture.AudioChannels; short audioSampleSize = capture.AudioSampleSize; int audioSamplingRate = capture.AudioSamplingRate; ArrayList pages = new ArrayList (); foreach (PropertyPage p in capture. PropertyPages) {if (p.SupportsPersisting) pages.Add (p.State);} // Restore settings Capture capture = new Capture (new Filter (videoDevice), new Filter (audioDevice)); capture.VideoCompressor = new Filter (videoCompressor Capture.Audiocompressor = New filter (audiocompressor); capture.framerate = framerate; capture.framesize = framesize; capture.audiochannels = audiochannels; Capture.Audios ampleSize = audioSampleSize; capture.AudioSamplingRate = audioSamplingRate; foreach (PropertyPage p in capture.PropertyPages) {if (p.SupportsPersisting) {p.State = (byte []) pages [0] pages.RemoveAt (0);}} / / Enable preview Capture.PreviewWindow = MyPanel; TV TUNER

To Access The TV Tuner, Use the THE

Property. If The Device Does Not Have A TV Tuner, This Property Will Be Null. See

,

and

For more information.

// Change to channel 5 Capture.Tuner.Channel = 5;

Troubleshooting

This class library uses COM Interop to access the full capabilities of DirectShow, so if there is another application that can successfully use a hardware device then it should be possible to modify this class library to use the device.Try the

Amcap Sample From The DirectX SDK (DX9 / Samples / C / DirectShow / Bin / Amcap.exe) OR

Virtual vcr from http://www.digtv.ws

Credits

THIS CLASS LIBRARY WOULD NOT BE POSIBLE WITHOUT THE DSHOWNET Project by NetMaster: http://www.codeproject.com/UserItems/directShownet.asp

Documentation is generated by ndoc available at

Http://ndoc.sourceforge.net

FEEDBACK

Feel Free To Send Comments and Questions to Me At Mportobello@hotmail.com. If The Topic May Be of Interest To Others, Post Your Questions on The www.codeproject.com.

Create A New Capture Object. VideoDevice And Audiode Wish To Capture Both Audio and Video. However at Least One Must Be a Valid Device. Use T

Class to list available devices.

Dispose of resources.

PREPARE for Capturing. Use this method...............

This Will Create / OverWrite a Zero Byte File with the name set in the filename.

This Will Disable Preview. Preview Will Resume ONCE CAPTURE BEGINS. This Problem Can Be fixediff can be used.

This method is optional. If cue () is not called, start () Will Call It Bealog Capturing. This Method Cannot Be Called While Capturing.

Begin Capturing.

Stop The Current Capture Capture. If The 'is no current capture, this method will succeed.

.

Create a new filter graph and add filters (devices, compressors, misc), but leave the filters unconnected. Call renderGraph () to connect the filters.Connects the filters of a previously created graph (created by createGraph ()). Once rendered the ................... ..

Setup and start the preview window if the user has review it (by setting previewWindow).

Disconnect and remove all filters except the device and compressor filters. This is the opposite of renderGraph (). Soem properties such as FrameRate can only be set when the device output pins are not connected.

Removes all filters downstream from a filter from the graph. This is called only by derenderGraph () to remove everything from the graph except the devices and compressors. The parameter "removeFirstFilter" is used to keep a compressor (that should be immediately downstream of the Device) if one is begin used.

Completely Tear Down A Filter Graph and Release All Associated Resources.

Resize the Preview When the PreviewWindow Is Resize

Get a valid temporary filename (with path). We all't using path.getTempFileName () Because IT Creates A 0-byte file

Retrieves the value of one member of the IAMStreamConfig format block. Helper function for several properties that expose video / audio settings from IAMStreamConfig.GetFormat (). IAMStreamConfig.GetFormat () returns a AMMediaType struct. AMMediaType.formatPtr points to a format block structure. This Format Block Structure May Be One of Several Types, The Type Being Determined by ammediatype.formattype.

Set the value of one member of the IAMStreamConfig format block. Helper function for several properties that expose video / audio settings from IAMStreamConfig.GetFormat (). IAMStreamConfig.GetFormat () returns a AMMediaType struct. AMMediaType.formatPtr points to a format block structure. This Format Block Structure May Be One of Several Types, The Type Being Determined by ammediatype.formattype.assert That The Class is in a stopped state.

Is The Class Currently Capturing. Read-ONLY.

Has the class been cued to begin capturing. Read-Only.

Is the class currently stopped. Read-Only.

Name of File to Capture To. Initially Set to a Valid Temporary File.

If the file does not exist, it will be created. If it does exist, it will be overwritten. An overwritten file will not be shortened if the captured data is smaller than the original file. The file will be valid, it will just contain Extra, Unused, Data After The Audio / Video Data.

.

This Property Cannot Be Chang Cue Capturing Or Cued.

The Control That Will Host The Preview WINDOW.

Setting this property will begin video preview immediately. Set this property after setting all other properties to avoid unnecessary changes to the internal filter graph (some properties like FrameSize require the internal filter graph to be stopped and disconnected before the property can be retrieved or set) .

To Stop Video Preview, SET this property to null.

The Capabilities of The Video Device.

IT May Be Required to Cue The Capture (See

Before All Capabilities Are Correctly Reported. If You Have Such A Desert, The Developer Would Be Interested to Hear from You.

The information contained in this property is retrieved and cached the first time this property is accessed. Future calls to this property use the cached results. This was done for performance.However, this means

you may get different results depending on when you access this property first. If you are experiencing problems, try accessing the property immediately after creating the Capture class or immediately after setting the video and audio compressors. Also, inform the developer.

The Capabilities of The Audio Device.

IT May Be Required to Cue The Capture (See

Before All Capabilities Are Correctly Reported. If You Have Such A Desert, The Developer Would Be Interested to Hear from You.

.............................................................

However, this means

you may get different results depending on when you access this property first. If you are experiencing problems, try accessing the property immediately after creating the Capture class or immediately after setting the video and audio compressors. Also, inform the developer.

THE VIDEO CAPTURE DEVICE FILTER. Read-Only. To Use A Different Device, Dispose of The Current Capture Instance and Create A New Instance With the desired device.

The Audio Capture Device Filter. Read-Only. To Use A Different Device, Dispose of The Current Capture Instance and Create A New Instance with the desired device.

The video compression filter. When this property is changed the internal filter graph is rebuilt. This means that some properties will be reset. Set this property as early as possible to avoid losing changes. This property can not be changed while capturing.The audio compression filter .

When this property is changed the internal filter graph is rebuilt. This means that some properties will be reset. Set this property as early as possible to avoid losing changes. This property can not be changed while capturing.

Use Capture.videosources To list Available Sources. Set to Null To Disable All Sources.

Use Capture.Audiosources To list Available Sources. Set to Null To Disable All Sources.

Collection of Available Video Sources / Physical Connectors on The Current Video Device.

IN MOST CASES, IF The Device Has Only One Source, This Collection Will Be Empty.

.............................................................

However, this means

you may get different results depending on when you access this property first. If you are experiencing problems, try accessing the property immediately after creating the Capture class or immediately after setting the video and audio compressors. Also, inform the developer.

Collection of Available Audio Sources / Physical Connectors on The Current Audio Device.

In most cases, if the device has only one source, this collection will be empty. For audio there are 2 different methods for enumerating audio sources an audio crossbar (usually TV tuners?) Or an audio mixer (usually sound cards?). This class will first look for an audio crossbar. If no sources or only one source is available on the crossbar, this class will then look for an audio mixer. This class does not support both methods.The information contained in this property is retrieved and cached ........................

However, this means

you may get different results depending on when you access this property first. If you are experiencing problems, try accessing the property immediately after creating the Capture class or immediately after setting the video and audio compressors. Also, inform the developer.

Available Property Pages.

................................

.............................................................

However, this means

you may get different results depending on when you access this property first. If you are experiencing problems, try accessing the property immediately after creating the Capture class or immediately after setting the video and audio compressors. Also, inform the developer.

The TV Tuner or Null If The Current Video Device Does Not Have A TV Tuner.

Gets and sets the frame rate buy to capture video.

Common frame rates:. 24 fps for film, 25 for PAL, 29.997 for NTSC Not all NTSC capture cards can capture at exactly 29.997 fps Not all frame rates are supported When changing the frame rate, the closest supported frame rate will be used.. .Not All Devices Support Getting / Setting This Property. If this property is not supported, Accessing It Will throw and exception.

This property can not be changed while capturing. Changing this property while preview is enabled will cause some fickering while the internal filter graph is partially rebuilt. Changing this property while cued will cancel the cue. Call Cue () again to re-cue the capture.

Gets and sets the frame size used to capture video.

To change the frame size, assign a new size object to this property

Capture.size = new size (w, h); Rather Than Modifying The size in place (Capture.Size.width = W;). Not All Frame Rates AresuTed.

NOT All Devices Support getting / setting this protection. If this property is not supported, Accessing It Will throw and exception.

This property can not be changed while capturing. Changing this property while preview is enabled will cause some fickering while the internal filter graph is partially rebuilt. Changing this property while cued will cancel the cue. Call Cue () again to re-cue the capture.

Get or set the number of channels in the Waveform-Audio Data.

Monaural Data Uses One Channel and Stereo Data Uses Two Channels.

NOT All Devices Support getting / setting this protection. If this property is not supported, Accessing It Will throw and exception.

This property can not be changed while capturing. Changing this property while preview is enabled will cause some fickering while the internal filter graph is partially rebuilt. Changing this property while cued will cancel the cue. Call Cue () again to re-cue the capture. Get or set the number of audio samples taken per second.

Common Sampling Rates Are 8.0 kHz, 11.025 kHz, 22.05 kHz, AND 44.1 kHz. Not All Sampling Rates AresuTed.

NOT All Devices Support getting / setting this protection. If this property is not supported, Accessing It Will throw and exception.

This property can not be changed while capturing. Changing this property while preview is enabled will cause some fickering while the internal filter graph is partially rebuilt. Changing this property while cued will cancel the cue. Call Cue () again to re-cue the capture.

Get or set the number of bits recorded per sample.

CommON Sample Sizes Are 8 Bit and 16 bit. Not all Samples Sizes Are Supported.

NOT All Devices Support getting / setting this protection. If this property is not supported, Accessing It Will throw and exception.

This property can not be changed while capturing. Changing this property while preview is enabled will cause some fickering while the internal filter graph is partially rebuilt. Changing this property while cued will cancel the cue. Call Cue () again to re-cue the capture.

Fired When a Capture Is Completed (Manually or Automatical).

Possible States of The Intert Filter Graph

REPRESENTS A Physical Connector or Source on an audio / video device. This class is used on filters That Support The Iamcrossbar Interface Such as TV Tuners.

Constructor. This class cannot be create Directly.

Retrieve The Friendly Name of a connectortype.

Release unmanaged resources.enabled or disable this source.

Exception thrown when the device cannot be rendered or start.

Property Pages for a DirectShow Filter (E.G. Hardware Device). The Property Pages Do Not Support PersiSting Their Settings.

A base class for representing proteness pages exposed by filters.

Name of Property Page. This Name May Not Be Unique

Does this Property Page Support Saving and Loading The User's Choices.

Constructor

SHOW The Property Page. Some Property Pages Cannot Be Displayed While Previewing and / OR Capturing. This Method Will Block Until The Property Page is close by the user.

Release unmanaged resources

............................. ...CRIPLITRATORSTICM. THE.

After showing this property page, read and store the value of this property. At a later time, the user's choices can be reloaded by setting this property with the value stored earlier. Note that some property pages, after setting this property, will not reflect The New State. However, The Filter Will Use The New Settings.

When reading this property, copy the entire array at once then manipulate your local copy (e..g byte [] myState = propertyPage.State). When setting this property set the entire array at once (e.g. propertyPage = myState).

NOT All Property Pages Support saving / loading state. Check the

Property to Determine IF this Property Page Supports it.

COM ISPECIFYPROPERTYPAGES INTERFACE

Constructor

Show The Property Page. Some Property Pages Cannot Be Displayed While Previewing and / OR Capturing.

Release unmanaged resources

Represents a DirectShow Filter (E.G. Video Capture Device, Compression Codec).

TO Save a Chosen Filer for Later Recall Save The Monikerstring Property on The Filter: String SavedMonikerstring = Myfilter.monikerstring;

To recall the filter create a new filter class and pass the string to the constructor:

Filter MySelectedFilter = New Filter (SavedMonikerstring);

Human-readable name of the filter

Unique string referencing this filter. This string can be used to recreate this filter.

Create a new filter from its moniker string.

Create a new filter from its moniker

Retrieve the a moniker's display name (i.e. it's unique string)

Retrieve the human-readable name of the filter

Get A Moniker's Human-Readable Name Based on a moniker string.

This method gets a UCOMIMoniker object HACK:... The only way to create a UCOMIMoniker from a moniker string is to use UCOMIMoniker.ParseDisplayName () So I need ANY UCOMIMoniker object so that I can call ParseDisplayName () Does anyone have a better solution This assumes there is at Least ONE Video Compressor Filter Installed on The System.

Compares The Current Instance with Another Object of The Same Type.

A Collection of Filter Objects (DirectShow Filters). This is buy by the

Class to Provide Lists of Capture Devices And Compression Filters. This class cannot be create Directly.

Populate The Collection with a list of filters from a particular category.

Populate the innerlist with a list of filters from a particular category

Get the filter at the specified index.

Provides Collections of Devices and Compression Codecs Installed on The System.

Devices and Compression Codecs Are IMplement in DirectShow As Filters, See The

Class for more information. To list the available video devices:

Filters filters = new filters (); Foreach (Filter F IN Filters.VideoInputDevices) {debug.writeline (f.name);} Collection of Available Video Capture Devices.

Collection of Available Audio Capture Devices.

Collection of available video compressors.

Collection of available audio compressors.

A collection of available PropertyPages in a DirectShow filter graph. It is up to the driver manufacturer to implement a property pages on their drivers. The list of supported property pages will vary from driver to driver.

Initialize Collection with no property pages.

Initialize Collection with Property Pages from existing graph.

Destructor. Release unmanaged resources.

Empty the collection.

Release unmanaged resources

Populate The Collection By Looking for Commonly Implement Property Pages.

For the ISPECIFICPROPERTYPAGE ISPECIFICPAGETY PAGE.

Get the filter at the specified index.

A Collection of Sources on an audio or video device. This is buy by the

class to provide a list of available sources on the currently selected audio and video devices. This class can not be created directly. This class assumes there is only 1 video and 1 audio crossbar and all input pins route to a single output pin on each crossbar.

Initialize Collection with no sources.

Initialize Collection with Sources from graph.

Destructor. Release unmanaged resources.

Empty the collection.

Release unmanaged resources.

Populate the collection from a filter graph.

Retrieve A List of Crossbar Filters in The Graph. Most Hardware Devices Should Have A Maximum of 2 Crossbars, One for Video and another for Audio.

Populate the internal InnerList with sources / physical connectors found on the crossbars. Each instance of this class is limited to video only or audio only sources (specified by the isVideoDevice parameter on the constructor) so we check each source before adding it to the list. Get the Source At the specified index.

Gets or sets the source / physical connection. This is marked.

Specify The Frequency of The TV Tuner.

Cable Frequency

Antenna FREQUENCY

Control and query a hardware TV tuner.

Initialize this Object with a DirectShow Tuner

Get or set the TV tuner channel.

Get or set the tuner frequency (Cable or Antenna).

INDICAT WHETHER A Signal IS Present On The Current Channel. If The Signal Streg Cannot Be determined, a NotSupportedException is thrown.

The property page to configure a Video for Windows compliant compression codec. Most compressors support this property page rather than a DirectShow property page. Also, most compressors do not support the IAMVideoCompression interface so this property page is the only method to configure a compressor.

Video for Windows Compression Dialog Interface

Constructor

Show The Property Page. Some Property Pages Cannot Be Displayed While Previewing and / OR Capturing.

Get or set the state of the property page. This is used to save and restore the user's choices without redisplaying the property page. This property will be null if unable to retrieve the property page's state.

After showing this property page, read and store the value of this property. At a later time, the user's choices can be reloaded by setting this property with the value stored earlier. Note that some property pages, after setting this property, will not reflect The New State. However, The Filter Will Use The New Settings.capabilities of The Video Device Such as min / max frame size and frame rate.

Native size of the incoming video signal. This is the largest signal the filter.. Read-only.

Minimum supported frame size. Read-only.

Maximum supported frame size. Read-only.

Granularity of the output width. This value specifies the increments That Are Valid Between Minframesize and maxframesize. Read-Only.

.....................................................................................

Minimum supported frame rate. Read-only.

Maximum supported frame rate. Read-only.

Retrieve Capabilities of a Video Device

转载请注明原文地址:https://www.9cbs.com/read-7686.html

New Post(0)