降低 AForge 中 AVI 文件的帧速率
我对视频输入完全陌生,几天前才开始使用 AForge。使用实时视频很舒服,但我现在需要对项目的文件进行一些操作。
使用Windows Media Video 9 VCM编解码器,保存不是问题。输出文件对我拥有的每个播放器都正常工作,但我的程序总是以大约两倍的帧速率播放它。这尤其奇怪,因为从来没有任何迹象表明帧速率发生了变化:保存视频的默认值和新播放器都表明帧速率为 25 fps。
我发现的唯一建议是在捕获视频之前更改帧速率,但这似乎没有任何作用。
环顾 AVIFileVideoSource 文档,我发现了 FrameIntervalFromSource 和 FrameInterval 属性,它们一起应该给我我正在寻找的结果,但我也无法让它们工作。其他一切都是死胡同,我已经没有想法了。这是我用来读取文件的代码:
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();
}
}
任何其他建议将不胜感激。谢谢您的宝贵时间。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过研究图书馆的其他一些区域,我找到了解决该问题的可行方法。在此解决方案中,我忽略了另外两个类:已经引用的 DirectShow 和 Control。具体来说,我需要使用 FileVideoSource 和 VideoSourcePlayer 的实例将视频转换为我可以使用的内容。
该版本与上述版本的不同之处在于,读写功能已合并为一个程序。而且,我当时太急于完成这件事,所以它仍然很脆弱。尽管如此,这是我的解决方案:
感谢您的阅读。
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.