Skip to content

Instantly share code, notes, and snippets.

@enddynayn
Last active February 2, 2017 01:04
Show Gist options
  • Save enddynayn/b74eac61cf7612bbb4e002dc21d10121 to your computer and use it in GitHub Desktop.
Save enddynayn/b74eac61cf7612bbb4e002dc21d10121 to your computer and use it in GitHub Desktop.
video upload duration and dimensions
<!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