Skip to content

Instantly share code, notes, and snippets.

@tyhenry
Created January 23, 2024 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyhenry/ace7973e230a4e80c98a307c1859291f to your computer and use it in GitHub Desktop.
Save tyhenry/ace7973e230a4e80c98a307c1859291f to your computer and use it in GitHub Desktop.
Get metadata on MP4 video using mp4box.js
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