I am new to DirectShow and am using the DirectShow.NET library. I'm trying to create a Graph in C# that saves a video stream from an IP camera to an AVI file.
I have successfully created a C# Windows Forms app that can display the live video stream onto a panel control on a form. That's a simple graph with the IP camera Source Filter->Color Space Converter->Video Renderer
I spawn a new thread for processing the events from the graph with this code:
public void Start()
{
// Create a new thread to process events
Thread t;
t = new Thread(new ThreadStart(EventWait));
t.Name = "Media Event Thread";
t.Start();
int hr = mediaControl.Run();
checkHR(hr, "Can't Run Graph");
}
The EventWait method processes the IMediaEvent GetEvent for the graph. All this works fine and as expected.
Then I created a new graph that branches off to save the video stream as an MPEG4 file to disk. That's where the error occurs after processing two frames.
The graph looks like this:
IP Camera Source Filter->Smart Tee(Preview Pin)->Color Space Converter->Video Renderer (this branch works)
Smart Tee(Capture Pin)->Color Space Converter->MS MPEG4 Codec V3->AVI Mux->File Writer
Can someone confirm that this branch is correct for saving an MPEG4 file to disk?
If this is correct, I assign an IFileSinkFilter object to the FilleWriter object and assign a filename like this:
IFileSinkFilter pFileSink = (IFileSinkFilter)pFileWriter;
// set the sink to the output file name
pFileSink.SetFileName("myvideo.avi", null);
I do this BEFORE the pins are connected to each filter. The graph builds without an error and I can actually see the myvideo.avi file created in the local folder, but after two frames are processed, the event receives an ErrorAbort event code.
The reason that I know that it is two frames is because the Source Filter returns an event when each frame is filled, which is captured by the event processing method and I setup an incrementing counter to display as a Debug.Writeline.
So, I would greatly appreciate some feedback. Also, if there are any good resources and tutorials for DirectShow, please let me know that as well.
Thanks,
Mark
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
From other forums, I have determined that the AVI Mux requires the Time and MediaTime to be valid timestamps and not zero as they are now. I understand that using a SampleGrabber filter and setting up a callback to the SampeCB method, I can set both the SetTime and SetMediaTime methods to valid timestamps.
Now, I just need to know how to determine the values that should be used for both the Start and End times for both the SetTime and SetMediaTime methods.
Any help is really appreciated.
Thanks,
Mark
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well, I don't immediately see anything wrong here. You aren't trying to write to a network drive, are you? You might also try the Infinite Tee filter rather than the Smart Tee.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It seems that the AVI Mux filter indicates that a sample that is being received has a timestamp issue as an error dialog appears with this message:
An error occurred in the graph: 80040249: No time stamp has been set for this sample
I took out the AVI Mux and File Writer and inserted a SampleGrabber just before the video is rendered as a simple preview. The graph is simply Source->Color Space Converter->SampleGrabber->Video Renderer. Using the GraphEditPlus tool, I am able to view the samples as they are being rendered. Here are a few records:
11:17:14 AM.750: SampleTime=6.975E+11, Time(start=0, end=0), MediaTime(start=0, end=0), data length=1228800, Data=0087000000870000...
11:17:14 AM.828: SampleTime=6.975E+11, Time(start=0, end=0), MediaTime(start=0, end=0), data length=1228800, Data=0002000000020000...
11:17:14 AM.859: SampleTime=6.975E+11, Time(start=0, end=0), MediaTime(start=0, end=0), data length=1228800, Data=0002000000020000...
I can let the graph run and run and run and all samples look the same except for the initial time stamp, which seems to be there, so I still don't understand why the AVI Mux is indicating the error.
Please if anyone has a solution, I really need one!!!
Thanks,
Mark
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am new to DirectShow and am using the DirectShow.NET library. I'm trying to create a Graph in C# that saves a video stream from an IP camera to an AVI file.
I have successfully created a C# Windows Forms app that can display the live video stream onto a panel control on a form. That's a simple graph with the IP camera Source Filter->Color Space Converter->Video Renderer
I spawn a new thread for processing the events from the graph with this code:
The EventWait method processes the IMediaEvent GetEvent for the graph. All this works fine and as expected.
Then I created a new graph that branches off to save the video stream as an MPEG4 file to disk. That's where the error occurs after processing two frames.
The graph looks like this:
IP Camera Source Filter->Smart Tee(Preview Pin)->Color Space Converter->Video Renderer (this branch works)
Smart Tee(Capture Pin)->Color Space Converter->MS MPEG4 Codec V3->AVI Mux->File Writer
Can someone confirm that this branch is correct for saving an MPEG4 file to disk?
If this is correct, I assign an IFileSinkFilter object to the FilleWriter object and assign a filename like this:
I do this BEFORE the pins are connected to each filter. The graph builds without an error and I can actually see the myvideo.avi file created in the local folder, but after two frames are processed, the event receives an ErrorAbort event code.
The reason that I know that it is two frames is because the Source Filter returns an event when each frame is filled, which is captured by the event processing method and I setup an incrementing counter to display as a Debug.Writeline.
So, I would greatly appreciate some feedback. Also, if there are any good resources and tutorials for DirectShow, please let me know that as well.
Thanks,
Mark
From other forums, I have determined that the AVI Mux requires the Time and MediaTime to be valid timestamps and not zero as they are now. I understand that using a SampleGrabber filter and setting up a callback to the SampeCB method, I can set both the SetTime and SetMediaTime methods to valid timestamps.
Now, I just need to know how to determine the values that should be used for both the Start and End times for both the SetTime and SetMediaTime methods.
Any help is really appreciated.
Thanks,
Mark
http://msdn.microsoft.com/en-us/library/dd407202%28VS.85%29.aspx
Well, I don't immediately see anything wrong here. You aren't trying to write to a network drive, are you? You might also try the Infinite Tee filter rather than the Smart Tee.
Thanks...but no luck. After replacing the Smart Tee with the Infinite Tee - still same error.
...more information....
It seems that the AVI Mux filter indicates that a sample that is being received has a timestamp issue as an error dialog appears with this message:
An error occurred in the graph: 80040249: No time stamp has been set for this sample
I took out the AVI Mux and File Writer and inserted a SampleGrabber just before the video is rendered as a simple preview. The graph is simply Source->Color Space Converter->SampleGrabber->Video Renderer. Using the GraphEditPlus tool, I am able to view the samples as they are being rendered. Here are a few records:
11:17:14 AM.750: SampleTime=6.975E+11, Time(start=0, end=0), MediaTime(start=0, end=0), data length=1228800, Data=0087000000870000...
11:17:14 AM.828: SampleTime=6.975E+11, Time(start=0, end=0), MediaTime(start=0, end=0), data length=1228800, Data=0002000000020000...
11:17:14 AM.859: SampleTime=6.975E+11, Time(start=0, end=0), MediaTime(start=0, end=0), data length=1228800, Data=0002000000020000...
I can let the graph run and run and run and all samples look the same except for the initial time stamp, which seems to be there, so I still don't understand why the AVI Mux is indicating the error.
Please if anyone has a solution, I really need one!!!
Thanks,
Mark