JavaScript MP4 Parser: Parse and extract information from MP4 video files

Recommend this page to a friend!
     
  Info   Example   View files Files   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 101 All time: 410 This week: 4Up
Version License JavaScript version Categories
mp4info 1.2Custom (specified...5Audio, Video, Parsers
Description 

Author

This object can parse and extract information from MP4 video files.

It can take the URL or selected file of a MP4 video and read it to parse its information.

The object takes a callback function to handle errors, or if it succeed it calls another callback function passing the parse information in easy to process data structure.

It returns information about the audio and video streams like the format, compatibility, progressivity, duration, bitrate, creator, codecs, size, samples, language, frame rate, widthm height, color depth, etc..

Innovation Award
JavaScript Programming Innovation award nominee
April 2016
Number 3


Prize: One downloadable e-book of choice by O'Reilly
Many sites need to take videos uploaded by the users. When a user uploads a video he may not be certain if that is the right video that he wants to upload and may only realize that after a few hours when the video finishes uploading.

This object is one of several others that can help addressing this issue by being able to parse and extract data from an MP4 video even before the user uploads it. This way the user can confirm if the video was the right was that he wanted to upload.

Other versions of this package exist for parsing AVI and MKV video files.

Manuel Lemos
Picture of Dantigny francois
  Performance   Level  
Name: Dantigny francois <contact>
Classes: 5 packages by
Country: France France
Age: ???
All time rank: 1307 in France France
Week rank: 2 Up1 in France France Up
Innovation award
Innovation award
Nominee: 5x

Example

<!DOCTYPE html> <meta charset="UTF-8"> <html> <head> <title>Test</title> <style type="text/css"> #inp{ display : inline; } #opt{ display : none; } #isIE{ display : none; } </style> <script type="text/javascript"> var ind=0; let indarrived = 0; let res=[]; let listeficname=[]; // 4 let pour progress let maxBar = 200; let currentBar = 0; let progressBar; let intervalId; //let timedeb, timeend; // pour évaluation de l'efficacité function change_ind(t) { document.querySelector('#out').innerHTML = ""; document.querySelector('#out').innerHTML = res[t]; } function init(){ /* ------------------------------ Interface ProgressBar ------------------------------ */ let initialisation = function() { progressBar = document.getElementById( "progressBar" ); progressBar.value = currentBar; progressBar.max = maxBar; } let displayBar = function() { //currentBar++; progressBar.value = currentBar; } intervalId = setInterval( displayBar , 100 ); // dysplayBar est appelée toutes les 100 millisecondes initialisation(); /* -------------------------------------------------- Détection d'Internet Explorer : Edge fonctionne !! -------------------------------------------------- */ let ua = window.navigator.userAgent; let msie = ua.indexOf('MSIE '); let trident = ua.indexOf('Trident/'); if ((msie > 0) || (trident > 0)){ document.getElementById('inp').style.visibility = 'hidden'; document.getElementById('out').style.visibility = 'hidden'; document.getElementById('isIE').style.display = 'inline'; } /* -------------------------------------------- corps principal : le(s) Worker(s) ------------------------------------------- */ document.querySelector('#inp').onchange = function(e) { let fichiersInput = document.querySelector("#inp"); let fichiers = fichiersInput.files; let nbFichiers = fichiers.length; let tmp = {}; //timedeb = Date.now(); // pour évaluation de l'efficacité for (let k=0; k<nbFichiers; k++){ res.push(''); new_element = new Option("", k, false, true); document.getElementById("opt").options[document.getElementById("opt").options.length] = new_element; } // Envoit les fichiers de manière synchrone les uns derrières les autres while (ind < nbFichiers){ listeficname.push(fichiers[ind].name); document.querySelector("#opt").options[ind].text=fichiers[ind].name; let MP4worker = new Worker('workerMP4.js'); // Retour du Worker MP4worker.addEventListener('message', function(e) { if (e.data.data != 'nop'){ // pour la progressBar : 2 lignes ci-dessous indarrived++; currentBar = (indarrived / nbFichiers) * maxBar; res[e.data.num]=e.data.data; } else { // pour la progressBar : 2 lignes ci-dessous indarrived++; currentBar = (indarrived / nbFichiers) * maxBar; tmp.data=listeficname[e.data.num]+" isn't a MP4 file !"; res[e.data.num]=tmp.data; } MP4worker.terminate(); if (indarrived == nbFichiers){ displayBar(); clearInterval(intervalId); document.getElementById("inp").style.display="none"; document.querySelector("#opt").selectedIndex=0; document.querySelector("#opt").style.display="block"; document.querySelector('#out').innerHTML = ""; document.querySelector('#out').innerHTML = res[0]; //timeend = Date.now(); // pour évaluation de l'efficacité //let duration = timeend - timedeb; //alert('duration = '+duration); } }, false); MP4worker.postMessage([fichiers[ind],ind]); // il en reste ? Envoit le suivant !! ind++; } } } </script> </head> <body onload="init()"> <center> <p><progress id="progressBar"></progress></p> <p id="isIE">Microsoft Internet not allowed ... Sorry !</p> <input id="inp" type="file" multiple> <select size="1" id="opt" onchange="change_ind(document.getElementById('opt').options.selectedIndex)"></select> <br> <textarea id="out" rows="40" cols="120">And then ? Choose some MP4 files (.MP4, .M4V, ... )</textarea> </center> </body> </html>

Details

MP4Info

Sort of "Mediainfo" for MP4 Files - little MP4Parser (just for main technics information about the file)

Dependances : null

Usage :

<script src="MP4Info.js" type="text/javascript" charset="utf-8"></script> 
(in single file .html)

importScripts('MP4Info.js');                                              
(in worker)

How use it :

 
        mp4(this.files[0], function(err, info) {
            if (err) {
                .....
            } else {
                sortie_texte = human_reading(info);
                ....
            }
        }); 

MP4Info return an object structured (named 'info') wich contains a lot of technicals information about the file. If we want to read this informations, we need to make them readable. So human_reading is here !

Examples :


for multiple or single file and no worker : index.html

Try it ?

http://aroug.eu/MP4Info/   (multiple + worker)       

Bugs :

This version use await/async so Microsoft Internet is forbiden ... but Edge run :-)
More : workers (multiple files) work now in kind of parallelism (not one after one)

  Files folder image Files (6)  
File Role Description
Accessible without login Plain text file index.html Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Plain text file MP4Info.js Class Class source
Plain text file MP4Infomin.js Class Class source
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file workerMP4.js Aux. Auxiliary script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:101
This week:0
All time:410
This week:4Up