이 코드와 캔버스를 사용하여 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, " ");
}
캡처의 양이 올바른지,하지만 문제 크롬에서는 모든 캔버스가 검은 색으로 표시되고 파이어 폭스에서는 항상 동일한 이미지를 표시합니다.
어쩌면 문제는 루프가 너무 빨라 캔버스를 칠할 수 없지만 .drawImage()가 비동기식이기 때문에 이론적으로 캔버스가 다음 줄로 넘어 가기 전에 칠해 져야한다는 것입니다. .
이 문제를 해결하는 방법에 대한 아이디어가 있으십니까? 감사합니다. .