Check if a Buffer/Uint8Array is a MP4 video
$ npm install --save is-mp4
$ bower install --save is-mp4
$ component install deepak1556/is-mp4
var readChunk = require('read-chunk'); // npm install read-chunk
var isMP4 = require('is-mp4');
var buffer = readChunk.sync('bigbuckbunny.mp4', 0, 8);
isMP4(buffer);
//=> true
var xhr = new XMLHttpRequest();
xhr.open('GET', 'bigbuckbunny.mp4');
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
isMP4(new Uint8Array(this.response));
//=> true
};
xhr.send();
Accepts a Buffer (Node.js) or Uint8Array.
It only needs the first 8 bytes.