Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();
//****************************************************
// Notice here: 
****************************************************
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!!
Posted
Updated 19-Apr-10 23:57pm
v2

1 solution

I can't see where theASFWriter variable is initialized.
Before running any Direct show graphs I would recommend you to use tools like Graphedit or GraphStudio to to build visually and test your graph and afterwards to build them programmatically.An year ago I needed to write an application, which uses direct show using the same library like you, to capture video stream of web camera and allows the user to configure camera resolution and project start was terrible because it's very difficult to find out the reasons for some exceptions.But after I considered using graphedit to test my graphs and then everything was OK.
 
Share this answer
 
v2
Comments
Darkcharm 6-Jun-10 23:20pm    
Yes,you are right .I haven't initialize the asfWriter on the right way !
Thanks !
Darkcharm 7-Jun-10 22:00pm    
It seems that I must use the right GUID !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900