Last active
February 2, 2017 01:04
-
-
Save enddynayn/b74eac61cf7612bbb4e002dc21d10121 to your computer and use it in GitHub Desktop.
video upload duration and dimensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script src="https://code.jquery.com/jquery-2.2.4.js"></script> | |
<form> | |
<input type="file" id="video"> | |
</form> | |
<div></div> | |
<div id="taco"></div> | |
<script> | |
$("#video").change(function(event) { | |
var file = event.target.files[0] | |
var reader = new FileReader(); | |
var video = document.createElement('video'); | |
var sizeInBytes = file.size; | |
var sizeInMB = (sizeInBytes / (1024*1024)).toFixed(2); | |
console.log('fize size', sizeInMB); | |
reader.readAsDataURL(file) | |
reader.onload = function(_file) { | |
video.preload = "metadata"; | |
video.src = _file.target.result | |
}; | |
video.addEventListener("loadedmetadata", function() { | |
document.querySelector("div") | |
.innerHTML = | |
"Duration: " + | |
video.duration + "s " + | |
"video-width: " + | |
video.videoWidth + | |
" video-height " + | |
video.videoHeight; | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment