主题预览

色调:

如果您使用的浏览器过时,不支持OKLCH颜色。颜色设置会不生效。

轻盈的鱼
幻想变成轻盈的鱼, 畅游在自由的海洋

通过视频url,获取缩略图

728 字

通过视频url,获取缩略图

    getVideoImg (url) {
      let _this = this
      // 创建视频对象
      let video = document.createElement('video')
      video.src = url
      video.width = 503
      video.height = 295
      video.setAttribute('crossOrigin', 'Anonymous')
      video.autoplay = true
      // video.play() // 开始播放
      video.addEventListener('loadeddata', () => {
        setTimeout(() => {
          let canvas = document.createElement('canvas')
          canvas.width = 503
          canvas.height = 503
          let ctx = canvas.getContext('2d')
          let imgHeight = video.videoHeight
          let imgWidth = video.videoWidth
          // canvas.width = imgWidth
          // canvas.height = imgHeight
          ctx.drawImage(video, 0, 0, imgWidth, imgHeight, 0, 0, video.width, video.width)
          let img = canvas.toDataURL('image/png')
          // img 为图片信息
          _this.$set(_this.imgList, url, img)
        }, 10)
      }, false)
    },