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!

[3683 byte] By [kastanienreis] at [2007-12-23]
# 1

hi

hr = videoWindow.put_height(480);

hr = videoWindow.put_width(640);

shxvacika at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 2

Thanks for replying.

This only changes the size of the window but the recorded stream is still 320*240. I want to record the stream with a resolution of 640*480.

kastanienreis at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 3

You want to use the IAMStreamConfig interface on the capture pin before you call RenderStream on it (and before you render the preview pin). I'm not familiar with how this would work in C#, but you will probably want to use ICaptureGraphBuilder::FindInterface and then query the available resolutions and select one.

G

GeraintDavies at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 4

Hi,

I got the same question. Did you get the solution ?

Thanks

Luke

Luke at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...

Software Development for Windows Vista

Site Classified