DirectShowNet: how do you set the resolution of a stream?
Hi
Recording A/V streams with DirectShowNet works, but I don't know how to change the video resolution.
This is part of my code:
IMediaControl mediaControl = null;
IGraphBuilder graphBuilder = null;
IBaseFilter videoDevice = null;
IBaseFilter audioDevice = null;
IBaseFilter videoCompressor = null;
IBaseFilter audioCompressor = null;
initGraph()
{
//Create the Graph
graphBuilder = (IGraphBuilder)new FilterGraph();
//Create the Capture Graph Builder
ICaptureGraphBuilder2 captureGraphBuilder = null;
captureGraphBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
//Create the media control for controlling the graph
mediaControl = (IMediaControl)this.graphBuilder;
// Attach the filter graph to the capture graph
int hr = captureGraphBuilder.SetFiltergraph(this.graphBuilder);
DsError.ThrowExceptionForHR(hr);
//Add Video input device to the graph
hr = graphBuilder.AddFilter(this.videoDevice, "video filter");
DsError.ThrowExceptionForHR(hr);
//Add the Video compressor filter to the graph
hr = graphBuilder.AddFilter(this.videoCompressor, "video compressor filter");
DsError.ThrowExceptionForHR(hr);
//Add Audio input device to the graph
hr = graphBuilder.AddFilter(this.audioDevice, "audio filter");
DsError.ThrowExceptionForHR(hr);
//Add Audio compressor to the graph
hr = graphBuilder.AddFilter(this.audioCompressor, "audio compressor filter");
DsError.ThrowExceptionForHR(hr);
//Create the file writer part of the graph. SetOutputFileName does this for us, and returns the mux and sink
IBaseFilter mux;
IFileSinkFilter sink;
hr = captureGraphBuilder.SetOutputFileName(MediaSubType.Avi, filename, out mux, out sink);
DsError.ThrowExceptionForHR(hr);
//Render any preview pin of device
hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, this.videoDevice1, null, null);
DsError.ThrowExceptionForHR(hr);
//Connect video device and compressor to the mux to render the capture part of the graph
hr = captureGraphBuilder.RenderStream(PinCategory.Capture, MediaType.Video, this.videoDevice1, this.videoCompressor, mux);
DsError.ThrowExceptionForHR(hr);
//Connect audio device and compressor to the mux to render the capture part of the graph
hr = captureGraphBuilder.RenderStream(PinCategory.Capture, MediaType.Audio, this.audioDevice, this.audioCompressor, mux);
DsError.ThrowExceptionForHR(hr);
//get the video window from the graph
IVideoWindow videoWindow = null;
videoWindow = (IVideoWindow)graphBuilder;
//Set the owener of the videoWindow to an IntPtr of some sort (the Handle of any control - could be a form / button etc.)
hr = videoWindow.put_Owner(this.panel1.Handle);
DsError.ThrowExceptionForHR(hr);
//Set the style of the video window
hr = videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren);
DsError.ThrowExceptionForHR(hr);
// Position video window in client rect of main application window
hr = videoWindow.SetWindowPosition(0, 0, panel1.Width, panel1.Height);
DsError.ThrowExceptionForHR(hr);
// Make the video window visible
hr = videoWindow.put_Visible(OABool.True);
DsError.ThrowExceptionForHR(hr);
Marshal.ReleaseComObject(mux);
Marshal.ReleaseComObject(sink);
Marshal.ReleaseComObject(captureGraphBuilder);
}
I want to change the resolution to 640*480, how do I do this?
Thanks!

