JS 上传文件--获取视频文件宽高
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<input type="file" id="fileButton">
<script>
fileButton.addEventListener('change', evt => {
const file = fileButton.files[0]
const url = URL.createObjectURL(file)
const video = document.createElement('video')
video.onloadedmetadata = evt => {
// Revoke when you don't need the url any more to release any reference
URL.revokeObjectURL(url)
console.log(video.videoWidth, video.videoHeight)
}
video.src = url
video.load() // fetches metadata
})
</script>
</body>
</html>