video标签指定视频的某一帧作为封面


import Vue from 'vue'
captureFrame(url, file) {
      const video = document.createElement('video')
      video.src = url
      const canvas = document.createElement('canvas')
      const ctx = canvas.getContext('2d')
      video.onloadedmetadata = () => {
        video.currentTime = 3//指定视频的低3秒
      }
      video.oncanplay = () => {
        canvas.width = 1160
        canvas.height = 570
        ctx.drawImage(video, 0, 0, 1160, 570)
        Vue.set(file, 'imageShow', canvas.toDataURL('image/png'))
      }
},
this.currentUrl = require('@/assets/video.mp4')
this.captureFrame(this.currentUrl,this.dataList[0])

你可能感兴趣的:(音视频,前端,javascript,video,canvas)