getVideo(value) {
const that = this;
const video = document.createElement('video');
video.setAttribute('crossOrigin', 'anonymous');
video.setAttribute('src', value);
video.setAttribute('width', '400');
video.setAttribute('height', '600');
video.setAttribute('preload', 'auto');
video.addEventListener('loadeddata', function() {
const canvas = document.createElement('canvas'),
width = video.width,
height = video.height;
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, width, height);
const dataURL = canvas.toDataURL('image/jpeg');
const file = that.dataURLtoFile(dataURL, '789.jpeg');
that.upload(file);
console.log(dataURL, file, '第一帧数据');
});
},
dataURLtoFile(dataurl, filename) {
const arr = dataurl.split(',');
const mime = arr[0].match(/:(.*?);/)[1];
const bstr = atob(arr[1]);
let n = bstr.length;
const u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new File([ u8arr ], filename, { type: mime });
},