发布时间:2026/8/28 4:46:33
视频录制测试页 !DOCTYPE htmlhtml langzh-CNheadmeta charsetUTF-8meta nameviewport contentwidthdevice-width, initial-scale1.0, maximum-scale1.0, user-scalablenotitleH5 活体录像验证 (最终修正版)/title!-- 引入 vConsole --script srchttps://unpkg.com/vconsolelatest/dist/vconsole.min.js/scriptstyle* { box-sizing: border-box; margin: 0; padding: 0; }body {font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif;display: flex;flex-direction: column;align-items: center;justify-content: center;min-height: 100vh;background-color: #f5f7fa;color: #333;padding: 20px;}/* 视频容器样式 */#video-container {width: 100%;max-width: 480px;aspect-ratio: 16 / 9;background-color: #000;border-radius: 12px;overflow: hidden;position: relative;box-shadow: 0 4px 12px rgba(0,0,0,0.1);margin-bottom: 24px;}video {width: 100%;height: 100%;object-fit: cover;transform: scaleX(-1); /* 镜像显示 */}/* 录制中状态指示器 - 右上角淡色小按钮 */#recording-indicator {position: absolute;top: 12px;right: 12px;background-color: rgba(255, 59, 48, 0.15); /* 淡红色背景 */color: #ff3b30;font-size: 12px;font-weight: 600;padding: 4px 10px;border-radius: 12px;display: none; /* 默认隐藏 */align-items: center;gap: 6px;backdrop-filter: blur(4px);z-index: 10;animation: breathe 1.5s infinite ease-in-out;}#recording-indicator::before {content: ;display: block;width: 6px;height: 6px;background-color: #ff3b30;border-radius: 50%;}keyframes breathe {0%, 100% { opacity: 0.6; transform: scale(0.98); }50% { opacity: 1; transform: scale(1.02); }}/* 倒计时提示 */#countdown {position: absolute;top: 50%;left: 50%;transform: translate(-50%, -50%);font-size: 48px;font-weight: bold;color: white;text-shadow: 0 2px 4px rgba(0,0,0,0.5);display: none;z-index: 5;}/* 按钮组样式 */.btn-group {display: flex;gap: 16px;width: 100%;max-width: 480px;margin-bottom: 16px;}button {flex: 1;padding: 14px 0;border: none;border-radius: 8px;font-size: 16px;font-weight: 600;cursor: pointer;transition: all 0.2s;}button:active { transform: scale(0.98); }#startBtn {background-color: #007aff;color: white;}#saveBtn {background-color: #34c759;color: white;display: none;}#closeBtn {background-color: #ff9500;color: white;display: none;}/* 状态文本 */#statusText {font-size: 14px;color: #666;text-align: center;min-height: 20px;}/* 结果预览区 */#resultContainer {width: 100%;max-width: 480px;margin-top: 20px;display: none;}#resultVideo {width: 100%;border-radius: 8px;background: #000;}.file-info {margin-top: 8px;font-size: 12px;color: #888;text-align: center;}/style/headbodydiv idvideo-containervideo idpreview autoplay playsinline muted/video!-- 录制中指示器 --div idrecording-indicator录制中/div!-- 倒计时 --div idcountdown3/div/divdiv classbtn-groupbutton idstartBtn开始验证/buttonbutton idsaveBtn保存视频/buttonbutton idcloseBtn关闭摄像头/button/divp idstatusText准备就绪/p!-- 结果预览 --div idresultContainervideo idresultVideo controls/videodiv classfile-info idfileInfo/div/divscript// 初始化 vConsoleconst vConsole new window.VConsole();console.log([System] vConsole 已启动);// DOM 元素const preview document.getElementById(preview);const startBtn document.getElementById(startBtn);const saveBtn document.getElementById(saveBtn);const closeBtn document.getElementById(closeBtn);const statusText document.getElementById(statusText);const recordingIndicator document.getElementById(recording-indicator);const countdownEl document.getElementById(countdown);const resultContainer document.getElementById(resultContainer);const resultVideo document.getElementById(resultVideo);const fileInfo document.getElementById(fileInfo);// 全局变量let mediaStream null;let recorder null;let recordedChunks [];let currentBlob null;let isRecording false;// 配置参数const CONFIG {duration: 6000, // 6秒自动结束maxSize: 10 * 1024 * 1024, // 10MB 限制// 源头控制限制分辨率和帧率constraints: {audio: false,video: {width: { ideal: 640, max: 1280 },height: { ideal: 480, max: 720 },frameRate: { ideal: 20, max: 24 }}}};/*** 核心类RecorderManager* 包含录制、自动停止、二次压缩逻辑*/class RecorderManager {constructor(stream) {this.stream stream;this.chunks [];this.recorder null;// 尝试选择兼容性最好的编码格式const options { mimeType: video/webm;codecsvp9 };if (!MediaRecorder.isTypeSupported(options.mimeType)) {options.mimeType video/webm;codecsvp8;if (!MediaRecorder.isTypeSupported(options.mimeType)) {options.mimeType video/webm;}}// 过程建议设置码率虽然浏览器不一定完全遵守options.videoBitsPerSecond 1500000; // 1.5Mbpsthis.recorder new MediaRecorder(this.stream, options);console.log([Recorder] 初始化完成MIME: ${options.mimeType});this.recorder.ondataavailable (e) {if (e.data e.data.size 0) {this.chunks.push(e.data);// 实时打印当前累计大小方便调试const currentSize this.chunks.reduce((acc, cur) acc cur.size, 0);console.log([Recorder] 接收数据块: ${(currentSize / 1024).toFixed(2)} KB);}};this.recorder.onstop () {console.log([Recorder] 录制已停止);const blob new Blob(this.chunks, { type: this.recorder.mimeType });this.handleFinish(blob);};}start() {this.chunks [];this.recorder.start(100); // 每100ms触发一次 dataavailableisRecording true;// 显示 UIrecordingIndicator.style.display flex;statusText.textContent 正在录制...;console.log([Recorder] 开始录制);// 6秒倒计时 UIlet count 3;countdownEl.style.display block;countdownEl.textContent count;const timer setInterval(() {count--;if (count 0) {countdownEl.textContent count;} else {clearInterval(timer);countdownEl.style.display none;}}, 1000);// 6秒后自动停止setTimeout(() {if (this.recorder this.recorder.state recording) {console.log([Recorder] 触发6秒自动停止);this.stop();}}, CONFIG.duration);}stop() {if (this.recorder this.recorder.state ! inactive) {this.recorder.stop();}}async handleFinish(blob) {isRecording false;recordingIndicator.style.display none; // 隐藏录制中标识console.log([Recorder] 原始文件大小: ${(blob.size / 1024 / 1024).toFixed(2)} MB);// 结果兜底如果超过 10MB进行二次压缩if (blob.size CONFIG.maxSize) {console.warn([Recorder] 文件过大启动二次压缩...);statusText.textContent 文件过大正在压缩...;try {blob await this.compressBlob(blob);console.log([Recorder] 压缩后大小: ${(blob.size / 1024 / 1024).toFixed(2)} MB);} catch (err) {console.error([Recorder] 压缩失败:, err);statusText.textContent 压缩失败请重试;return;}}currentBlob blob;this.showResult(blob);}/*** 二次压缩利用 MediaRecorder 重新编码* 不依赖第三方库通过降低码率实现压缩*/compressBlob(originalBlob) {return new Promise((resolve, reject) {const url URL.createObjectURL(originalBlob);const tempVideo document.createElement(video);tempVideo.src url;tempVideo.muted true;tempVideo.playsInline true;// 创建一个新的低码率录制器const compressOptions {mimeType: video/webm,videoBitsPerSecond: 500000 // 500kbps 极低码率};let compressChunks [];let compressRecorder;tempVideo.onloadedmetadata () {try {// 捕获视频流进行重录const stream tempVideo.captureStream ? tempVideo.captureStream() : tempVideo.mozCaptureStream();compressRecorder new MediaRecorder(stream, compressOptions);compressRecorder.ondataavailable (e) {if (e.data.size 0) compressChunks.push(e.data);};compressRecorder.onstop () {URL.revokeObjectURL(url);const compressedBlob new Blob(compressChunks, { type: video/webm });resolve(compressedBlob);};compressRecorder.start();tempVideo.play();// 播放完毕即压缩完成tempVideo.onended () {if (compressRecorder.state ! inactive) {compressRecorder.stop();}};} catch (e) {URL.revokeObjectURL(url);reject(e);}};tempVideo.onerror () reject(new Error(视频加载失败));});}showResult(blob) {const url URL.createObjectURL(blob);resultVideo.src url;resultContainer.style.display block;fileInfo.textContent 大小: ${(blob.size / 1024).toFixed(2)} KB | 类型: ${blob.type};saveBtn.style.display block;closeBtn.style.display block;startBtn.textContent 重新验证;statusText.textContent ✅ 录制完成;}destroy() {if (this.stream) {this.stream.getTracks().forEach(track track.stop());}this.stream null;this.recorder null;}}let manager null;// 1. 开始验证startBtn.addEventListener(click, async () {try {statusText.textContent 正在开启摄像头...;console.log([UI] 点击开始验证);// 获取媒体流mediaStream await navigator.mediaDevices.getUserMedia(CONFIG.constraints);preview.srcObject mediaStream;// 实例化管理器并开始manager new RecorderManager(mediaStream);manager.start();startBtn.style.display none;resultContainer.style.display none;} catch (err) {console.error([Error] 获取摄像头失败:, err);statusText.textContent ❌ 无法访问摄像头: err.message;}});// 2. 保存视频saveBtn.addEventListener(click, () {if (!currentBlob) return;const url URL.createObjectURL(currentBlob);const a document.createElement(a);a.href url;a.download liveness_${Date.now()}.webm;document.body.appendChild(a);a.click();document.body.removeChild(a);URL.revokeObjectURL(url);console.log([UI] 视频已下载);});// 3. 关闭摄像头closeBtn.addEventListener(click, () {if (manager) {manager.destroy();manager null;}preview.srcObject null;currentBlob null;saveBtn.style.display none;closeBtn.style.display none;startBtn.style.display block;startBtn.textContent 开始验证;statusText.textContent 摄像头已安全关闭;recordingIndicator.style.display none; // 确保关闭时隐藏console.log([UI] 摄像头已关闭);});/script/body/html

