JS 获取视频的时长、宽高
选择一个文件上传,获取视频的时长、宽高
<!DOCTYPE html>
<html lang="cmn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>获取视频的时长、宽高</title>
</head>
<body>
<input type="file" id="input-a">
<script>
var uploadFile = "";
document.getElementById("input-a").addEventListener('change', function () {
uploadFile = this.files[0];
var video = document.createElement('video')
video.preload = 'metadata'
video.src = window.URL.createObjectURL(uploadFile);
video.onloadedmetadata = function () {
console.log("时长:", video.duration);
console.log("宽度:", video.videoWidth);
console.log("高度:", video.videoHeight);
}
});
</script>
</body>
</html>