Reputation: 684
I am using DirectShow.Net and I am capturing video from a webcam and saving it to an AVI file. AVI files can get large and I would like to save it in a different format. I am using ICaptureGraphBuilder2::SetOutputFileName( MediaSubType.type, name, out, out). ICaptureGraphBuilder will only let me use a MediaSubType of .AVI or .ASF to save a file. If i try to change the type it tries to save as, it will crash:
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 the Video input device to the graph
hr = graphBuilder.AddFilter(theDevice, "source filter");
DsError.ThrowExceptionForHR(hr);
//Add the Video compressor filter to the graph
hr = graphBuilder.AddFilter(theCompressor, "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.MPEG1Video, textBox1.Text, out mux, out sink);
captureGraphBuilder.SetOutputFileName
DsError.ThrowExceptionForHR(hr);
//Render any preview pin of the device
hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, theDevice, null, null);
DsError.ThrowExceptionForHR(hr);
Is there a way to save to anything other then AVI or ASF without too much hassle?
Upvotes: 1
Views: 3708
Reputation: 7452
The problem is most likely not the AVI container format but the codec that you are using to compress the video.
You will need to add a different video compression filter (probably MPEG4 or AVC) and wherever you get that will probably also supply an MP4 mux that you can and should use instead of the avi mux that you are using now.
Upvotes: 4
Reputation: 18295
Have you looked at EmguCV (www.emgu.com which is a .net wrapper for open cv. This has a number of classes in it that may help.
Upvotes: 0