2011-03-08 91 views
1

我正在用VLC浏览器插件编写脚本来确定任何视频文件的长度。我首先告诉VLC试图播放该文件。然后我会定期探测它的长度。一旦它告诉我长度不为零,我知道视频已经成功开始播放,并且长度是准确的。VLC打开视频文件需要几秒钟?

困难的部分是错误检测。我必须检测提供的文件是否是一个已破解的视频,甚至不是视频。有人可能会谎称文本文件错误地命名为video.avi,VLC将无法播放它。我随意决定,如果VLC报告连续5秒的长度为0,那么我会认为提供的文件不合适。这是一个准确的假设吗?是否有可能严重碎片化的硬盘需要5秒以上的时间才能为视频文件提供VLC?文件的比特率与阅读时间有什么关系?

下面是我的JavaScript代码段,它决定了文件的长度。你不必阅读它来理解我的问题,但你们中的一些人可能会喜欢看到它。

/** 
* Find the total length of a playlist item. 
* 
* @param PlaylistItem playlistItem 
* @param options 
* onSuccess: void function(int length) 
* onFailure: void function() - timeout 
* onComplete: void function() - called after onSuccess or onFailure 
* @return void 
*/ 
findLength: function(playlistItem, options) { 
    var option = { 
     onSuccess: Prototype.emptyFunction, 
     onFailure: Prototype.emptyFunction, 
     onComplete: Prototype.emptyFunction 
    }; 

    Object.extend(option, options); 

    if (playlistItem.getLength() > 0) { 
     option.onSuccess(playlistItem.getLength()); 
     option.onComplete(); 
    } 

    if (this.lengthPoller) { 
     this.lengthPoller.stop(); 
    } 

    this.preview(playlistItem); 

    this.lengthPoller = new PeriodicalExecuter(
     function(poller) { 
      if (this.secondsInComa >= MYAPP.Vlc.MAX_SECONDS_IN_COMA) { 
       this.secondsInComa = 0; 
       option.onFailure(); 
       this.stop(); 
       poller.stop(); 
       option.onComplete(); 
      } else { 
       var currLength = this.vlc.input.length; 
       if (currLength > 0) { 
        currLength /= 1000; 
        playlistItem.setLength(currLength); 
        option.onSuccess(currLength); 
        this.secondsInComa = 0; 
        this.stop(); 
        poller.stop(); 
        option.onComplete(); 
       } else { 
        this.secondsInComa += MYAPP.Vlc.LENGTH_POLLING_PERIOD; 
       } 
      } 
     }.bind(this), 
     MYAPP.Vlc.LENGTH_POLLING_PERIOD 
    ); 
} 

回答

0

我发现它可能需要超过5秒。如果Windows处于非活动状态,Windows将把硬盘置于睡眠​​状态。我试图从一个不活动的驱动器加载视频。花费超过5秒的时间让驱动器后退。我的代码错误地将视频标记为有缺陷。