将视频文件加载到 C++ 的缓冲区中

发布于 2024-11-04 19:04:34 字数 312 浏览 1 评论 0原文

我目前正在尝试创建一个程序,该程序接受视频文件(通常是 AVI),并尝试将其转换为图像。到目前为止,我的流程运行得很完美,如果需要的话可以不用管。但是,我想看看是否可以优化它的速度。所以我的问题是是否可以将视频文件的一部分逐块加载到内存中而不是流式传输。也许将 2 - 3 分钟的剪辑加载到缓冲区中,对其进行处理,然后在接下来的 2 - 3 分钟的视频中重复使用它。我已经研究了 Direct Show 和 OpenCV 来加载和播放视频文件,但到目前为止还没有找到有关将视频加载到缓冲区的任何信息。非常感谢任何教程或概念的链接。

如果有帮助的话,这将在 Windows XP/7 机器上开发。

I am currently trying to create a program that takes a video file, usually an AVI, and trying to convert it into images. So far I got the process working perfectly and could be left alone if needed. However, I would like to see if it was possible to optimize it for speed. So my question is if it is possible to load a portion of a video file into memory chunk by chunk instead of streaming it. Maybe load up a 2 - 3 minute clip into a buffer, process it, and reuse it for the next 2 - 3 minutes of video. I have looked into Direct Show and OpenCV into loading and playing video files, but so far haven't been able to find anything regarding loading videos into a buffer. Any links to tutorials or concepts is greatly appreciated.

This will be developed on a Windows XP/7 machine if it helps.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

春夜浅 2024-11-11 19:04:35

您可以做的就是从磁盘将一些帧(我们称之为 N 帧块)加载到队列中。一旦为缓冲区设置了限制,就可以将帧拉出并进行处理。您可以使用两个队列(Q1 和 Q2)和两个线程(T1 和 T2)并行执行此操作。在使用 T2 处理 Q1 中的帧时,您可以使用 T1 加载 Q2。当一个队列已满时,您将进行上下文切换,并在另一个队列从磁盘加载帧时将帧拉出并处理它们。当然,您需要处理与这种方法相关的线程/并行化复杂性,在这种情况下,BOOST 线程可能会有所帮助。

What you can do is to load a few frames, lets call it a chunk of N frames, into a queue from the disk. Once you set a limit for the buffer, you then pull the frames out and process them. You can do this in parallel by using two queues (Q1 and Q2) and two threads (T1 and T2). While processing frames from Q1 using T2, you can load Q2 using T1. You will be doing a context-switching one queue when it is full and pull the frames out and process them while the other queue is being loaded with frames from the disk. Of course you will need to handle the threading/parallelization intricacies associated with such an approach, in which case, BOOST threading might be helpful.

海拔太高太耀眼 2024-11-11 19:04:35

此类应用程序的瓶颈是从磁盘读取文件,以及将每一帧转换为图像。你无法逃避这些任务。除非您以错误的方式执行此操作,否则您无法采取任何措施来显着加快应用程序的执行速度。

希望您不必将这些图像写回磁盘。

The bottleneck of an application like that is reading the file from the disk, and converting each frame to an image. You can't escape from those tasks. Unless you are doing it in the wrong way, there's nothing you can do to significantly speed up the execution of the application.

Hopefully you don't have to write those images back to the disk.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文