キャンバス オーバーレイを含むビデオ要素があります。次に、ビデオの上に描画するための描画ツールのセットアップと、ビデオとキャンバスの両方から drawImage を実行して圧縮されたフレームを保存する保存ボタンがあります。ただし、最初に [保存] を押すと、キャンバスの drawImage からの結果しか得られず、ビデオは表示されません。その後の保存では、両方の画像が適切にレイヤー化されて表示されます。これはビデオ イメージの読み込みに問題があるのではないかと考えましたが、保存する前にビデオが完全に読み込まれ、フレームを進めて 2 回目の保存で適切に動作させることもできます。
これがコードです...
<div style="width:960px; height:540px; display:inline-block;">
<video id="video" src="media/_tmp/AA_017_COMP_v37.mov" width="960" height="540" ></video>
</div>
<canvas id="canvas" width="960" height="540" style="position:absolute; top:40px; left:9px; z-index:100;"></canvas>
<input type="button" value="save" id="btn" size="30" onclick="save()" style="float:left; padding:4px; margin-right:4px;" >
<div id="saved" style="border:1px solid #000; position:absolute; top:626px; left:10px; bottom:40px; width:958px; overflow:auto;">SAVED:</div>
function save() {
//COMP CANVAS OVER VIDEOFRAME
var video = document.getElementById("video");
var currentFrame = Math.floor((<?php echo $mov_frames ?> / video.duration) * video.currentTime);
var compCanvas = document.createElement('canvas');
compCanvas.width = video.width;
compCanvas.height = video.height;
compContext = compCanvas.getContext('2d');
compContext.drawImage(video, 0, 0);
compContext.drawImage(canvas, 0, 0);
var dataURL = compCanvas.toDataURL();
$("#saved").append('<div style="width:954px; border-bottom:1px solid #000; padding:2px 2px 0 2px;"><img id="compFrame_'+currentFrame+'" width="180" height="90" src="'+dataURL+'" />Frame: '+currentFrame+'</div>');
}