2011-03-08 92 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秒的時間讓驅動器後退。我的代碼錯誤地將視頻標記爲有缺陷。