For days ,I tried to capture video streams by Web Camara with DirectShowLib.DLL and I gone through the samples to find the way .
At last I writed the codes like this:
DsDevice[] theDevices;
theDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice );
this .Text =theDevices [0].Name .ToString ();
IFilterGraph2 theFilterGraph = new FilterGraph() as IFilterGraph2;
IMediaControl theMediaControl = null;
theMediaControl = theFilterGraph as IMediaControl;
IBaseFilter theCaptureFilter = null;
IBaseFilter theASFWriter = null;
ICaptureGraphBuilder2 theCAPBuilder = null;
IFileSinkFilter theSinkFilter = null;
SaveFileDialog theSaveDialog = new SaveFileDialog();
theSaveDialog.ShowDialog();
IConfigAsfWriter theConfig = (IConfigAsfWriter)theASFWriter;
Guid theGuid = typeof(IBaseFilter).GUID;
theCAPBuilder =(ICaptureGraphBuilder2 ) new CaptureGraphBuilder2();
****************************************************
theConfig.ConfigureFilterUsingProfileGuid(theGuid);
theCAPBuilder.SetFiltergraph(theFilterGraph);
theFilterGraph.AddSourceFilterForMoniker(theDevices[0].Mon,
null,
theDevices[0].Name,
out theCaptureFilter);
theCAPBuilder.RenderStream(PinCategory.Capture,
MediaType.Video,
theCaptureFilter,
null,
theASFWriter);
theCAPBuilder.SetOutputFileName(MediaSubType.Asf,
theSaveDialog.FileName,
out theASFWriter,
out theSinkFilter);
theMediaControl.Run();
IVideoWindow theWindow = (IVideoWindow)theFilterGraph;
theWindow.put_Owner(this.Handle);
theWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren);
theWindow.SetWindowPosition(0, 0,
this.ClientSize.Width,
this.ClientSize.Height);
theWindow.put_Visible(OABool.True);
OK,Now,run without the noticed line. I gave it a file name with the SaveFileDialog ,such as "j:\first.wmv",then,the form display,but,I can't see any thing except a black ground. Shuted it down ,I can't find the file - first.wmv
Obvious ,there is something wrong .Why,the sample goes well and my application is like this? Then ,I try to run it with the noticed line. It just throwed me a exception : should initialize the object with "new".
Oh,my God ,what is this?!
I have the IConfigAsfWriter like this:
IConfigAsfWriter theConfig = (IConfigAsfWriter)theASFWriter
,and ,I have the GUID Like this:
Guid theGuid = typeof(IBaseFilter).GUID
Why this exception ?
I tried other Configure ways in the list of IConfigAsfWriter ,but no help. Any one can show me the right way ? THANKS!!