Created
January 23, 2024 22:54
-
-
Save tyhenry/ace7973e230a4e80c98a307c1859291f to your computer and use it in GitHub Desktop.
Get metadata on MP4 video using mp4box.js
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
import * as MP4Box from 'mp4box'; | |
// returns a Promise that resolves to video metadata using MP4Box.js | |
export const getMp4Info = async (videoBlob) => { | |
const mp4boxfile = MP4Box.createFile(); | |
return new Promise((resolve, reject) => { | |
mp4boxfile.onReady = function (info) { | |
resolve(info); | |
}; | |
mp4boxfile.onError = function (e) { | |
reject(e); | |
} | |
videoBlob.arrayBuffer().then((buffer) => { | |
buffer.fileStart = 0; | |
mp4boxfile.appendBuffer(buffer); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment