Javascript 是否可以反向播放 HTML5 视频?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5277293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 16:27:13  来源:igfitidea点击:

Is it possible to play HTML5 video in reverse?

javascripthtmlhtml5-video

提问by Ish

Is HTML5 <video>tag be play video in reverse, or I have to download 2 videos (forward and backword play). Any solution that avoid user from downloading 2 videos?

HTML5<video>标签是反向播放视频,还是我必须下载 2 个视频(正向和反向播放)。任何避免用户下载 2 个视频的解决方案?

采纳答案by Frédéric Hamidi

Without even going into HTML5 or Javascript, many video formats are streamingformats that are designed to be played forward. Playing it backwards would require decoding the whole stream, storing each raw frame on the disk to avoid clobbering memory, then rendering the frames backwards.

甚至无需使用 HTML5 或 Javascript,许多视频格式都是旨在向前播放的流格式。向后播放需要解码整个流,将每个原始帧存储在磁盘上以避免破坏内存,然后向后渲染帧。

At least one person actually tried thatusing mplayer, though, so it canbe done, at least in principle.

不过,至少有一个人实际尝试过使用mplayer,因此可以做到,至少在原则上是这样。

回答by Eli Grey

aMediaElement.playbackRate = -1;

UAs may not support this, though it is valid to set playbackRateto a negative value.

UA 可能不支持这一点,尽管设置playbackRate为负值是有效的。

回答by BaptisteB

I managed to do it in an update method. Every frame I decrease video.currentTime to the time elapsed and so far it is the best result I managed to get.

我设法在更新方法中做到了。每一帧我都将 video.currentTime 减少到经过的时间,到目前为止,这是我设法获得的最佳结果。