"use strict";(function(){var root=this;var WebMGL={Video:WebMGLVideo,fromImageArray:function(images,fps){return toWebM(images.map((function(image){var webp=parseWebP(parseRIFF(root.atob(image.slice(23))));webp.duration=1e3/fps;return webp})))},toWebM:toWebM};var atob=window&&window.atob?window.atob:require("atob");if(typeof module!=="undefined"&&module.exports){module.exports=WebMGL}else{root.WebMGL=WebMGL}function WebMGLError(message){return new Error("[WebMGL] "+message)}function toWebM(frames){var info=checkFrames(frames);var counter=0;var EBML=[{id:440786851,data:[{data:1,id:17030},{data:1,id:17143},{data:4,id:17138},{data:8,id:17139},{data:"webm",id:17026},{data:2,id:17031},{data:2,id:17029}]},{id:408125543,data:[{id:357149030,data:[{data:1e6,id:2807729},{data:"whammy",id:19840},{data:"whammy",id:22337},{data:doubleToString(info.duration),id:17545}]},{id:374648427,data:[{id:174,data:[{data:1,id:215},{data:1,id:25541},{data:0,id:156},{data:"und",id:2274716},{data:"V_VP8",id:134},{data:"VP8",id:2459272},{data:1,id:131},{id:224,data:[{data:info.width,id:176},{data:info.height,id:186}]}]}]},{id:524531317,data:[{data:0,id:231}].concat(frames.map((function(webp){var block=makeSimpleBlock({discardable:0,frame:webp.data.slice(webp.data.indexOf("*")-3),invisible:0,keyframe:1,lacing:0,trackNum:1,timecode:Math.round(counter)});counter+=webp.duration;return{data:block,id:163}})))}]}];return generateEBML(EBML)}function checkFrames(frames){var width=frames[0].width;var height=frames[0].height;var duration=frames[0].duration;for(var i=1;i0){parts.push(num&255);num=num>>8}return new Uint8Array(parts.reverse())}function strToBuffer(str){var arr=new Uint8Array(str.length);for(var i=0;i127){throw WebMGLError("TrackNumber > 127 not supported")}var out=[data.trackNum|128,data.timecode>>8,data.timecode&255,flags].map((function(e){return String.fromCharCode(e)})).join("")+data.frame;return out}function parseWebP(riff){var VP8=riff.RIFF[0].WEBP[0];var frame_start=VP8.indexOf("*");for(var i=0,c=[];i<4;i++)c[i]=VP8.charCodeAt(frame_start+3+i);var width,height,tmp;tmp=c[1]<<8|c[0];width=tmp&16383;tmp=c[3]<<8|c[2];height=tmp&16383;return{width:width,height:height,data:VP8,riff:riff}}function parseRIFF(string){var offset=0;var chunks={};while(offset