0
我試圖生成一組縮略圖的瀏覽器進行使用帆布與此代碼HTML5視頻:捕獲組
var fps = video_model.getFps(); //frames per second, comes from another script
var start = shot.getStart(); //start time of capture, comes from another script
var end = shot.getEnd(); //end time of capture, comes from another script
for(var i = start; i <= end; i += 50){ //capture every 50 frames
video.get(0).currentTime = i/fps;
var capture = $(document.createElement("canvas"))
.attr({
id: video.get(0).currentTime + "sec",
width: video.get(0).videoWidth,
height: video.get(0).videoHeight
})
var ctx = capture.get(0).getContext("2d");
ctx.drawImage(video.get(0), 0, 0, video.get(0).videoWidth, video.get(0).videoHeight);
$("body").append(capture, " ");
}
的捕獲量是正確的,但問題在Chrome中,所有畫布都顯示爲黑色,而在Firefox中,它們總是顯示相同的圖像。
也許問題在於循環太快而不能讓畫布上色,但我讀過.drawImage()是異步的,因此理論上應該讓畫布在跳到下一行之前進行繪製。
有關如何解決此問題的任何想法? 謝謝。