Skip to content

从视频文件提取画面帧

js
function captureVideoFrame(videoFile, timestamp) {
    const video = document.createElement('video');
    video.src = videoFile; // Object.createObjectURL(videoFile);
    video.currentTime = timestamp;
    video.crossOrigin = 'anonymous';
    return new Promise((resolve, reject) => {
        video.oncanplaythrough = () => {
            const canvas = document.createElement('canvas');
            canvas.width = video.videoWidth;
            canvas.height = video.videoHeight;
            const ctx = canvas.getContext('2d');
            ctx.drawImage(video, 0, 0);
            const dataURL = canvas.toDataURL('image/png');
            resolve(dataURL);
        };
        video.onerror = reject;
    });
}

苏ICP备2025160170号-1 | 前端进化之路 | Released under the MIT License.