ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ function create_poster(url){ let width = 100; let height = 160; /* 创建视频dom节点 */ let node = document.createElement("video"); node.style.width = `${width}px`; node.style.height = `${height}px`; /* 自动播放 */ node.autoplay = true; node.src = url; node.volume = 0 node.setAttribute("crossOrigin", "anonymous"); /* 创建canvas节点 */ let canvasNode = document.createElement("canvas"); canvasNode.width = width; canvasNode.height = height; const canvasFill = canvasNode.getContext("2d"); /* 把视频变成canvas */ return new Promise(resolve => { node.onplaying = () => { canvasFill.drawImage(node, 0, 0, canvasNode.width, canvasNode.height); /* 把canvas变成图片 */ const imgSrc = canvasNode.toDataURL("image/jpeg"); resolve(imgSrc); }; }); } ~~~ ~~~ create_poster('/de2wrg3e4sdr/uploads/xx.mp4').then((file_data)=>{ }) ~~~