【发布时间】:2011-11-28 09:53:30
【问题描述】:
当使用以下函数将视频动态加载到画布上时,我正在尝试找到一种方法来提供正确的视频格式(我的视频以 h264 和 webm 编码):
function loadVideo(video_path){
var ctx = document.getElementById('c').getContext('2d');
var vid = document.getElementById('v');
vid.src = video_path;
vid.load();
// play the video once it has loaded
vid.addEventListener('canplay', function(e){
vid.style.display = "block";
vid.play();
}, false);
// hide the video container once the video has finished playing
vid.addEventListener('ended', function(e){
vid.style.display = "none";
}, false);
}
这是body标签内的简单html:
<video id="v" type="video/webm" width="960" height="500"></video>
<canvas id="c"></canvas>
我可以通过用户代理嗅探路线为我提供正确的 video_path 字符串,但有没有更优雅的方法?
【问题讨论】:
-
不完全相关但可能有用:Zencoder 有 a great FAQ on which codecs and formats to use。
标签: javascript html html5-video h.264 webm