在 OpenCV 中反向播放视频 [英] Reverse video playback in OpenCV

查看:56
本文介绍了在 OpenCV 中反向播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 OpenCV 中向后播放视频?通过 API 调用或通过缓冲视频帧并将顺序反转为一个新的视频文件.

Is it possible to play videos backwards in OpenCV? Either by an API call or by buffering video frames and reversing the order into a new video file.

谢谢

推荐答案

唯一可行的方法是手动提取帧,缓冲它们(在内存或文件上),然后以相反的顺序重新加载它们.

The only practical way to do it is to manually extract frames, buffer them ( on memory or files) then reload them in reverse order.

问题在于视频压缩器都在利用时间冗余——事实上,两个连续的帧在大多数情况下非常相似.因此,他们不时地编码一个完整的帧(通常每几百帧)然后只发送前一个和当前之间的差异.

The problem is that video compressors are all exploiting time redundancy - the fact that two consecutive frames are most of the time very similar. So, they encode a full frame from time to time (usually every few hundred frames) then only send differences between the previous and current.

现在,要使解码工作,必须按照相同的顺序进行 - 解码一个关键帧(一个完整的),然后为每个新帧添加差异以获得当前图像.

Now, for decoding to work, it must be done in the same order - decode a keyframe (a full one), then for each new frame, add differences to obtain the current image.

这种策略使得在视频中反向播放变得非常困难.有几种技术,但都涉及缓冲.

This strategy makes it very hard to reverse play in video. There are several techniques, but all involve buffering.

现在,您可能已经看到了 Astor 描述的 CV_CAP_PROP_POS_FRAMES 参数.看起来没问题,但是由于上述问题,OpenCV 无法正确跳转到特定帧(这些问题存在多个错误).他们(OpenCV 开发人员)正在研究一些解决方案,但即使是那些解决方案也会很慢(他们涉及返回到前一个关键帧,然后解码回选定的关键帧).如果你使用这种技术,每一帧平均必须被解码数百次,这使得它非常慢.然而,它不起作用.

Now, you may have seen the CV_CAP_PROP_POS_FRAMES parameters, described by Astor. It seems ok, but because of the issues described above, OpenCV is not able to correctly jump to a specific frame (there are multiple bugs open on these issues). They (OpenCV devs) are working on some solutions, but even those will be very slow (they involve going back to previous keyframe, then decoding back to the selected one). If you use this technique, each frame must be decoded hundreds of times on average, making it very slow. And yet, it doesn't work.

编辑如果您采用缓冲方式来反转它,请记住,解码后的视频会迅速消耗普通计算机的内存资源.一个普通的 720p 视频一分钟长在解压时需要 4.7GB 内存!将帧作为单个文件存储在磁盘上是解决此问题的实用方法.

Edit If you pursue the buffer way to reverse it, keep in mind that a decoded video will quickly eat off the memory resources of a regular computer. A usual 720p video one minute long needs 4.7GB of memory when decompressed! Storing frames as individual files on disk is a practical solution to this problem.

这篇关于在 OpenCV 中反向播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