I am completely new to video input, and just started working with AForge a few days ago. Working with live video is comfortable, but I need to do something with files for a project now.
Using the Windows Media Video 9 VCM codec, saving has not been a problem. The output file works normally with every player I have, but my program always plays it back at about double the frame rate. This is especially odd since there is never any indication that the frame rate is changed: both the default the video was saved with and the new player indicate that the frame rate is 25 fps.
The only suggestions I have found are to change the frame rate before the video is captured, but this seems to do nothing.
Looking around in the AVIFileVideoSource documentation, I found the FrameIntervalFromSource and FrameInterval properties which, together, should give me the results I am looking for, but I can’t get them to work, either. Everything else has been a dead end, and I am out of ideas. Here is the code that I am using to read the file:
public partial class Form1 : Form
{
AVIReader input = new AVIReader();
AVIFileVideoSource source = new AVIFileVideoSource("test.avi");
public Form1()
{
InitializeComponent();
}
public void cam_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
input.Open("test.avi");
for (int i = 0; i < input.Length; i++)
{
pictureBox1.Image = input.GetNextFrame();
}
source.Stop();
input.Close();
}
private void button1_Click(object sender, EventArgs e)
{
source.NewFrame += new NewFrameEventHandler(cam_NewFrame);
source.Start();
}
private void button2_Click(object sender, EventArgs e)
{
source.Stop();
input.Close();
}
}
Any other suggestions would be greatly appreciated. Thank you for your time.
I found a working solution to the problem by looking into some other areas of the library. In this solution, there were two other classes that I was overlooking: DirectShow, which was already referenced, and Control. Specifically, I needed to use instances of FileVideoSource and VideoSourcePlayer to get the video into something I could work with.
This version is different from the above in that both the read and write functions have been combined into one program. Furthermore, I was in something of a rush to get this done, so it is still quite fragile. Nevertheless, here is my solution:
Thank you for reading.