How can I render video stream from webcam to file if I use smart tee filter?
So I add SmartTee filter and get something like that:
Capture filter
|
SmartTee filter
| |
capture preview
| |
Mux filter GrabFilter
| |
FileWriter VideoRenderer
So that's connetion capture filter and smart tee:
// Get capture filter
srcFilter = FindCaptureDevice();
// Add Capture filter to our graph.
graph.AddFilter(srcFilter, "Video Capture");
//Add smartTee filter to graph
smartTeeFilter = (IBaseFilter)new SmartTee();
graph.AddFilter(smartTeeFilter, "Smart Tee");
IPin outPin = GetPin(PinDirection.Output, srcFilter);
IPin inPin = GetPin(PinDirection.Input, smartTeeFilter);
graph.Connect(outPin, inPin);
That's connection with grabber and rendering (just in case):
sampGrabber = new SampleGrabber() as ISampleGrabber;
baseGrabFilter = sampGrabber as IBaseFilter;
graph.AddFilter(baseGrabFilter, "Grabber");
IPin sourcePin, grabPin;
sourcePin = GetPin(PinDirection.Output, smartTeeFilter);
grabPin = GetPin(PinDirection.Input, baseGrabFilter);
graph.Connect(sourcePin, grabPin);
graph.Render(GetPin(PinDirection.Output, baseGrabFilter));
And that's all I have in saving file part:
IBaseFilter mux;
IFileSinkFilter sink;
capture.SetOutputFileName(
MediaSubType.Avi, // Specifies AVI for the target file.
path, // File name.
out mux, // Receives a pointer to the mux.
out sink); // (Optional) Receives a pointer to the file sink.
sink.SetFileName(path, null);
IPin outPin = DsFindPin.ByDirection(smartTeeFilter, PinDirection.Output, 1);
IPin inPin = GetPin(PinDirection.Input, mux);
graph.Connect(outPin, inPin);
control.Run();
It's no thrown exceptions. Just creating file with size 64Kb. What's wrong with my saving to file code?
Added.
I check out CapWMV example and in there saving is like this:
IFileSinkFilter sink = null;
IBaseFilter fileWriterFilter = null;
capture = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
capture.SetFiltergraph(graph);
int hr = capture.SetOutputFileName(MediaSubType.Avi, path, out fileWriterFilter, out sink);
DsError.ThrowExceptionForHR(hr);
hr = capture.RenderStream(null, null, smartTeeFilter, null, fileWriterFilter);
DsError.ThrowExceptionForHR(hr);
hr = control.Run();
DsError.ThrowExceptionForHR(hr);
And again I get 64 Kb file and nothing else. Where's my mistake?