欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  资讯频道

Firefogg:ogg Theora视频编码插件

程序员文章站 2022-06-10 12:41:21
...

Firefogg是Firefox的一个开源扩展,由Jan Gerber编写而成,能直接在浏览器中编码上传的视频。

它能最大限度的降低服务器端的transocding基础设施,节省本地上传的时间。

Firefogg:ogg Theora视频编码插件

使用Firefogg的网站:



示例:

if(typeof(Firefogg) == 'undefined') {
  alert('You dont have Firefogg, please go to http://firefogg.org to install it');
  window.open('http://firefogg.org');
}
 
var ogg = new Firefogg();
if(ogg.selectVideo()) {
  var options = JSON.stringify({'maxSize': 320, 'videoBitrate': 500});
  var data = JSON.stringify({'title': 'example video'});
  ogg.upload(options, 'http://example.com/addvideo', data);
  var updateStatus = function() {
    var status = ogg.status();
    var progress = ogg.progress();
 
    //do something with status and progress, i.e. set progressbar width:
    var progressbar = document.getElementById('progressbar');
    progressbar.style.width= parseInt(progress*200) +'px';
    progressbar.innerHTML = parseInt(progress*100) + '% - ' + status;
 
    //loop to get new status if still encoding or uploading
    if(ogg.state == 'encoding' || ogg.state == 'uploading') {
      setTimeout(updateStatus, 500);
    }
    //encoding sucessfull, state can also be 'encoding failed'
    else if (ogg.state == 'done') {
      progressbar.innerHTML = 'Upload done. You can close this window now';
    }
  }
  updateStatus()
}