本文整理汇总了C#中ISampleGrabber.SetMediaType方法的典型用法代码示例。如果您正苦于以下问题:C# ISampleGrabber.SetMediaType方法的具体用法?C# ISampleGrabber.SetMediaType怎么用?C# ISampleGrabber.SetMediaType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISampleGrabber
的用法示例。
在下文中一共展示了ISampleGrabber.SetMediaType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MainForm
public MainForm()
{
InitializeComponent();
graphbuilder = (IGraphBuilder)new FilterGraph();
samplegrabber = (ISampleGrabber)new SampleGrabber();
graphbuilder.AddFilter((IBaseFilter)samplegrabber, "samplegrabber");
mt = new AMMediaType();
mt.majorType = MediaType.Video;
mt.subType = MediaSubType.RGB24;
mt.formatType = FormatType.VideoInfo;
samplegrabber.SetMediaType(mt);
PrintSeconds();
}
示例2: ConfigSampleGrabber
private static void ConfigSampleGrabber(ISampleGrabber sb)
{
// set the media type
var media = new AMMediaType
{
majorType = MediaType.Video,
subType = MediaSubType.RGB24,
formatType = FormatType.VideoInfo
};
// that's the call to the ISampleGrabber interface
sb.SetMediaType(media);
DsUtils.FreeAMMediaType(media);
}
示例3: CaptureForm
public CaptureForm()
{
InitializeComponent();
graph_builder = (IGraphBuilder)new FilterGraph();
media_control = (IMediaControl)graph_builder;
events = (IMediaEventEx)graph_builder;
grabber = (ISampleGrabber)new SampleGrabber();
AMMediaType media_type = new AMMediaType();
media_type.majorType = MediaType.Video;
media_type.subType = MediaSubType.RGB24;
grabber.SetMediaType( media_type );
grabber.SetCallback( this, 1 );
cbDevices.Items.AddRange( GetDevices( FilterCategory.VideoInputDevice ) );
}
示例4: createGraph
// --------------------- Private Methods -----------------------
/// <summary>
/// Create a new filter graph and add filters (devices, compressors,
/// misc), but leave the filters unconnected. Call renderGraph()
/// to connect the filters.
/// </summary>
protected void createGraph()
{
Guid cat;
Guid med;
int hr;
Type comType = null;
object comObj = null;
// Ensure required properties are set
if ( videoDevice == null && audioDevice == null )
throw new ArgumentException( "The video and/or audio device have not been set. Please set one or both to valid capture devices.\n" );
// Skip if we are already created
if ( (int)graphState < (int)GraphState.Created )
{
// Garbage collect, ensure that previous filters are released
GC.Collect();
// Make a new filter graph
graphBuilder = (IGraphBuilder) Activator.CreateInstance( Type.GetTypeFromCLSID( Clsid.FilterGraph, true ) );
// Get the Capture Graph Builder
Guid clsid = Clsid.CaptureGraphBuilder2;
Guid riid = typeof(ICaptureGraphBuilder2).GUID;
captureGraphBuilder = (ICaptureGraphBuilder2) DsBugWO.CreateDsInstance( ref clsid, ref riid );
// sampGrabber, ISampleGrabber to capture frames
comType=Type.GetTypeFromCLSID( Clsid.SampleGrabber, true );
if(comType==null)
throw new NotImplementedException (@"DirectShow SampleGrabber not installed/registered");
comObj=Activator.CreateInstance( comType );
sampGrabber = (ISampleGrabber) comObj; comObj = null;
// Link the CaptureGraphBuilder to the filter graph
hr = captureGraphBuilder.SetFiltergraph( graphBuilder );
//if( hr < 0 ) Marshal.ThrowExceptionForHR( hr );
// Begin set up of SampGrabber <<<<<<----------------------------------------------------
AMMediaType media = new AMMediaType();
media.majorType= MediaType.Video;
media.subType = MediaSubType.RGB24;
media.formatType = FormatType.VideoInfo;
hr = sampGrabber.SetMediaType( media );
//if( hr<0 ) Marshal.ThrowExceptionForHR( hr );
// Finish set up of SampGrabber <<<<<<----------------------------------------------------
// Add the graph to the Running Object Table so it can be
// viewed with GraphEdit
#if DEBUG
DsROT.AddGraphToRot( graphBuilder, out rotCookie );
#endif
// Get the video device and add it to the filter graph
if ( VideoDevice != null )
{
videoDeviceFilter = (IBaseFilter) Marshal.BindToMoniker( VideoDevice.MonikerString );
hr = graphBuilder.AddFilter( videoDeviceFilter, "Video Capture Device" );
//if( hr < 0 ) Marshal.ThrowExceptionForHR( hr );
// Add SampGrabber Filter <<<<<<----------------------------------------------------
mediaEvt = (IMediaEventEx) graphBuilder;
baseGrabFlt = (IBaseFilter) sampGrabber;
hr = graphBuilder.AddFilter( baseGrabFlt, "DS.NET Grabber" );
//if( hr < 0 ) Marshal.ThrowExceptionForHR( hr );
}
// Get the audio device and add it to the filter graph
if ( AudioDevice != null )
{
audioDeviceFilter = (IBaseFilter) Marshal.BindToMoniker( AudioDevice.MonikerString );
hr = graphBuilder.AddFilter( audioDeviceFilter, "Audio Capture Device" );
//if( hr < 0 ) Marshal.ThrowExceptionForHR( hr );
}
// Get the video compressor and add it to the filter graph
if ( VideoCompressor != null )
{
videoCompressorFilter = (IBaseFilter) Marshal.BindToMoniker( VideoCompressor.MonikerString );
hr = graphBuilder.AddFilter( videoCompressorFilter, "Video Compressor" );
//if( hr < 0 ) Marshal.ThrowExceptionForHR( hr );
}
// Get the audio compressor and add it to the filter graph
if ( AudioCompressor != null )
{
audioCompressorFilter = (IBaseFilter) Marshal.BindToMoniker( AudioCompressor.MonikerString );
hr = graphBuilder.AddFilter( audioCompressorFilter, "Audio Compressor" );
//if( hr < 0 ) Marshal.ThrowExceptionForHR( hr );
}
// Retrieve the stream control interface for the video device
// FindInterface will also add any required filters
//.........这里部分代码省略.........
示例5: CaptureVideo
private void CaptureVideo(IntPtr ctlHandle)
{
int hr = 0;
IBaseFilter sourceFilter = null;
try
{
// Get DirectShow interfaces
GetInterfaces(ctlHandle);
// Attach the filter graph to the capture graph
hr = this.captureGraphBuilder.SetFiltergraph(this.graphBuilder);
//captureGraphBuilder.RenderStream(PinCategory.Preview,MediaType.Video,
DsError.ThrowExceptionForHR(hr);
// Use the system device enumerator and class enumerator to find
// a video capture/preview device, such as a desktop USB video camera.
sourceFilter = FindCaptureDevice();
if (sourceFilter == null)
{
log("Couldn't find a video input device.");
return;
}
// Add Capture filter to our graph.
hr = this.graphBuilder.AddFilter(sourceFilter, "Video Capture");
DsError.ThrowExceptionForHR(hr);
this.samplegrabber = (ISampleGrabber)new SampleGrabber();
AMMediaType mt = new AMMediaType();
mt.majorType = MediaType.Video;
mt.subType = MediaSubType.RGB24;
mt.formatType = FormatType.VideoInfo;
samplegrabber.SetMediaType(mt);
//samplegrabber.
hr = this.graphBuilder.AddFilter((IBaseFilter)samplegrabber, "samplegrabber");
DsError.ThrowExceptionForHR(hr);
IBaseFilter nullRenderer = (IBaseFilter)new NullRenderer();
hr = graphBuilder.AddFilter(nullRenderer, "Null Renderer");
// Render the preview pin on the video capture filter
// Use this instead of this.graphBuilder.RenderFile
hr = this.captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, sourceFilter, (IBaseFilter)samplegrabber, nullRenderer);
//DsError.ThrowExceptionForHR(hr);
if (hr != 0) log(DsError.GetErrorText(hr));
// Now that the filter has been added to the graph and we have
// rendered its stream, we can release this reference to the filter.
Marshal.ReleaseComObject(sourceFilter);
// Set video window style and position
//SetupVideoWindow(ctlHandle);
// Add our graph to the running object table, which will allow
// the GraphEdit application to "spy" on our graph
rot = new DsROTEntry(this.graphBuilder);
// Start previewing video data
hr = this.mediaControl.Run();
DsError.ThrowExceptionForHR(hr);
// Remember current state
this.currentState = PlayState.Running;
samplegrabber.SetBufferSamples(true);
samplegrabber.SetOneShot(false);
}
catch
{
MessageBox.Show("CaptureVideo(ctlHandle) suffered a fatal error.");
}
}
示例6: ConfigureSampleGrabber
private void ConfigureSampleGrabber(ISampleGrabber sampGrabber)
{
AMMediaType media;
int hr;
// Set the media type to Video/YUY2
media = new AMMediaType();
media.majorType = MediaType.Video;
media.subType = MediaSubType.YUY2;
media.formatType = FormatType.VideoInfo;
hr = sampGrabber.SetMediaType(media);
DsError.ThrowExceptionForHR(hr);
DsUtils.FreeAMMediaType(media);
media = null;
hr = sampGrabber.SetCallback(this, 1);
DsError.ThrowExceptionForHR(hr);
}
示例7: ConfigureSampleGrabber
/// <summary> Set the options on the sample grabber </summary>
private void ConfigureSampleGrabber(ISampleGrabber sampGrabber)
{
AMMediaType media;
int hr;
// Set the media type to Video/RBG24
media = new AMMediaType();
media.majorType = MediaType.Video;
media.subType = MediaSubType.RGB24;
media.formatType = FormatType.VideoInfo;
hr = sampGrabber.SetMediaType(media);
DsError.ThrowExceptionForHR(hr);
DsUtils.FreeAMMediaType(media);
media = null;
// Choose to call BufferCB instead of SampleCB
hr = sampGrabber.SetCallback(this, 1);
DsError.ThrowExceptionForHR(hr);
}
示例8: ConfigureSampleGrabber
private void ConfigureSampleGrabber(ISampleGrabber sampGrabber)
{
AMMediaType media = new AMMediaType
{
majorType = MediaType.Video,
subType = MediaSubType.RGB24,
formatType = FormatType.VideoInfo
};
// Set the media type to Video/RBG24
int hr = sampGrabber.SetMediaType(media);
DsError.ThrowExceptionForHR(hr);
DsUtils.FreeAMMediaType(media);
// Configure the samplegrabber
hr = sampGrabber.SetCallback(this, 1);
DsError.ThrowExceptionForHR(hr);
}
示例9: SetupSampleGrabber
private void SetupSampleGrabber(ISampleGrabber sampleGrabber)
{
var mediaType = new DirectShowLib.AMMediaType
{
majorType = MediaType.Video,
subType = MediaSubType.RGB24,
formatType = FormatType.VideoInfo
};
int hr = sampleGrabber.SetMediaType(mediaType);
DsUtils.FreeAMMediaType(mediaType);
DsError.ThrowExceptionForHR(hr);
hr = sampleGrabber.SetCallback(this, 0);
DsError.ThrowExceptionForHR(hr);
}
示例10: RunWorker
void RunWorker()
{
try
{
graph = Activator.CreateInstance(Type.GetTypeFromCLSID(FilterGraph)) as IGraphBuilder;
sourceObject = FilterInfo.CreateFilter(deviceMoniker);
grabber = Activator.CreateInstance(Type.GetTypeFromCLSID(SampleGrabber)) as ISampleGrabber;
grabberObject = grabber as IBaseFilter;
graph.AddFilter(sourceObject, "source");
graph.AddFilter(grabberObject, "grabber");
using (AMMediaType mediaType = new AMMediaType())
{
mediaType.MajorType = MediaTypes.Video;
mediaType.SubType = MediaSubTypes.RGB32;
grabber.SetMediaType(mediaType);
if (graph.Connect(sourceObject.GetPin(PinDirection.Output, 0), grabberObject.GetPin(PinDirection.Input, 0)) >= 0)
{
if (grabber.GetConnectedMediaType(mediaType) == 0)
{
VideoInfoHeader header = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.FormatPtr, typeof(VideoInfoHeader));
capGrabber.Width = header.BmiHeader.Width;
capGrabber.Height = header.BmiHeader.Height;
}
}
graph.Render(grabberObject.GetPin(PinDirection.Output, 0));
grabber.SetBufferSamples(false);
grabber.SetOneShot(false);
grabber.SetCallback(capGrabber, 1);
IVideoWindow wnd = (IVideoWindow)graph;
wnd.put_AutoShow(false);
wnd = null;
control = (IMediaControl)graph;
control.Run();
while (!stopSignal.WaitOne(0, true))
{
Thread.Sleep(10);
}
control.StopWhenReady();
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
}
finally
{
graph = null;
sourceObject = null;
grabberObject = null;
grabber = null;
capGrabber = null;
control = null;
}
}
示例11: ConfigureSampleGrabber
/// <summary>
/// Configures the sample grabber
/// </summary>
/// <param name="sampGrabber"></param>
private void ConfigureSampleGrabber(ISampleGrabber sampGrabber)
{
AMMediaType media;
int status;
// Set the media type to Video/RBG24
media = new AMMediaType();
media.majorType = MediaType.Video;
media.subType = MediaSubType.RGB24;
media.formatType = FormatType.VideoInfo;
status = sampGrabber.SetMediaType(media);
DsError.ThrowExceptionForHR(status);
DsUtils.FreeAMMediaType(media);
media = null;
// Configure the samplegrabber
status = sampGrabber.SetCallback(this, 1);
DsError.ThrowExceptionForHR(status);
}
示例12: InitializeCapture
private void InitializeCapture()
{
graphBuilder = (IGraphBuilder)new FilterGraph();
mediaControl = (IMediaControl)graphBuilder;
captureGraphBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
hr = captureGraphBuilder.SetFiltergraph(graphBuilder);
DsError.ThrowExceptionForHR(hr);
IBaseFilter videoInput = GetVideoInputObject();
if (null != videoInput)
{
SetConfigurations(videoInput);
sampleGrabber = new SampleGrabber() as ISampleGrabber;
hr = graphBuilder.AddFilter((IBaseFilter)sampleGrabber, "Render");
DsError.ThrowExceptionForHR(hr);
hr = graphBuilder.AddFilter(videoInput, "Camera");
DsError.ThrowExceptionForHR(hr);
AMMediaType type = new AMMediaType() { majorType = MediaType.Video, subType = MediaSubType.ARGB32, formatType = FormatType.VideoInfo };
hr = sampleGrabber.SetMediaType(type);
DsError.ThrowExceptionForHR(hr);
DsUtils.FreeAMMediaType(type);
sampleGrabber.SetBufferSamples(false);
sampleGrabber.SetOneShot(false);
sampleGrabber.GetConnectedMediaType(new AMMediaType());
sampleGrabber.SetCallback((ISampleGrabberCB)this, 1);
hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, videoInput, null, sampleGrabber as IBaseFilter);
DsError.ThrowExceptionForHR(hr);
Marshal.ReleaseComObject(videoInput);
}
}
示例13: ConfigureSampleGrabber
private void ConfigureSampleGrabber(ISampleGrabber sampGrabber)
{
var media = new AMMediaType
{
majorType = MediaType.Video,
subType = MediaSubType.RGB24,
formatType = FormatType.VideoInfo
};
var hr = sampGrabber.SetMediaType(media);
DsError.ThrowExceptionForHR(hr);
DsUtils.FreeAMMediaType(media);
hr = sampGrabber.SetCallback(this, 1);
DsError.ThrowExceptionForHR(hr);
}
示例14: Init
/// <summary>
/// Worker thread that captures the images
/// </summary>
private void Init()
{
try
{
log.Trace("Start worker thread");
// Create the main graph
_graph = Activator.CreateInstance(Type.GetTypeFromCLSID(FilterGraph)) as IGraphBuilder;
// Create the webcam source
_sourceObject = FilterInfo.CreateFilter(_monikerString);
// Create the grabber
_grabber = Activator.CreateInstance(Type.GetTypeFromCLSID(SampleGrabber)) as ISampleGrabber;
_grabberObject = _grabber as IBaseFilter;
// Add the source and grabber to the main graph
_graph.AddFilter(_sourceObject, "source");
_graph.AddFilter(_grabberObject, "grabber");
using (AMMediaType mediaType = new AMMediaType())
{
mediaType.MajorType = MediaTypes.Video;
mediaType.SubType = MediaSubTypes.RGB32;
_grabber.SetMediaType(mediaType);
if (_graph.Connect(_sourceObject.GetPin(PinDirection.Output, 0), _grabberObject.GetPin(PinDirection.Input, 0)) >= 0)
{
if (_grabber.GetConnectedMediaType(mediaType) == 0)
{
// During startup, this code can be too fast, so try at least 3 times
int retryCount = 0;
bool succeeded = false;
while ((retryCount < 3) && !succeeded)
{
// Tried again
retryCount++;
try
{
// Retrieve the grabber information
VideoInfoHeader header = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.FormatPtr, typeof(VideoInfoHeader));
_capGrabber.Width = header.BmiHeader.Width;
_capGrabber.Height = header.BmiHeader.Height;
// Succeeded
succeeded = true;
}
catch
{
// Trace
log.InfoFormat("Failed to retrieve the grabber information, tried {0} time(s)", retryCount);
// Sleep
Thread.Sleep(50);
}
}
}
}
_graph.Render(_grabberObject.GetPin(PinDirection.Output, 0));
_grabber.SetBufferSamples(false);
_grabber.SetOneShot(false);
_grabber.SetCallback(_capGrabber, 1);
log.Trace("_grabber set up");
// Get the video window
IVideoWindow wnd = (IVideoWindow)_graph;
wnd.put_AutoShow(false);
wnd = null;
// Create the control and run
_control = (IMediaControl)_graph;
_control.Run();
log.Trace("control runs");
// Wait for the stop signal
//while (!_stopSignal.WaitOne(0, true))
//{
// Thread.Sleep(10);
//}
}
}catch (Exception ex)
{
// Trace
log.Debug(ex);
Release();
}
}
示例15: SetUpForTs
public void SetUpForTs(ISampleGrabberCB grabber, int methodToCall)
{
FilterGraphTools.DisconnectPins(mpeg2Demux);
//FilterGraphTools.DisconnectPins(demodulator);
FilterGraphTools.DisconnectPins(audioRenderer);
FilterGraphTools.DisconnectPins(videoRenderer);
//graphBuilder.RemoveFilter(audioRenderer);
//graphBuilder.RemoveFilter(videoRenderer);
sampleGrabber = (ISampleGrabber)new SampleGrabber();
AMMediaType media = new AMMediaType();
media.majorType = MediaType.Stream;
media.subType = MediaSubType.Mpeg2Transport;
media.formatType = FormatType.MpegStreams;
sampleGrabber.SetOneShot(false);
sampleGrabber.SetBufferSamples(true);
int hr = sampleGrabber.SetMediaType(media);
DsError.ThrowExceptionForHR(hr);
graphBuilder.AddFilter((IBaseFilter)sampleGrabber, "Sample Grabber");
nullRenderer = (IBaseFilter)new NullRenderer();
graphBuilder.AddFilter(nullRenderer, "NULL Renderer");
IPin pinIn = DsFindPin.ByName((IBaseFilter)sampleGrabber, "Input");
IPin pinOut = DsFindPin.ByDirection(capture, PinDirection.Output, 0);
IEnumMediaTypes eMedia;
pinOut.EnumMediaTypes(out eMedia);
AMMediaType[] mediaTypes = new AMMediaType[1];
eMedia.Next(mediaTypes.Length, mediaTypes, IntPtr.Zero);
hr = sampleGrabber.SetMediaType(mediaTypes[0]);
DsError.ThrowExceptionForHR(hr);
pinOut.Disconnect();
PinInfo info;
pinOut.QueryPinInfo(out info);
hr = graphBuilder.ConnectDirect(pinOut, pinIn, mediaTypes[0]);
//hr = graphBuilder.Connect(pinOut, pinIn);
DsError.ThrowExceptionForHR(hr);
// Release the Pin
Marshal.ReleaseComObject(pinIn);
pinIn = DsFindPin.ByName(nullRenderer, "In");
pinOut = DsFindPin.ByName((IBaseFilter)sampleGrabber, "Output");
hr = graphBuilder.Connect(pinOut, pinIn);
DsError.ThrowExceptionForHR(hr);
sampleGrabber.SetCallback(grabber, methodToCall);
// Release the Pin
Marshal.ReleaseComObject(pinIn);
pinIn = null;
}