相关新闻

2026/8/27 6:20:02

Three.js 3D 地图特效与材质实现指南 _

一、地形材质(MeshStandardMaterial) 1.1 实现原理 使用 Three.js 的 PBR(物理正确渲染)材质,结合多张纹理实现真实感地形效果: 漫反射纹理(diffuseMap):控制表面颜色 位…

2026/8/28 2:00:41

AI模型仓库安全基线配置与密钥泄露防护实践

无法生成该主题的技术博文。这个标题涉及的是一起涉外法律事件、公司间纠纷和网络安全入侵事件,属于新闻和法律范畴,而不是可以在博客中安全展开的工程实践教程。输入材料中没有提供任何可验证的技术细节、代码、配置或实现流程,无法补全成一…

2026/8/28 1:30:39

选择排序算法

/*** 选择排序。* author Bright Lee*/ public class SelectionSort {public static void sort(int[] array) {for (int i 0; i < array.length; i) {int minIndex i;for (int j i 1; j < array.length; j) {if (array[j] < array[minIndex]) {minIndex j;}}int …

2026/8/28 1:15:38

跨角色协作如何化解产品冲突

跨角色协作如何化解产品冲突创业团队围绕智能产品争论时&#xff0c;真正冲突的往往不是某个功能&#xff0c;而是谁承担错误的后果。产品想验证需求&#xff0c;工程担心输出不可控&#xff0c;销售希望给客户明确承诺。把讨论压成“大家对齐一下”&#xff0c;问题通常只会延…

2026/8/28 1:10:38

法学专业注意:2026年AIGC检测越来越严,论文AI率超标的自救指南

法学专业的论文写作&#xff0c;在2026年迎来了最严监管年&#xff1a;各大高校法学院普遍在查重之外加设AIGC检测&#xff0c;有的学校明确要求毕业论文AI率不得超过20%&#xff0c;超标直接延期答辩。法学论文本身法条引用多、程式化表达多&#xff0c;天然容易被检测系统&qu…

2026/8/28 0:20:35

AI Agent工具调用安全:Pyshackle执行前门禁实践

在 AI Agent 应用里&#xff0c;工具调用&#xff08;tool call&#xff09;是连接大模型能力和真实世界的桥梁。Agent 决定调用哪个工具、填入什么参数&#xff0c;执行器再做删除文件、发送邮件、查询数据库等真实操作。这个机制非常实用&#xff0c;但也把安全边界放到了很不…

2026/8/26 9:13:28

[光学原理与应用-521]:对光的错误理解与纠偏

首先光是一种能量的载体和形态&#xff0c;宏观上观察到的光是由无数个微观的光量子组成的&#xff0c;每个光子在产生的瞬间&#xff0c;其在真空的空间中以确定不变的速度沿着一个初始的方向一直向前&#xff0c;在微观层面&#xff0c;每个光量子的运动轨迹是以波函数所展现…

2026/8/27 10:58:22

SIP通话转接原理与REFER方法实战解析

1. 通话转接不是“挂断再拨号”&#xff0c;而是SIP会话的动态重定向你有没有遇到过这样的场景&#xff1a;客服坐席A正在和客户通电话&#xff0c;突然需要把这通对话无缝转给专家坐席B&#xff0c;客户完全感知不到中间的断连——既没听到忙音&#xff0c;也没被要求重新拨号…

2026/8/27 7:46:21

Kolla-ansible单节点OpenStack部署实战:从环境准备到排坑指南

1. 为什么选择Kolla-ansible来部署单节点OpenStack&#xff1f;如果你正在寻找一种能把OpenStack从“概念”快速变成“可用的实验环境”的方法&#xff0c;那么Kolla-ansible几乎是当前最主流、最省心的选择。我见过太多人卡在手动编译依赖、配置服务、处理版本冲突的泥潭里&am…

2026/8/28 0:00:34

2026学术工具专业测评|Paperxie全维度性能实测报告[特殊字符]

2026年国内高校毕业论文审核体系全面升级&#xff0c;重复率查重AIGC人工智能检测双检机制正式常态化落地&#xff0c;多所高校明确执行“双项一票否决”制度&#xff0c;重复率超标或AI生成痕迹不达标&#xff0c;均直接取消答辩资格。随着抽检力度加大、学术规范要求升级&…

2026/8/28 0:00:34

凭什么稳居论文工具顶流[特殊字符]Paperxie综合实力深度全解析

2026年论文双检内卷严重&#xff0c;市面上AI论文工具层出不穷&#xff0c;但大多只是单一功能凑数、模板化严重、双检高风险、套路收费。 在一众同质化工具里&#xff0c;Paperxie能长期稳居行业顶流、成为应届生公认毕业神器&#xff0c;从来不是靠营销&#xff0c;而是靠实…

2026/8/28 0:00:34

2026论文工具深度测评|为什么Paperxie是目前最稳的学术工具✅

2026高校论文查重AIGC双检严查常态化。 市面上绝大多数AI论文工具依旧存在明显短板&#xff1a;模板感重、AI痕迹超标、改写毁逻辑、收费套路多、查重不准、格式适配差。 在全网工具普遍“偏科”的现状下&#xff0c;Paperxie凭借全维度均衡实力脱颖而出&#xff0c;成为适配…

2026/8/26 19:34:06

实测才敢推 AI论文网站 2026最新测评与推荐

2026年真正好用的AI论文网站&#xff0c;核心看生成的论文质量、低AI味、格式正确、学术适配四大指标。综合实测&#xff0c;千笔AI、ThouPen、豆包、DeepSeek、Grammarly 是当前最值得推荐的梯队&#xff0c;覆盖从免费到付费、从中文到英文、从文科到理工的全场景需求。一、综…

2026/8/26 19:17:08

2026必备!AI论文网站测评:最新推荐与深度对比

2026年真正好用的AI论文网站&#xff0c;核心看生成的论文质量、低AI味、格式正确、学术适配四大指标。综合实测&#xff0c;千笔AI、ThouPen、豆包、DeepSeek、Grammarly 是当前最值得推荐的梯队&#xff0c;覆盖从免费到付费、从中文到英文、从文科到理工的全场景需求。 一、…

2026/8/26 19:34:05

摆脱论文困扰!盘点2026年全网爆红的的AI论文写作工具

一天写完毕业论文在2026年已不再是天方夜谭。2026年最炸裂、实测能大幅提速的AI论文写作工具&#xff0c;覆盖选题构思、文献整理、内容生成、格式排版等核心场景&#xff0c;真正帮你高效搞定论文难题。 一、全流程王者&#xff1a;一站式搞定论文全链路&#xff08;一天定稿首…