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

查看:157
本文介绍了在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天全站免登陆