Created
April 5, 2020 07:52
-
-
Save numToStr/8469c8ac17deeecd3f7d0a077b6af432 to your computer and use it in GitHub Desktop.
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
const fs = require("fs").promises; | |
const buff = Buffer.alloc(100); | |
const header = Buffer.from("mvhd"); | |
async function length() { | |
const file = await fs.open("video.mp4", "r"); | |
const { buffer } = await file.read(buff, 0, 100, 0); | |
await file.close(); | |
const start = buffer.indexOf(header) + 17; | |
const timeScale = buffer.readUInt32BE(start); | |
const duration = buffer.readUInt32BE(start + 4); | |
const audioLength = Math.floor((duration / timeScale) * 1000) / 1000; | |
console.log(buffer, header, start, timeScale, duration, audioLength); | |
} | |
length(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment