JavaScript AVI Parser: Parse and extract information from AVI 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
StarStarStarStar 66%Total: 78 All time: 461 This week: 4Up
Version License JavaScript version Categories
aviinfo 1.0Custom (specified...5Audio, Video, Parsers
Description 

Author

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

It can take the URL or selected file of a AVI 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, indexation, duration, bitrate, creator, codecs, size, samples, language, frame rate, width height, color depth, etc..

Innovation Award
JavaScript Programming Innovation award nominee
April 2016
Number 5
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 MP4 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> <html> <head> <title>Test</title> </head> <body> <!-- Make a file input for you to select an AVI --> <center> <input type="file"> <br> <textarea id="out" rows="40" cols="120">And then ? Choose yours AVI Files ! </textarea> </center> <!-- Include MP$.js --> <script src="AVIInfo.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> function duree(s) { function onetotwo(Pint) { if (Pint < 10) { return '0' + Pint.toString(); } else { return Pint.toString(); } } function onetothree(Pint) { if (Pint < 10) { return '00' + Pint.toString(); } else { if (Pint < 100) { return '0' + Pint.toString(); } else { return Pint.toString(); } } } var out = ''; var lhh = ''; var lmn = ''; var lss = ''; var lms = ''; lhh = Math.floor(s / 3600); lmn = Math.floor((s - lhh * 3600) / 60); lss = Math.floor(s - lhh * 3600 - lmn * 60); lms = Math.ceil((s - lhh * 3600 - lmn * 60 - lss) * 1000); if (lhh > 0) { lhh = lhh.toString() + ":"; out = lhh; } if (lmn > 0) { if (out.length == 0) { out = lmn.toString() + ":"; } else { out = out + onetotwo(lmn) + ":"; } } else { if (out.length > 0) { out = out + "00:"; } } if (lss > 0) { if (out.length == 0) { out = lss.toString(); } else { out = out + onetotwo(lss); } } else { if (out.length == 0) { out = "0"; } else { out = out + "00"; } } if (lms != 0) { out = out + '.' + onetothree(lms); } return out; } function humanFileSize(size) { var i = Math.floor(Math.log(size) / Math.log(1024)); return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['o', 'ko', 'Mo', 'Go', 'To'][i]; }; function humanBitrate(size) { var i = Math.floor(Math.log(size) / Math.log(1024)); return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['bps', 'kbps', 'Mbps', 'Gbps', 'Tbps'][i]; }; function human_reading(info) { info.text = "ArouG's AVI Infos :\n"; info.text += "-------------------\n"; info.text += "File : " + info.filename + "\n"; var d= new Date(info.filedate); info.text += "Date : " + (d.getFullYear()) + '/' + (d.getMonth() + 1) + '/' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + "\n"; info.text += "Size : " + humanFileSize(info.filesize) + "\n"; info.text += "Format : AVI \n"; if (info.isOpenDML){ info.text += "Format profile : OPENDML\n"; } if (info.AVIF_HASINDEX) { info.text += "Indexed : Yes\n"; } else { info.text += "Indexed : No\n"; } info.text += "Duration : " + duree(info.dureeS) + "\n"; var DataSize = 0; for (var i = 0; i < info.tracks.length; i++) DataSize += info.tracks[i].Totalsize; GlobBitrate = 8 * DataSize / info.dureeS; info.text += "Global bitrate : " + humanBitrate(GlobBitrate) + "\n"; if (info.swft){ if (info.swft.offset > 0) { info.text += "Creator : " + info.swft.name + "\n"; } } info.text += "Count of streams : " + info.dwStreams + "\n"; info.text += "\n"; for (var i = 0; i < info.tracks.length; i++) { if (info.tracks[i].strh.Typet == 'vids'){ info.text += "Video :\n"; } if (info.tracks[i].strh.Typet == 'auds'){ info.text += "Audio :\n"; } if (info.tracks[i].strh.Typet == 'txts'){ info.text += "Subtitles :\n"; } info.text += "Track number " + (i+1) + "\n"; info.text += "Size : " + humanFileSize(info.tracks[i].Totalsize) + "\n"; info.text += "Count of samples : " + info.tracks[i].strh.dwLength + "\n"; info.text += "Duration : " + duree(info.tracks[i].strh.dureeS) + "\n"; var tmp = 8 * info.tracks[i].Totalsize / info.tracks[i].strh.dureeS; if ((info.tracks[i].strh.Typet == 'vids') || (info.tracks[i].strh.Typet == 'auds')) { info.text += "Global Bitrate : " + humanBitrate(tmp) + "\n"; } if (info.tracks[i].strh.wLanguage != "```"){ info.text += "Langage : " + info.tracks[i].strh.wLanguage + "\n"; } if (info.tracks[i].strh.Typet == 'vids') { tmp = Math.ceil(100 * info.tracks[i].strh.dwLength / info.tracks[i].strh.dureeS) / 100; info.text += "Framerate : " + tmp + " FPS\n"; info.text += "Width : " + Math.ceil(info.dwWidth) + "\n"; info.text += "Heidth : " + Math.ceil(info.dwHeight) + "\n"; info.text += "Codec Video more info :\n"; if (info.tracks[i].strh.handler) { info.text += "handler : " + info.tracks[i].strh.handler + "\n"; } info.text += "Compressor : " + info.tracks[i].strf.biCompression + "\n"; info.text += "Depth (number of bits / pixel) : " + info.tracks[i].strf.biBitCount + "\n"; } if (info.tracks[i].strh.Typet == 'auds') { info.text += "Codec Audio more info :\n"; info.text += "handler : 0x" + info.tracks[i].strf.wFormatTag.toString(16).toUpperCase() + "\n"; info.text += "Compressor : " + info.tracks[i].audiocodec[0] + "\n"; info.text += "Count of channels : " + info.tracks[i].strf.nChannels + "\n"; info.text += "SampleRate : " + info.tracks[i].strf.nSamplesPerSec + "\n"; } info.text += "\n"; } return info.text; } document.querySelector('input[type="file"]').onchange = function(e) { avi(this.files[0], function(err, info) { if (err) { console.log('error : ' + err); } else { sortie_texte = human_reading(info); console.log(JSON.stringify(info)); document.querySelector('#out').innerHTML = ""; document.querySelector('#out').innerHTML = sortie_texte; } }); } </script> </body> </html>

Details

AVIInfo

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

Dependances : null

Usage :

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

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

How use it : 2 ways :

1

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

2 -------------------------------------------------------------------------------------

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

where 'withmovis' is false or true (false by default or by ignore). When withmovis is true, AVIInfo will calculate sizes by reading each size of each frame. It's more exact but more slower

AVIInfo 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 a single file and no worker : index.html
for multiple files and worker   : indexw.html

Try it ?

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

PS : AVI files should have troubles (http://www.virtualdub.org/blog/pivot/entry.php?id=25 (common problems in 'bad AVI files')) In these cases, you should use some tool to repair it. I use AviDemux (https://fr.wikipedia.org/wiki/Avidemux) ;-)


  Files folder image Files (6)  
File Role Description
Plain text file AVIInfo.js Class main class
Accessible without login Plain text file index.html Example example without worker
Accessible without login Plain text file indexw.html Example example with worker
Accessible without login Plain text file LICENSE Lic. license
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file workerAVI.js Appl. main class worker

 Version Control Unique User Downloads Download Rankings  
 100%
Total:78
This week:0
All time:461
This week:4Up
 User Ratings  
 
 All time
Utility:83%StarStarStarStarStar
Consistency:83%StarStarStarStarStar
Documentation:83%StarStarStarStarStar
Examples:83%StarStarStarStarStar
Tests:-
Videos:-
Overall:66%StarStarStarStar
Rank:25