如何获取当前播放视频文件的当前帧?

发布于 2024-10-06 02:41:44 字数 58 浏览 3 评论 0原文

所以我们有 flv 文件,我们用 mx:vidodisplay 来播放它。如何获取我们当前所在的流帧?

So we have flv file, we play it with mx:vidodisplay for example. how to get on which stream frame we are currently on?

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

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

发布评论

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

评论(2

岁月无声 2024-10-13 02:41:44

您可以在流元数据中检查距当前时间最近的关键帧
更新
创建流时,您需要处理其“onMetaData”调用:

private var metaInfo: Object;
private function initStream():void{
     stream = new NetStream(conn);
     stream.bufferTime = 5;            
     stream.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
     stream.client = new Object();
     stream.client.onMetaData = onMetaData;/*this is what you need*/
     video.attachNetStream(stream);
}
private function onMetaData(info:Object):void {
    metaInfo = info;
    var tmpstr:String = '';
    for(var s:String in info){
       var tstr:String = s + ' = ' + info[s] + '\n';
       tmpstr += tstr.indexOf('object') == -1 ? tstr : '';
       for(var a:String in info[s]){
           var ttstr:String = s + ':' + a + ' = ' + info[s][a] + '\n';
           tmpstr += ttstr.indexOf('object') == -1 ? ttstr : '';
            for(var c:String in info[s][a]){
                var tttstr:String = s + ':' + a + ':' + c + ' = ' + info[s][a][c] + '\n';
                tmpstr += tttstr.indexOf('object') == -1 ? tttstr : '';                     
            }
        }
    }
    trace(tmpstr);          
}

在此跟踪中,您将看到流的元数据是否包含以下项目:
搜索点:93:偏移量= 10342550
搜索点:93:时间 = 165.799

或者也许:
关键帧:次数 = 0,0.48,0.96,1.44,1.92,2.4,2.88,3.36,3.84,4.32,4.8,5.28,5.76,6.24
关键帧:文件位置 = 1063,95174,136998,176043,209542,239148,271062,302006,331724,363948,395039,427503,456317,483313

这取决于编码器设置,如果您的元数据具有任何此类对象(metadata['keyframes']metadata['seekpoints'] 等),您可以执行以下操作:

for (var i:int = 0; i < metaInfo['keyframes']['times'].length; i++) {
    if (stream.time < metaInfo['keyframes']['times'][i]) {
        var keyFrameNum: int = (metaInfo['keyframes']['times'][i] - stream.time < stream.time - metaInfo['keyframes']['times'][i - 1]) ? i : i - 1;
    }
}

you can check the nearest keyframe to the current time in stream metadata
upd
when creating a stream you need to handle its' onMetaData call:

private var metaInfo: Object;
private function initStream():void{
     stream = new NetStream(conn);
     stream.bufferTime = 5;            
     stream.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
     stream.client = new Object();
     stream.client.onMetaData = onMetaData;/*this is what you need*/
     video.attachNetStream(stream);
}
private function onMetaData(info:Object):void {
    metaInfo = info;
    var tmpstr:String = '';
    for(var s:String in info){
       var tstr:String = s + ' = ' + info[s] + '\n';
       tmpstr += tstr.indexOf('object') == -1 ? tstr : '';
       for(var a:String in info[s]){
           var ttstr:String = s + ':' + a + ' = ' + info[s][a] + '\n';
           tmpstr += ttstr.indexOf('object') == -1 ? ttstr : '';
            for(var c:String in info[s][a]){
                var tttstr:String = s + ':' + a + ':' + c + ' = ' + info[s][a][c] + '\n';
                tmpstr += tttstr.indexOf('object') == -1 ? tttstr : '';                     
            }
        }
    }
    trace(tmpstr);          
}

in this trace you'll see if the streams' metadata has items like:
seekpoints:93:offset = 10342550
seekpoints:93:time = 165.799

or maybe:
keyframes:times = 0,0.48,0.96,1.44,1.92,2.4,2.88,3.36,3.84,4.32,4.8,5.28,5.76,6.24
keyframes:filepositions = 1063,95174,136998,176043,209542,239148,271062,302006,331724,363948,395039,427503,456317,483313

it depends on encoder settings, if your metadata has any object of this kind (metadata['keyframes'], metadata['seekpoints'] etc) you can do the following:

for (var i:int = 0; i < metaInfo['keyframes']['times'].length; i++) {
    if (stream.time < metaInfo['keyframes']['times'][i]) {
        var keyFrameNum: int = (metaInfo['keyframes']['times'][i] - stream.time < stream.time - metaInfo['keyframes']['times'][i - 1]) ? i : i - 1;
    }
}
小…楫夜泊 2024-10-13 02:41:44

我做了一个静态类来将 netstream 元数据对象解析为 as3 对象。您可以使用 JSON.stringify(parse(info)) 来检查 info 中的所有属性。这个类刚刚实现。可能里面有一些bug。

public class NetStreamMetaData
{
    public static function parse(object:Object, isArray:Boolean = false):Object{
        var ret:Object = {};
        if(isArray)
            ret = [];

        var k:String;
        for(k in object){
            if(isNaN(Number(k))){
                if(object[k] is Array){
                    ret[k] = parse(object[k], true);
                }else{
                    ret[k] = object[k];
                }   
            }else{
                if(object[k] is Array){
                    ret.push(parse(object[k], false));
                }else{
                    ret.push(object[k]);
                }
            }
        }
        return ret;
    }
}

I did a static class to parse netstream metadata object to as3 object. You can use JSON.stringify(parse(info)) to check all attribute in info. This class just draftly implement. May be some bugs inside.

public class NetStreamMetaData
{
    public static function parse(object:Object, isArray:Boolean = false):Object{
        var ret:Object = {};
        if(isArray)
            ret = [];

        var k:String;
        for(k in object){
            if(isNaN(Number(k))){
                if(object[k] is Array){
                    ret[k] = parse(object[k], true);
                }else{
                    ret[k] = object[k];
                }   
            }else{
                if(object[k] is Array){
                    ret.push(parse(object[k], false));
                }else{
                    ret.push(object[k]);
                }
            }
        }
        return ret;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文