寻找 Flash 视频中特定位置的播放头?
如果您在 Flash 中加载 FLVPlayback 组件或在 Flex 中加载 VideoDisplay 并尝试查找特定位置或将 playheadTime 设置为特定位置,则影片总是向上或向下舍入很大的量。
在 Flash 中,将 FLVPlayback 组件拖至舞台并将源设置为 http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/examples/assets/phone.flv 然后尝试 video.seek(6) 或 video.playheadTime = 6;
它只会转到 10。同样,如果您使用内置的擦洗器,唯一的间隔是 0、5 或 10。因此您看到的擦洗帧最多为 3
以下是具有相同结果的 Flex 示例。
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:media="com.synapsegroup.media.*">
<mx:Script>
<![CDATA[
import mx.events.MetadataEvent;
import mx.events.SliderEvent;
import mx.events.VideoEvent;
protected function scrubber_changeHandler(event:SliderEvent):void
{
trace(event.value);
video.playheadTime = event.value;
}
protected function video_playheadUpdateHandler(event:mx.events.VideoEvent):void
{
//scrubber.value = event.playheadTime;
//http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/examples/assets/phone.flv
}
]]>
</mx:Script>
<mx:Panel>
<mx:VideoDisplay id="video" source="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/examples/assets/phone.flv" minWidth="200" minHeight="200"
autoPlay="false"
/>
<mx:ControlBar>
<mx:Button label="Play" click="video.play();"/>
<mx:Button label="Stop" click="video.pause();"/>
<mx:HSlider liveDragging="true" id="scrubber" minimum="0" maximum="11.5" change="scrubber_changeHandler(event)" thumbPress="video.pause();"/>
</mx:ControlBar>
</mx:Panel>
</mx:Application>
在这两种情况下,如果您单击播放/暂停的速度足够快,您可以以更大的粒度暂停各个帧,但这不是一个好的用户体验
我是否缺少一些以编程方式执行此操作的功能?
我还想说,间隔根据视频长度而变化,3 分钟长的内容有 10 秒的间隔
If you load up a FLVPlayback component in Flash or VideoDisplay in Flex and try to seek to a specific location or set playheadTime to a specific location, the movie always rounds up or down by very large amounts
In flash, drag a FLVPlayback component to stage and set source to http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/examples/assets/phone.flv
Then try to video.seek(6) or video.playheadTime = 6;
It will just goto 10. Likewise if you use their built in scrubber the only intervals are 0, 5, or 10. So at most the scrubbing frame you see is 3
Here is an example of flex with the same result.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:media="com.synapsegroup.media.*">
<mx:Script>
<![CDATA[
import mx.events.MetadataEvent;
import mx.events.SliderEvent;
import mx.events.VideoEvent;
protected function scrubber_changeHandler(event:SliderEvent):void
{
trace(event.value);
video.playheadTime = event.value;
}
protected function video_playheadUpdateHandler(event:mx.events.VideoEvent):void
{
//scrubber.value = event.playheadTime;
//http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/examples/assets/phone.flv
}
]]>
</mx:Script>
<mx:Panel>
<mx:VideoDisplay id="video" source="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/examples/assets/phone.flv" minWidth="200" minHeight="200"
autoPlay="false"
/>
<mx:ControlBar>
<mx:Button label="Play" click="video.play();"/>
<mx:Button label="Stop" click="video.pause();"/>
<mx:HSlider liveDragging="true" id="scrubber" minimum="0" maximum="11.5" change="scrubber_changeHandler(event)" thumbPress="video.pause();"/>
</mx:ControlBar>
</mx:Panel>
</mx:Application>
In both cases if you click play/pause fast enough you can pause on individual frames with much more granularity, but thats not a good UX
Is there something I'm missing to do this programatically?
I'd also say that the interval changes depending on the video length, something that was 3minutes long had 10 second intervals
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
flash 的文档提到seek() 的值是近似值。
造成这种情况的部分原因是视频的压缩方式。它被分成多个块,带有一个关键帧和一组增量帧,其中仅包含有关已更改内容的数据。通过这种方式,视频的整体文件大小比每帧包含每个像素要小得多。
然而,这也意味着您不能直接跳到任何帧,因为许多帧实际上并不存在。播放头必须找到最近的前一个关键帧,然后从该关键帧开始向前播放。
要获得可以停止并寻找任何帧的视频,您必须使用关键帧距离 1 对其进行编码。尝试一下,你会发现你的文件大小很大,但你现在可以让它顺利地向后播放。
至于擦洗棒在寻找时不精确,是的。这是。有点马虎。嘘土坯和所有这些。但是,嘿,必须在告诉玩家在每次鼠标移动时进行搜索(这可能会让玩家陷入困境,因为它会为每次鼠标移动计算 keframe 加增量)与实际能够拖动栏之间进行权衡。
它并不出色,但您可以从 netstream 类中编写自己的代码,并根据您的喜好设置平衡。大多数时候,我发现它们的平衡完全可以使用,即使能够更精确就更好了。
The documentation for flash mentions that values for seek() are approximate.
Part of the reason for this is how video is compressed. It is broken into chunks, with a keyframe, and a set of delta frames, that just contain data about what has changed. In this way, the overall file size for the video is much smaller than having every frame contain every pixel.
However, this also means that you can't just skip to any frame, because many frames do not actually exist. The playhead has to find the closest preceeding keyframe, then play forward from that.
To have a video that can stop and seek to any frame, you have to encode it with a keyframe distance of one. Try that and you will see that you file size is enourmouse, but you can now make it play smoothly backwards.
As for the scrub bar being inexact in seeking, yes. It is. Its kinda sloppy. Boo adobe and all that. But hey have to make a tradeoff between telling the player to seek on every mouse move, which could bog down the player as it computes keframe plus delta for every mouse move, versus actually being able to drag the bar.
Its not brilliant, but you can code your own from a netstream class and set a balance more to you liking. Most of the time I find their balance entirely servicable, even if it would be nice to be able to be more precise.