简体   繁体   English

使用DirectShow捕获AVI视频

[英]Capturing an AVI video with DirectShow

I'm trying to capture an AVI video, using DirectShow AVIMux and FileWriter Filters. 我正在尝试使用DirectShow AVIMuxFileWriter过滤器捕获AVI视频。 When I connect SampleGrabber filter instead of the AVIMux , I can clearly see that the stream is 30 fps, however upon capturing the video, each frame is duplicated 4 time and I get a 120 frames instead of 30. The movie is 4 times slower than it should be and only the first frame in the set of 4 is a Key Frame. 当我连接SampleGrabber过滤器而不是AVIMux ,我可以清楚地看到流为30 fps,但是在捕获视频时,每帧被复制4次,我得到的是120帧而不是30帧。电影的速度比慢4倍。它应该是,并且只有4个一组中的第一帧是关键帧。 I tried the same experiment with 8 fps and for each image I received, I had 15 frames in the video. 我以8 fps进行了相同的实验,对于收到的每个图像,视频中都有15帧。 And in case of 15 fps, I got each frame 8 times. 在15 fps的情况下,我每帧获得8次。

I tried both writing the code in C++ and testing it with Graph Edit Plus. 我尝试用C ++编写代码并使用Graph Edit Plus对其进行测试。 Is there any way I can control it? 有什么办法可以控制吗? Maybe some restrictions on the AVIMux filter? 也许对AVIMux过滤器有一些限制?

You don't specify your capture format which could have some bearing on the problem, but generally it sounds like the graph when writing to file has some bottleneck which prevents the stream from continuing to flow at 30fps. 您没有指定可能与问题有关的捕获格式,但是通常听起来像是在写入文件时该图存在一些瓶颈,从而阻止了流以30fps的速度继续流。 The camera is attempting to produce frames at 30fps, and it will do so as long as buffers are recycled for it to fill. 相机正在尝试以30fps的速度产生帧,并且只要缓冲区被回收以填满,相机就会这样做。

But here the buffers aren't available because the file writer is busy getting them onto the disk. 但是这里缓冲区不可用,因为文件编写器正忙于将它们放到磁盘上。 The capture filter is starved and in this situation it increments the "dropped frame" counter which travels with each captured frame. 捕获过滤器饿了,在这种情况下,它增加了“丢失的帧”计数器,该计数器随每个捕获的帧移动。 AVIMux uses this count to insert an indicator into the AVI file which says in effect "a frame should have been available here to write to file, but isn't; at playback time repeat the last frame". AVIMux使用此计数在AVI文件中插入一个指示符,该指示符实际上是“这里应该有一个帧可以写入文件,但没有;在回放时重复最后一帧”。 So the file should have placeholders for 30 frames per second - some filled with actual frames, and some "dropped frames". 因此,文件应具有每秒30帧的占位符-有些填充有实际帧,有些填充了“丢帧”。

Also, you don't mention whether you're muxing in audio, which would be acting as a reference clock for the graph to maintain audio-video sync. 另外,您没有提及是否要混音,这将成为图表的参考时钟,以保持音视频同步。 When capture completes if also using an audio stream, AVIMux alters the framerate of the video stream to make the duration of the two streams equal. 如果还使用音频流完成捕获,则AVIMux会更改视频流的帧速率,以使两个流的持续时间相等。 You can check whether AVIMux has altered the framerate of the video stream by dumping the AVI file header (or maybe right click on the file in explorer and look at the properties). 您可以通过转储AVI文件标题来检查AVIMux是否已更改视频流的帧率(或者可以右键单击资源管理器中的文件并查看属性)。

If I had to hazard a guess as to the root of the problem, I'd wager the capture driver has a bug in calculating the dropped frame count which is in turn messing up AVIMux. 如果我不得不对问题的根源做出猜测,我会押注捕获驱动程序在计算丢弃的帧数时会有一个错误,这反过来又使AVIMux混乱。 Does this happen with a different camera? 使用其他相机会发生这种情况吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM