This commit is contained in:
Your Name
2026-03-23 18:02:16 +08:00
parent 18fee2e8f8
commit 250d173c2f
525 changed files with 10659 additions and 793 deletions
+35
View File
@@ -0,0 +1,35 @@
/** 从视频通话区域截取当前最大的一路 video 帧(WebRTC 画面) */
export async function captureVideoFrameFromElement(
container: HTMLElement
): Promise<Blob | null> {
const videos = Array.from(container.querySelectorAll('video')) as HTMLVideoElement[]
let best: HTMLVideoElement | null = null
let bestArea = 0
for (const v of videos) {
if (v.readyState < 2) continue
const vw = v.videoWidth || v.clientWidth
const vh = v.videoHeight || v.clientHeight
const area = vw * vh
if (area > bestArea) {
bestArea = area
best = v
}
}
if (!best) return null
const vw = best.videoWidth || best.clientWidth
const vh = best.videoHeight || best.clientHeight
if (!vw || !vh) return null
const canvas = document.createElement('canvas')
canvas.width = vw
canvas.height = vh
const ctx = canvas.getContext('2d')
if (!ctx) return null
try {
ctx.drawImage(best, 0, 0, vw, vh)
} catch {
return null
}
return new Promise((resolve) => {
canvas.toBlob((b) => resolve(b), 'image/jpeg', 0.92)
})
}