JavaScript FLV Parser: Parse and extract information from FLV 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: 58 All time: 489 This week: 4Up
Version License JavaScript version Categories
flvinfo 1.0Custom (specified...5Audio, Video, Parsers
Description 

Author

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

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

Innovation Award
JavaScript Programming Innovation award nominee
June 2016
Number 2


Prize: One ebook of choice by Packt
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 Flash 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, 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> <html> <head> <title>Test</title> </head> <body> <!-- Make a file input for you to select an FLV --> <center> <input type="file"> <!--br> Mode : <input id="toggle" type="button" value="Complete"--> <br> <textarea id="out" rows="40" cols="120">And then ? Choose one FLV file : </textarea> </center> <script src="FLVInfo.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 FLV Infos :\n"; info.text += "-------------------\n"; if (info.parseMetaDataBREAK){ info.text = "MetaDataParsing has been broken :\n"; } if (info.parseFlagsBREAK){ info.text = "BEWARE : FLV parsing has been broken and factor 2 is supposed\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 += "Version FLV : "+info.FLVVers+"\n"; info.dureeS = (info.lastStampTime - info.firstStampTime) / 1000; info.text += "Duration : " + duree(info.dureeS) + "\n"; var Gbitrate = 0; Gbitrate = (info.AudionbB + info.VideonbB) * 8 / info.dureeS; // kbps info.text += "Global bitrate : " + humanBitrate(Gbitrate) + "\n"; if (info.onMetaData.metadatacreator){ info.text += "Creator : " + info.onMetaData.metadatacreator + "\n"; } var tot = 0; if (info.AudionbB > 0) tot += 1; if (info.VideonbB > 0) tot += 1; info.text += "Count of streams : " + tot + "\n"; info.text += "\n"; if (info.VideonbB > 0){ info.text += "Video Track Id : " + info.VideoCodecId + "\n"; info.text += "Video Codec : " + info.VideoCodec; if (info.onMetaData.videocodecid){ if (isNaN(info.onMetaData.videocodecid)){ info.text += " (" + info.onMetaData.videocodecid + ")"; } } info.text += "\n"; info.text += "Size = " + humanFileSize(info.VideonbB) + "\n"; info.text += "Bitrate : " + humanBitrate(info.VideonbB * 8 / info.dureeS) + "\n"; if (info.onMetaData.framerate){ info.text += "Framerate : " + (info.onMetaData.framerate * info.factor) + " FPS\n"; } else { tot = Math.round(info.VideoTagsCount / (info.lastStampTime - info.firstStampTime)) / 1000; info.text += "Framerate : " + tot + " FPS (*)\n"; } if (info.onMetaData.width){ info.text += "Width : " + (info.onMetaData.width * info.factor) + "\n"; info.text += "Heidth : " + (info.onMetaData.height * info.factor) + "\n"; } info.text += "\n"; } if (info.AudionbB > 0){ info.text += "Audio Track Id : " + info.AudioCodecId + "\n"; info.text += "Audio Codec : " + info.AudioFormat; if (info.onMetaData.audiocodecid){ if (isNaN(info.onMetaData.audiocodecid)){ info.text += " (" + info.onMetaData.audiocodecid + ")"; } } info.text += "\n"; info.text += "Size = " + humanFileSize(info.AudionbB) + "\n"; info.text += "Bitrate : " + humanBitrate(info.AudionbB * 8 / info.dureeS) + "\n"; if (info.AudioFormat == 'AAC'){ info.text += "Profile : " + info.modeAAC + "\n"; info.text += "Count of channels : " + info.AACnbChannels + " (" + info.AACConfigChannels + ")\n"; if (info.onMetaData.audiosamplerate){ info.text += "Sampling : " + (info.factor * info.onMetaData.audiosamplerate / 1000) + " kHz\n"; } else { info.text += "Sampling : " + (info.AudioSampling) + " kHz (*)\n"; } } else { tot = 1; if (info.AudioMode == "stereo"){ tot =2; } info.text += "Count of channels : " + tot + "\n"; info.text += "Mode : " + info.AudioMode + "\n"; info.text += "Sampling : " + (info.AudioSampling) + " kHz\n"; } } return info.text; } document.querySelector('input[type="file"]').onchange = function(e) { // video/x-flv flv(this.files[0], function(err, info) { if (err) { //console.log('error : ' + err); sortie_texte = err; document.querySelector('#out').innerHTML = ""; document.querySelector('#out').innerHTML = sortie_texte; } 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

FLVInfo.js

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

Dependances : null

Usage :

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

importScripts('FLVInfo.js');                                              <-- or FLVInfo_min.js -->                                        
(in worker)

How use it :

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

FLVInfo 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 ! Try with short files because FLV parse the totality of the file. So, more big is the fie, more time to do the job !

Examples :


for a single file and no worker : index.html
for multiple files and worker   : indexw.html

Try it ?

http://aroug.eu/FLVInfo/   (multiple + worker + use FLVInfo.min.js)    

  Files folder image Files (7)  
File Role Description
Plain text file FLVInfo.js Class Main Class
Plain text file FLVInfo_min.js Class Main class minified
Accessible without login Plain text file index.html Example Example single file
Accessible without login Plain text file indexw.html Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file workerFLV.js Example Main class worker

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