diff --git a/.gitignore b/.gitignore index 20490bc..aaf41d8 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,6 @@ tests/*/_extensions # .css.map (can be generated manually from .scss file) _extensions/closeread/closeread.css.map + +# images generated for video demo +docs/gallery/demos/videos/image*.png diff --git a/_extensions/closeread/closeread.css b/_extensions/closeread/closeread.css index 5092d2d..7cf8f78 100644 --- a/_extensions/closeread/closeread.css +++ b/_extensions/closeread/closeread.css @@ -85,6 +85,25 @@ color: rgb(0, 0, 0); transition: color 0.7s linear; } +.cr-section .sticky-col .sticky-col-stack .scale-to-cover, +.cr-section .sticky-col .sticky-col-stack .sticky:has(.scale-to-cover) { + width: 100%; + height: 100%; +} +.cr-section .sticky-col .sticky-col-stack .scale-to-cover > p, +.cr-section .sticky-col .sticky-col-stack .sticky:has(.scale-to-cover) > p { + margin: 0; +} +.cr-section .sticky-col .sticky-col-stack .scale-to-cover *, +.cr-section .sticky-col .sticky-col-stack .sticky:has(.scale-to-cover) * { + width: 100%; + height: 100%; +} +.cr-section .sticky-col .sticky-col-stack .scale-to-cover :is(video, img, iframe), .cr-section .sticky-col .sticky-col-stack .scale-to-cover:is(video, img, iframe), +.cr-section .sticky-col .sticky-col-stack .sticky:has(.scale-to-cover) :is(video, img, iframe), +.cr-section .sticky-col .sticky-col-stack .sticky:has(.scale-to-cover):is(video, img, iframe) { + object-fit: cover; +} /* mobile sizing (bootstrap: xs) is always overlay-center */ @media (max-width: 575.98px) { diff --git a/_extensions/closeread/closeread.js b/_extensions/closeread/closeread.js index 97a6ee5..1aed8e1 100644 --- a/_extensions/closeread/closeread.js +++ b/_extensions/closeread/closeread.js @@ -60,7 +60,7 @@ document.addEventListener("DOMContentLoaded", () => { ojsProgressBlock?.define("crProgressBlock", 0); if (ojsModule === undefined) { - console.error("Warning: Quarto OJS module not found") + console.warn("Warning: Quarto OJS module not found") } // expand hlz option into highlight and zoom-to @@ -70,6 +70,13 @@ document.addEventListener("DOMContentLoaded", () => { trigger.setAttribute('data-zoom-to', hlzValue); trigger.setAttribute('data-highlight', hlzValue); }); + + // initialise scrolly videos + let scrollyVideo = new ScrollyVideo({ + scrollyVideoContainer: "cr-rayshader", + src: "rayshader.mp4", + trackScroll: false + }) // collect all sticky elements const allStickies = Array.from(document.querySelectorAll(".sticky")); @@ -103,6 +110,9 @@ document.addEventListener("DOMContentLoaded", () => { function crTriggerStepProgress(trigger) { ojsTriggerProgress?.define("crTriggerProgress", trigger.progress) ojsDirection?.define("crDirection", trigger.direction) + scrollyVideo.setVideoPercentage(trigger.progress, { + transitionSpeed: 12, easing: t => +t // linear easing + }) } function crProgressStepEnter(progressBlock) { @@ -195,6 +205,7 @@ function updateStickies(allStickies, focusedStickyName, trigger) { // apply additional effects transformSticky(focusedSticky, trigger.element); highlightSpans(focusedSticky, trigger.element); + controlVideo(focusedSticky, trigger.element); if ( // scale-to-fill only takes effect if there are no other transforms focusedSticky.classList.contains("scale-to-fill") && @@ -410,6 +421,47 @@ function scaleToFill(el, paddingX = 75, paddingY = 50) { `matrix(${scale}, 0, 0, ${scale}, 0, ${centerDeltaY})`) } +//==============// +// Videos // +//==============// +// Execute different methods on video elements such as play() and pause(). +function controlVideo(focusedSticky, triggerEl) { + + console.log("Controlling video ", focusedSticky, "from trigger", triggerEl) + + // get any video methods + const videoAttributes = Array.from(triggerEl.attributes).filter(attr => + /^data-.*-video$/.test(attr.name)); + + // exit function if there's no video method + if (videoAttributes.length == 0) { + return; + } + + if (videoAttributes.length > 1) { + console.warn(`Multiple video method are called by a single trigger. Applying only the first one, ${videoAttributes[0].name}`) + } + + // get video element + const videoEl = focusedSticky.querySelector("video"); + + // execute method on video + if (videoAttributes[0].value !== "false") { + const attributeName = videoAttributes[0].name; + + // extract method from attribute name + const methodName = attributeName.replace(/^data-/, "").replace(/-video$/, ""); + + // check if the method exists on videoEl, then call it + if (typeof videoEl[methodName] === "function") { + videoEl[methodName](); + } else { + console.log(`Method ${methodName} does not exist for a video element.`); + } + } +} + + /* getBooleanConfig: checks for a with named attribute `cr-[metaFlag]` and returns true if its value is "true" or false otherwise */ function getBooleanConfig(metaFlag) { diff --git a/_extensions/closeread/closeread.lua b/_extensions/closeread/closeread.lua index f263498..a4f7642 100644 --- a/_extensions/closeread/closeread.lua +++ b/_extensions/closeread/closeread.lua @@ -543,6 +543,12 @@ quarto.doc.add_html_dependency({ scripts = {"closeread.js"} }) +quarto.doc.add_html_dependency({ + name = "scrollyvideo", + version = "0.0.23", + scripts = {"scrollyvideo.js"} +}) + --=============-- -- Run Filters -- diff --git a/_extensions/closeread/closeread.scss b/_extensions/closeread/closeread.scss index 7f3f138..57e98ea 100644 --- a/_extensions/closeread/closeread.scss +++ b/_extensions/closeread/closeread.scss @@ -140,6 +140,26 @@ } } } + + .scale-to-cover, + .sticky:has(.scale-to-cover) { + width: 100%; + height: 100%; + + > p { + margin: 0; + } + + * { + width: 100%; + height: 100%; + } + + :is(video, img, iframe), + &:is(video, img, iframe) { + object-fit: cover; + } + } } } } diff --git a/_extensions/closeread/scrollyvideo.js b/_extensions/closeread/scrollyvideo.js new file mode 100644 index 0000000..7159808 --- /dev/null +++ b/_extensions/closeread/scrollyvideo.js @@ -0,0 +1,7 @@ +/** + * Skipped minification because the original files appears to be already minified. + * Original file: /npm/scrolly-video@0.0.23/dist/scrolly-video.js + * + * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files + */ +var ScrollyVideo=function(){"use strict";var t,e,i="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},s={exports:{}};t=s,e=s.exports,function(i,s){var r="function",n="undefined",a="object",o="string",h="model",d="name",l="type",p="vendor",f="version",u="architecture",c="console",m="mobile",_="tablet",g="smarttv",y="wearable",b="embedded",v="Amazon",w="Apple",S="ASUS",U="BlackBerry",x="Browser",E="Chrome",B="Firefox",T="Google",A="Huawei",z="LG",k="Microsoft",I="Motorola",C="Opera",P="Samsung",F="Sharp",L="Sony",D="Xiaomi",R="Zebra",N="Facebook",M=function(t){for(var e={},i=0;i0?2===h.length?typeof h[1]==r?this[h[0]]=h[1].call(this,l):this[h[0]]=h[1]:3===h.length?typeof h[1]!==r||h[1].exec&&h[1].test?this[h[0]]=l?l.replace(h[1],h[2]):s:this[h[0]]=l?h[1].call(this,l,h[2]):s:4===h.length&&(this[h[0]]=l?h[3].call(this,l.replace(h[1],h[2])):s):this[h]=l||s;p+=2}},Y=function(t,e){for(var i in e)if(typeof e[i]===a&&e[i].length>0){for(var r=0;r350?H(t,350):t,this},this.setUA(r),this};W.VERSION="1.0.33",W.BROWSER=M([d,f,"major"]),W.CPU=M([u]),W.DEVICE=M([h,p,l,c,m,g,_,y,b]),W.ENGINE=W.OS=M([d,f]),t.exports&&(e=t.exports=W),e.UAParser=W;var K=typeof i!==n&&(i.jQuery||i.Zepto);if(K&&!K.ua){var X=new W;K.ua=X.getResult(),K.ua.get=function(){return X.getUA()},K.ua.set=function(t){X.setUA(t);var e=X.getResult();for(var i in e)K.ua[i]=e[i]}}}("object"==typeof window?window:i);var r=s.exports,n={};!function(t){var e,i,s,r=(e=new Date,i=4,s={setLogLevel:function(t){i=t==this.debug?1:t==this.info?2:t==this.warn?3:(this.error,4)},debug:function(t,s){void 0===console.debug&&(console.debug=console.log),1>=i&&console.debug("["+r.getDurationString(new Date-e,1e3)+"]","["+t+"]",s)},log:function(t,e){this.debug(t.msg)},info:function(t,s){2>=i&&console.info("["+r.getDurationString(new Date-e,1e3)+"]","["+t+"]",s)},warn:function(t,s){3>=i&&console.warn("["+r.getDurationString(new Date-e,1e3)+"]","["+t+"]",s)},error:function(t,s){4>=i&&console.error("["+r.getDurationString(new Date-e,1e3)+"]","["+t+"]",s)}},s);r.getDurationString=function(t,e){var i;function s(t,e){for(var i=(""+t).split(".");i[0].length0){for(var i="",s=0;s0&&(i+=","),i+="["+r.getDurationString(t.start(s))+","+r.getDurationString(t.end(s))+"]";return i}return"(empty)"},t.Log=r;var n=function(t){if(!(t instanceof ArrayBuffer))throw"Needs an array buffer";this.buffer=t,this.dataview=new DataView(t),this.position=0};n.prototype.getPosition=function(){return this.position},n.prototype.getEndPosition=function(){return this.buffer.byteLength},n.prototype.getLength=function(){return this.buffer.byteLength},n.prototype.seek=function(t){var e=Math.max(0,Math.min(this.buffer.byteLength,t));return this.position=isNaN(e)||!isFinite(e)?0:e,!0},n.prototype.isEos=function(){return this.getPosition()>=this.getEndPosition()},n.prototype.readAnyInt=function(t,e){var i=0;if(this.position+t<=this.buffer.byteLength){switch(t){case 1:i=e?this.dataview.getInt8(this.position):this.dataview.getUint8(this.position);break;case 2:i=e?this.dataview.getInt16(this.position):this.dataview.getUint16(this.position);break;case 3:if(e)throw"No method for reading signed 24 bits values";i=this.dataview.getUint8(this.position)<<16,i|=this.dataview.getUint8(this.position+1)<<8,i|=this.dataview.getUint8(this.position+2);break;case 4:i=e?this.dataview.getInt32(this.position):this.dataview.getUint32(this.position);break;case 8:if(e)throw"No method for reading signed 64 bits values";i=this.dataview.getUint32(this.position)<<32,i|=this.dataview.getUint32(this.position+4);break;default:throw"readInt method not implemented for size: "+t}return this.position+=t,i}throw"Not enough bytes in buffer"},n.prototype.readUint8=function(){return this.readAnyInt(1,!1)},n.prototype.readUint16=function(){return this.readAnyInt(2,!1)},n.prototype.readUint24=function(){return this.readAnyInt(3,!1)},n.prototype.readUint32=function(){return this.readAnyInt(4,!1)},n.prototype.readUint64=function(){return this.readAnyInt(8,!1)},n.prototype.readString=function(t){if(this.position+t<=this.buffer.byteLength){for(var e="",i=0;ithis._byteLength&&(this._byteLength=e);else{for(i<1&&(i=1);e>i;)i*=2;var s=new ArrayBuffer(i),r=new Uint8Array(this._buffer);new Uint8Array(s,0,r.length).set(r),this.buffer=s,this._byteLength=e}}},a.prototype._trimAlloc=function(){if(this._byteLength!=this._buffer.byteLength){var t=new ArrayBuffer(this._byteLength),e=new Uint8Array(t),i=new Uint8Array(this._buffer,0,e.length);e.set(i),this.buffer=t}},a.BIG_ENDIAN=!1,a.LITTLE_ENDIAN=!0,a.prototype._byteLength=0,Object.defineProperty(a.prototype,"byteLength",{get:function(){return this._byteLength-this._byteOffset}}),Object.defineProperty(a.prototype,"buffer",{get:function(){return this._trimAlloc(),this._buffer},set:function(t){this._buffer=t,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._buffer.byteLength}}),Object.defineProperty(a.prototype,"byteOffset",{get:function(){return this._byteOffset},set:function(t){this._byteOffset=t,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._buffer.byteLength}}),Object.defineProperty(a.prototype,"dataView",{get:function(){return this._dataView},set:function(t){this._byteOffset=t.byteOffset,this._buffer=t.buffer,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._byteOffset+t.byteLength}}),a.prototype.seek=function(t){var e=Math.max(0,Math.min(this.byteLength,t));this.position=isNaN(e)||!isFinite(e)?0:e},a.prototype.isEof=function(){return this.position>=this._byteLength},a.prototype.mapUint8Array=function(t){this._realloc(1*t);var e=new Uint8Array(this._buffer,this.byteOffset+this.position,t);return this.position+=1*t,e},a.prototype.readInt32Array=function(t,e){t=null==t?this.byteLength-this.position/4:t;var i=new Int32Array(t);return a.memcpy(i.buffer,0,this.buffer,this.byteOffset+this.position,t*i.BYTES_PER_ELEMENT),a.arrayToNative(i,null==e?this.endianness:e),this.position+=i.byteLength,i},a.prototype.readInt16Array=function(t,e){t=null==t?this.byteLength-this.position/2:t;var i=new Int16Array(t);return a.memcpy(i.buffer,0,this.buffer,this.byteOffset+this.position,t*i.BYTES_PER_ELEMENT),a.arrayToNative(i,null==e?this.endianness:e),this.position+=i.byteLength,i},a.prototype.readInt8Array=function(t){t=null==t?this.byteLength-this.position:t;var e=new Int8Array(t);return a.memcpy(e.buffer,0,this.buffer,this.byteOffset+this.position,t*e.BYTES_PER_ELEMENT),this.position+=e.byteLength,e},a.prototype.readUint32Array=function(t,e){t=null==t?this.byteLength-this.position/4:t;var i=new Uint32Array(t);return a.memcpy(i.buffer,0,this.buffer,this.byteOffset+this.position,t*i.BYTES_PER_ELEMENT),a.arrayToNative(i,null==e?this.endianness:e),this.position+=i.byteLength,i},a.prototype.readUint16Array=function(t,e){t=null==t?this.byteLength-this.position/2:t;var i=new Uint16Array(t);return a.memcpy(i.buffer,0,this.buffer,this.byteOffset+this.position,t*i.BYTES_PER_ELEMENT),a.arrayToNative(i,null==e?this.endianness:e),this.position+=i.byteLength,i},a.prototype.readUint8Array=function(t){t=null==t?this.byteLength-this.position:t;var e=new Uint8Array(t);return a.memcpy(e.buffer,0,this.buffer,this.byteOffset+this.position,t*e.BYTES_PER_ELEMENT),this.position+=e.byteLength,e},a.prototype.readFloat64Array=function(t,e){t=null==t?this.byteLength-this.position/8:t;var i=new Float64Array(t);return a.memcpy(i.buffer,0,this.buffer,this.byteOffset+this.position,t*i.BYTES_PER_ELEMENT),a.arrayToNative(i,null==e?this.endianness:e),this.position+=i.byteLength,i},a.prototype.readFloat32Array=function(t,e){t=null==t?this.byteLength-this.position/4:t;var i=new Float32Array(t);return a.memcpy(i.buffer,0,this.buffer,this.byteOffset+this.position,t*i.BYTES_PER_ELEMENT),a.arrayToNative(i,null==e?this.endianness:e),this.position+=i.byteLength,i},a.prototype.readInt32=function(t){var e=this._dataView.getInt32(this.position,null==t?this.endianness:t);return this.position+=4,e},a.prototype.readInt16=function(t){var e=this._dataView.getInt16(this.position,null==t?this.endianness:t);return this.position+=2,e},a.prototype.readInt8=function(){var t=this._dataView.getInt8(this.position);return this.position+=1,t},a.prototype.readUint32=function(t){var e=this._dataView.getUint32(this.position,null==t?this.endianness:t);return this.position+=4,e},a.prototype.readUint16=function(t){var e=this._dataView.getUint16(this.position,null==t?this.endianness:t);return this.position+=2,e},a.prototype.readUint8=function(){var t=this._dataView.getUint8(this.position);return this.position+=1,t},a.prototype.readFloat32=function(t){var e=this._dataView.getFloat32(this.position,null==t?this.endianness:t);return this.position+=4,e},a.prototype.readFloat64=function(t){var e=this._dataView.getFloat64(this.position,null==t?this.endianness:t);return this.position+=8,e},a.endianness=new Int8Array(new Int16Array([1]).buffer)[0]>0,a.memcpy=function(t,e,i,s,r){var n=new Uint8Array(t,e,r),a=new Uint8Array(i,s,r);n.set(a)},a.arrayToNative=function(t,e){return e==this.endianness?t:this.flipArrayEndianness(t)},a.nativeToEndian=function(t,e){return this.endianness==e?t:this.flipArrayEndianness(t)},a.flipArrayEndianness=function(t){for(var e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),i=0;ir;s--,r++){var n=e[r];e[r]=e[s],e[s]=n}return t},a.prototype.failurePosition=0,String.fromCharCodeUint8=function(t){for(var e=[],i=0;i>16),this.writeUint8((65280&t)>>8),this.writeUint8(255&t)},a.prototype.adjustUint32=function(t,e){var i=this.position;this.seek(t),this.writeUint32(e),this.seek(i)},a.prototype.mapInt32Array=function(t,e){this._realloc(4*t);var i=new Int32Array(this._buffer,this.byteOffset+this.position,t);return a.arrayToNative(i,null==e?this.endianness:e),this.position+=4*t,i},a.prototype.mapInt16Array=function(t,e){this._realloc(2*t);var i=new Int16Array(this._buffer,this.byteOffset+this.position,t);return a.arrayToNative(i,null==e?this.endianness:e),this.position+=2*t,i},a.prototype.mapInt8Array=function(t){this._realloc(1*t);var e=new Int8Array(this._buffer,this.byteOffset+this.position,t);return this.position+=1*t,e},a.prototype.mapUint32Array=function(t,e){this._realloc(4*t);var i=new Uint32Array(this._buffer,this.byteOffset+this.position,t);return a.arrayToNative(i,null==e?this.endianness:e),this.position+=4*t,i},a.prototype.mapUint16Array=function(t,e){this._realloc(2*t);var i=new Uint16Array(this._buffer,this.byteOffset+this.position,t);return a.arrayToNative(i,null==e?this.endianness:e),this.position+=2*t,i},a.prototype.mapFloat64Array=function(t,e){this._realloc(8*t);var i=new Float64Array(this._buffer,this.byteOffset+this.position,t);return a.arrayToNative(i,null==e?this.endianness:e),this.position+=8*t,i},a.prototype.mapFloat32Array=function(t,e){this._realloc(4*t);var i=new Float32Array(this._buffer,this.byteOffset+this.position,t);return a.arrayToNative(i,null==e?this.endianness:e),this.position+=4*t,i};var h=function(t){this.buffers=[],this.bufferIndex=-1,t&&(this.insertBuffer(t),this.bufferIndex=0)};(h.prototype=new a(new ArrayBuffer,0,a.BIG_ENDIAN)).initialized=function(){var t;return this.bufferIndex>-1||(this.buffers.length>0?0===(t=this.buffers[0]).fileStart?(this.buffer=t,this.bufferIndex=0,r.debug("MultiBufferStream","Stream ready for parsing"),!0):(r.warn("MultiBufferStream","The first buffer should have a fileStart of 0"),this.logBufferLevel(),!1):(r.warn("MultiBufferStream","No buffer to start parsing from"),this.logBufferLevel(),!1))},ArrayBuffer.concat=function(t,e){r.debug("ArrayBuffer","Trying to create a new buffer of size: "+(t.byteLength+e.byteLength));var i=new Uint8Array(t.byteLength+e.byteLength);return i.set(new Uint8Array(t),0),i.set(new Uint8Array(e),t.byteLength),i.buffer},h.prototype.reduceBuffer=function(t,e,i){var s;return(s=new Uint8Array(i)).set(new Uint8Array(t,e,i)),s.buffer.fileStart=t.fileStart+e,s.buffer.usedBytes=0,s.buffer},h.prototype.insertBuffer=function(t){for(var e=!0,i=0;is.byteLength){this.buffers.splice(i,1),i--;continue}r.warn("MultiBufferStream","Buffer (fileStart: "+t.fileStart+" - Length: "+t.byteLength+") already appended, ignoring")}else t.fileStart+t.byteLength<=s.fileStart||(t=this.reduceBuffer(t,0,s.fileStart-t.fileStart)),r.debug("MultiBufferStream","Appending new buffer (fileStart: "+t.fileStart+" - Length: "+t.byteLength+")"),this.buffers.splice(i,0,t),0===i&&(this.buffer=t);e=!1;break}if(t.fileStart0)){e=!1;break}t=this.reduceBuffer(t,n,a)}}e&&(r.debug("MultiBufferStream","Appending new buffer (fileStart: "+t.fileStart+" - Length: "+t.byteLength+")"),this.buffers.push(t),0===i&&(this.buffer=t))},h.prototype.logBufferLevel=function(t){var e,i,s,n,a,o=[],h="";for(s=0,n=0,e=0;e0&&(h+=a.end-1+"]");var d=t?r.info:r.debug;0===this.buffers.length?d("MultiBufferStream","No more buffer in memory"):d("MultiBufferStream",this.buffers.length+" stored buffer(s) ("+s+"/"+n+" bytes), continuous ranges: "+h)},h.prototype.cleanBuffers=function(){var t,e;for(t=0;t"+this.buffer.byteLength+")"),!0}return!1}return!1},h.prototype.findPosition=function(t,e,i){var s,n=null,a=-1;for(s=!0===t?0:this.bufferIndex;s=e?(r.debug("MultiBufferStream","Found position in existing buffer #"+a),a):-1},h.prototype.findEndContiguousBuf=function(t){var e,i,s,r=void 0!==t?t:this.bufferIndex;if(i=this.buffers[r],this.buffers.length>r+1)for(e=r+1;e>3;return 31===s&&i.data.length>=2&&(s=32+((7&i.data[0])<<3)+((224&i.data[1])>>5)),s}return null},i.DecoderConfigDescriptor=function(t){i.Descriptor.call(this,4,t)},i.DecoderConfigDescriptor.prototype=new i.Descriptor,i.DecoderConfigDescriptor.prototype.parse=function(t){this.oti=t.readUint8(),this.streamType=t.readUint8(),this.bufferSize=t.readUint24(),this.maxBitrate=t.readUint32(),this.avgBitrate=t.readUint32(),this.size-=13,this.parseRemainingDescriptors(t)},i.DecoderSpecificInfo=function(t){i.Descriptor.call(this,5,t)},i.DecoderSpecificInfo.prototype=new i.Descriptor,i.SLConfigDescriptor=function(t){i.Descriptor.call(this,6,t)},i.SLConfigDescriptor.prototype=new i.Descriptor,this};t.MPEG4DescriptorParser=d;var l={ERR_INVALID_DATA:-1,ERR_NOT_ENOUGH_DATA:0,OK:1,BASIC_BOXES:["mdat","idat","free","skip","meco","strk"],FULL_BOXES:["hmhd","nmhd","iods","xml ","bxml","ipro","mere"],CONTAINER_BOXES:[["moov",["trak","pssh"]],["trak"],["edts"],["mdia"],["minf"],["dinf"],["stbl",["sgpd","sbgp"]],["mvex",["trex"]],["moof",["traf"]],["traf",["trun","sgpd","sbgp"]],["vttc"],["tref"],["iref"],["mfra",["tfra"]],["meco"],["hnti"],["hinf"],["strk"],["strd"],["sinf"],["rinf"],["schi"],["trgr"],["udta",["kind"]],["iprp",["ipma"]],["ipco"]],boxCodes:[],fullBoxCodes:[],containerBoxCodes:[],sampleEntryCodes:{},sampleGroupEntryCodes:[],trackGroupTypes:[],UUIDBoxes:{},UUIDs:[],initialize:function(){l.FullBox.prototype=new l.Box,l.ContainerBox.prototype=new l.Box,l.SampleEntry.prototype=new l.Box,l.TrackGroupTypeBox.prototype=new l.FullBox,l.BASIC_BOXES.forEach((function(t){l.createBoxCtor(t)})),l.FULL_BOXES.forEach((function(t){l.createFullBoxCtor(t)})),l.CONTAINER_BOXES.forEach((function(t){l.createContainerBoxCtor(t[0],null,t[1])}))},Box:function(t,e,i){this.type=t,this.size=e,this.uuid=i},FullBox:function(t,e,i){l.Box.call(this,t,e,i),this.flags=0,this.version=0},ContainerBox:function(t,e,i){l.Box.call(this,t,e,i),this.boxes=[]},SampleEntry:function(t,e,i,s){l.ContainerBox.call(this,t,e),this.hdr_size=i,this.start=s},SampleGroupEntry:function(t){this.grouping_type=t},TrackGroupTypeBox:function(t,e){l.FullBox.call(this,t,e)},createBoxCtor:function(t,e){l.boxCodes.push(t),l[t+"Box"]=function(e){l.Box.call(this,t,e)},l[t+"Box"].prototype=new l.Box,e&&(l[t+"Box"].prototype.parse=e)},createFullBoxCtor:function(t,e){l[t+"Box"]=function(e){l.FullBox.call(this,t,e)},l[t+"Box"].prototype=new l.FullBox,l[t+"Box"].prototype.parse=function(t){this.parseFullHeader(t),e&&e.call(this,t)}},addSubBoxArrays:function(t){if(t){this.subBoxNames=t;for(var e=t.length,i=0;ii?(r.error("BoxParser","Box of type '"+p+"' has a size "+d+" greater than its container size "+i),{code:l.ERR_NOT_ENOUGH_DATA,type:p,size:d,hdr_size:h,start:o}):o+d>t.getEndPosition()?(t.seek(o),r.info("BoxParser","Not enough data in stream to parse the entire '"+p+"' box"),{code:l.ERR_NOT_ENOUGH_DATA,type:p,size:d,hdr_size:h,start:o}):e?{code:l.OK,type:p,size:d,hdr_size:h,start:o}:(l[p+"Box"]?s=new l[p+"Box"](d):"uuid"!==p?(r.warn("BoxParser","Unknown box type: '"+p+"'"),(s=new l.Box(p,d)).has_unparsed_data=!0):l.UUIDBoxes[a]?s=new l.UUIDBoxes[a](d):(r.warn("BoxParser","Unknown uuid type: '"+a+"'"),(s=new l.Box(p,d)).uuid=a,s.has_unparsed_data=!0),s.hdr_size=h,s.start=o,s.write===l.Box.prototype.write&&"mdat"!==s.type&&(r.info("BoxParser","'"+f+"' box writing not yet implemented, keeping unparsed data in memory for later write"),s.parseDataAndRewind(t)),s.parse(t),(n=t.getPosition()-(s.start+s.size))<0?(r.warn("BoxParser","Parsing of box '"+f+"' did not read the entire indicated box data size (missing "+-n+" bytes), seeking forward"),t.seek(s.start+s.size)):n>0&&(r.error("BoxParser","Parsing of box '"+f+"' read "+n+" more bytes than the indicated box data size, seeking backwards"),t.seek(s.start+s.size)),{code:l.OK,box:s,size:s.size})},l.Box.prototype.parse=function(t){"mdat"!=this.type?this.data=t.readUint8Array(this.size-this.hdr_size):0===this.size?t.seek(t.getEndPosition()):t.seek(this.start+this.size)},l.Box.prototype.parseDataAndRewind=function(t){this.data=t.readUint8Array(this.size-this.hdr_size),t.position-=this.size-this.hdr_size},l.FullBox.prototype.parseDataAndRewind=function(t){this.parseFullHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size),this.hdr_size-=4,t.position-=this.size-this.hdr_size},l.FullBox.prototype.parseFullHeader=function(t){this.version=t.readUint8(),this.flags=t.readUint24(),this.hdr_size+=4},l.FullBox.prototype.parse=function(t){this.parseFullHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size)},l.ContainerBox.prototype.parse=function(t){for(var e,i;t.getPosition()>10&31,e[1]=this.language>>5&31,e[2]=31&this.language,this.languageString=String.fromCharCode(e[0]+96,e[1]+96,e[2]+96)},l.SAMPLE_ENTRY_TYPE_VISUAL="Visual",l.SAMPLE_ENTRY_TYPE_AUDIO="Audio",l.SAMPLE_ENTRY_TYPE_HINT="Hint",l.SAMPLE_ENTRY_TYPE_METADATA="Metadata",l.SAMPLE_ENTRY_TYPE_SUBTITLE="Subtitle",l.SAMPLE_ENTRY_TYPE_SYSTEM="System",l.SAMPLE_ENTRY_TYPE_TEXT="Text",l.SampleEntry.prototype.parseHeader=function(t){t.readUint8Array(6),this.data_reference_index=t.readUint16(),this.hdr_size+=8},l.SampleEntry.prototype.parse=function(t){this.parseHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size)},l.SampleEntry.prototype.parseDataAndRewind=function(t){this.parseHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size),this.hdr_size-=8,t.position-=this.size-this.hdr_size},l.SampleEntry.prototype.parseFooter=function(t){l.ContainerBox.prototype.parse.call(this,t)},l.createMediaSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_HINT),l.createMediaSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_METADATA),l.createMediaSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_SUBTITLE),l.createMediaSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_SYSTEM),l.createMediaSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_TEXT),l.createMediaSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_VISUAL,(function(t){var e;this.parseHeader(t),t.readUint16(),t.readUint16(),t.readUint32Array(3),this.width=t.readUint16(),this.height=t.readUint16(),this.horizresolution=t.readUint32(),this.vertresolution=t.readUint32(),t.readUint32(),this.frame_count=t.readUint16(),e=Math.min(31,t.readUint8()),this.compressorname=t.readString(e),e<31&&t.readString(31-e),this.depth=t.readUint16(),t.readUint16(),this.parseFooter(t)})),l.createMediaSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_AUDIO,(function(t){this.parseHeader(t),t.readUint32Array(2),this.channel_count=t.readUint16(),this.samplesize=t.readUint16(),t.readUint16(),t.readUint16(),this.samplerate=t.readUint32()/65536,this.parseFooter(t)})),l.createSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_VISUAL,"avc1"),l.createSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_VISUAL,"avc2"),l.createSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_VISUAL,"avc3"),l.createSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_VISUAL,"avc4"),l.createSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_VISUAL,"av01"),l.createSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_VISUAL,"hvc1"),l.createSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_VISUAL,"hev1"),l.createSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_AUDIO,"mp4a"),l.createSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_AUDIO,"ac-3"),l.createSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_AUDIO,"ec-3"),l.createEncryptedSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_VISUAL,"encv"),l.createEncryptedSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_AUDIO,"enca"),l.createEncryptedSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_SUBTITLE,"encu"),l.createEncryptedSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_SYSTEM,"encs"),l.createEncryptedSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_TEXT,"enct"),l.createEncryptedSampleEntryCtor(l.SAMPLE_ENTRY_TYPE_METADATA,"encm"),l.createBoxCtor("a1lx",(function(t){var e=16*(1+(1&(1&t.readUint8())));this.layer_size=[];for(var i=0;i<3;i++)this.layer_size[i]=16==e?t.readUint16():t.readUint32()})),l.createBoxCtor("a1op",(function(t){this.op_index=t.readUint8()})),l.createFullBoxCtor("auxC",(function(t){this.aux_type=t.readCString();var e=this.size-this.hdr_size-(this.aux_type.length+1);this.aux_subtype=t.readUint8Array(e)})),l.createBoxCtor("av1C",(function(t){var e=t.readUint8();if(e>>7&!1)r.error("av1C marker problem");else if(this.version=127&e,1===this.version)if(e=t.readUint8(),this.seq_profile=e>>5&7,this.seq_level_idx_0=31&e,e=t.readUint8(),this.seq_tier_0=e>>7&1,this.high_bitdepth=e>>6&1,this.twelve_bit=e>>5&1,this.monochrome=e>>4&1,this.chroma_subsampling_x=e>>3&1,this.chroma_subsampling_y=e>>2&1,this.chroma_sample_position=3&e,e=t.readUint8(),this.reserved_1=e>>5&7,0===this.reserved_1){if(this.initial_presentation_delay_present=e>>4&1,1===this.initial_presentation_delay_present)this.initial_presentation_delay_minus_one=15&e;else if(this.reserved_2=15&e,0!==this.reserved_2)return void r.error("av1C reserved_2 parsing problem");var i=this.size-this.hdr_size-4;this.configOBUs=t.readUint8Array(i)}else r.error("av1C reserved_1 parsing problem");else r.error("av1C version "+this.version+" not supported")})),l.createBoxCtor("avcC",(function(t){var e,i;for(this.configurationVersion=t.readUint8(),this.AVCProfileIndication=t.readUint8(),this.profile_compatibility=t.readUint8(),this.AVCLevelIndication=t.readUint8(),this.lengthSizeMinusOne=3&t.readUint8(),this.nb_SPS_nalus=31&t.readUint8(),i=this.size-this.hdr_size-6,this.SPS=[],e=0;e0&&(this.ext=t.readUint8Array(i))})),l.createBoxCtor("btrt",(function(t){this.bufferSizeDB=t.readUint32(),this.maxBitrate=t.readUint32(),this.avgBitrate=t.readUint32()})),l.createBoxCtor("clap",(function(t){this.cleanApertureWidthN=t.readUint32(),this.cleanApertureWidthD=t.readUint32(),this.cleanApertureHeightN=t.readUint32(),this.cleanApertureHeightD=t.readUint32(),this.horizOffN=t.readUint32(),this.horizOffD=t.readUint32(),this.vertOffN=t.readUint32(),this.vertOffD=t.readUint32()})),l.createBoxCtor("clli",(function(t){this.max_content_light_level=t.readUint16(),this.max_pic_average_light_level=t.readUint16()})),l.createFullBoxCtor("co64",(function(t){var e,i;if(e=t.readUint32(),this.chunk_offsets=[],0===this.version)for(i=0;i>7}else("rICC"===this.colour_type||"prof"===this.colour_type)&&(this.ICC_profile=t.readUint8Array(this.size-4))})),l.createFullBoxCtor("cprt",(function(t){this.parseLanguage(t),this.notice=t.readCString()})),l.createFullBoxCtor("cslg",(function(t){0===this.version&&(this.compositionToDTSShift=t.readInt32(),this.leastDecodeToDisplayDelta=t.readInt32(),this.greatestDecodeToDisplayDelta=t.readInt32(),this.compositionStartTime=t.readInt32(),this.compositionEndTime=t.readInt32())})),l.createFullBoxCtor("ctts",(function(t){var e,i;if(e=t.readUint32(),this.sample_counts=[],this.sample_offsets=[],0===this.version)for(i=0;i>6,this.bsid=e>>1&31,this.bsmod=(1&e)<<2|i>>6&3,this.acmod=i>>3&7,this.lfeon=i>>2&1,this.bit_rate_code=3&i|s>>5&7})),l.createBoxCtor("dec3",(function(t){var e=t.readUint16();this.data_rate=e>>3,this.num_ind_sub=7&e,this.ind_subs=[];for(var i=0;i>6,s.bsid=r>>1&31,s.bsmod=(1&r)<<4|n>>4&15,s.acmod=n>>1&7,s.lfeon=1&n,s.num_dep_sub=a>>1&15,s.num_dep_sub>0&&(s.chan_loc=(1&a)<<8|t.readUint8())}})),l.createFullBoxCtor("dfLa",(function(t){var e=[],i=["STREAMINFO","PADDING","APPLICATION","SEEKTABLE","VORBIS_COMMENT","CUESHEET","PICTURE","RESERVED"];for(this.parseFullHeader(t);;){var s=t.readUint8(),r=Math.min(127&s,i.length-1);if(r?t.readUint8Array(t.readUint24()):(t.readUint8Array(13),this.samplerate=t.readUint32()>>12,t.readUint8Array(20)),e.push(i[r]),128&s)break}this.numMetadataBlocks=e.length+" ("+e.join(", ")+")"})),l.createBoxCtor("dimm",(function(t){this.bytessent=t.readUint64()})),l.createBoxCtor("dmax",(function(t){this.time=t.readUint32()})),l.createBoxCtor("dmed",(function(t){this.bytessent=t.readUint64()})),l.createFullBoxCtor("dref",(function(t){var e,i;this.entries=[];for(var s=t.readUint32(),r=0;r=4;)this.compatible_brands[i]=t.readString(4),e-=4,i++})),l.createFullBoxCtor("hdlr",(function(t){0===this.version&&(t.readUint32(),this.handler=t.readString(4),t.readUint32Array(3),this.name=t.readString(this.size-this.hdr_size-20),"\0"===this.name[this.name.length-1]&&(this.name=this.name.slice(0,-1)))})),l.createBoxCtor("hvcC",(function(t){var e,i,s,r;this.configurationVersion=t.readUint8(),r=t.readUint8(),this.general_profile_space=r>>6,this.general_tier_flag=(32&r)>>5,this.general_profile_idc=31&r,this.general_profile_compatibility=t.readUint32(),this.general_constraint_indicator=t.readUint8Array(6),this.general_level_idc=t.readUint8(),this.min_spatial_segmentation_idc=4095&t.readUint16(),this.parallelismType=3&t.readUint8(),this.chroma_format_idc=3&t.readUint8(),this.bit_depth_luma_minus8=7&t.readUint8(),this.bit_depth_chroma_minus8=7&t.readUint8(),this.avgFrameRate=t.readUint16(),r=t.readUint8(),this.constantFrameRate=r>>6,this.numTemporalLayers=(13&r)>>3,this.temporalIdNested=(4&r)>>2,this.lengthSizeMinusOne=3&r,this.nalu_arrays=[];var n=t.readUint8();for(e=0;e>7,a.nalu_type=63&r;var o=t.readUint16();for(i=0;i>4&15,this.length_size=15&e,e=t.readUint8(),this.base_offset_size=e>>4&15,1===this.version||2===this.version?this.index_size=15&e:this.index_size=0,this.items=[];var i=0;if(this.version<2)i=t.readUint16();else{if(2!==this.version)throw"version of iloc box not supported";i=t.readUint32()}for(var s=0;s>7,this.axis=1&e})),l.createFullBoxCtor("infe",(function(t){if(0!==this.version&&1!==this.version||(this.item_ID=t.readUint16(),this.item_protection_index=t.readUint16(),this.item_name=t.readCString(),this.content_type=t.readCString(),this.content_encoding=t.readCString()),1===this.version)return this.extension_type=t.readString(4),r.warn("BoxParser","Cannot parse extension type"),void t.seek(this.start+this.size);this.version>=2&&(2===this.version?this.item_ID=t.readUint16():3===this.version&&(this.item_ID=t.readUint32()),this.item_protection_index=t.readUint16(),this.item_type=t.readString(4),this.item_name=t.readCString(),"mime"===this.item_type?(this.content_type=t.readCString(),this.content_encoding=t.readCString()):"uri "===this.item_type&&(this.item_uri_type=t.readCString()))})),l.createFullBoxCtor("ipma",(function(t){var e,i;for(entry_count=t.readUint32(),this.associations=[],e=0;e>7==1,1&this.flags?a.property_index=(127&n)<<8|t.readUint8():a.property_index=127&n}}})),l.createFullBoxCtor("iref",(function(t){var e,i;for(this.references=[];t.getPosition()>7,s.assignment_type=127&n,s.assignment_type){case 0:s.grouping_type=t.readString(4);break;case 1:s.grouping_type=t.readString(4),s.grouping_type_parameter=t.readUint32();break;case 2:case 3:break;case 4:s.sub_track_id=t.readUint32();break;default:r.warn("BoxParser","Unknown leva assignement type")}}})),l.createBoxCtor("lsel",(function(t){this.layer_id=t.readUint16()})),l.createBoxCtor("maxr",(function(t){this.period=t.readUint32(),this.bytes=t.readUint32()})),l.createBoxCtor("mdcv",(function(t){this.display_primaries=[],this.display_primaries[0]={},this.display_primaries[0].x=t.readUint16(),this.display_primaries[0].y=t.readUint16(),this.display_primaries[1]={},this.display_primaries[1].x=t.readUint16(),this.display_primaries[1].y=t.readUint16(),this.display_primaries[2]={},this.display_primaries[2].x=t.readUint16(),this.display_primaries[2].y=t.readUint16(),this.white_point={},this.white_point.x=t.readUint16(),this.white_point.y=t.readUint16(),this.max_display_mastering_luminance=t.readUint32(),this.min_display_mastering_luminance=t.readUint32()})),l.createFullBoxCtor("mdhd",(function(t){1==this.version?(this.creation_time=t.readUint64(),this.modification_time=t.readUint64(),this.timescale=t.readUint32(),this.duration=t.readUint64()):(this.creation_time=t.readUint32(),this.modification_time=t.readUint32(),this.timescale=t.readUint32(),this.duration=t.readUint32()),this.parseLanguage(t),t.readUint16()})),l.createFullBoxCtor("mehd",(function(t){1&this.flags&&(r.warn("BoxParser","mehd box incorrectly uses flags set to 1, converting version to 1"),this.version=1),1==this.version?this.fragment_duration=t.readUint64():this.fragment_duration=t.readUint32()})),l.createFullBoxCtor("meta",(function(t){this.boxes=[],l.ContainerBox.prototype.parse.call(this,t)})),l.createFullBoxCtor("mfhd",(function(t){this.sequence_number=t.readUint32()})),l.createFullBoxCtor("mfro",(function(t){this._size=t.readUint32()})),l.createFullBoxCtor("mvhd",(function(t){1==this.version?(this.creation_time=t.readUint64(),this.modification_time=t.readUint64(),this.timescale=t.readUint32(),this.duration=t.readUint64()):(this.creation_time=t.readUint32(),this.modification_time=t.readUint32(),this.timescale=t.readUint32(),this.duration=t.readUint32()),this.rate=t.readUint32(),this.volume=t.readUint16()>>8,t.readUint16(),t.readUint32Array(2),this.matrix=t.readUint32Array(9),t.readUint32Array(6),this.next_track_id=t.readUint32()})),l.createBoxCtor("npck",(function(t){this.packetssent=t.readUint32()})),l.createBoxCtor("nump",(function(t){this.packetssent=t.readUint64()})),l.createFullBoxCtor("padb",(function(t){var e=t.readUint32();this.padbits=[];for(var i=0;i0){var e=t.readUint32();this.kid=[];for(var i=0;i0&&(this.data=t.readUint8Array(s))})),l.createFullBoxCtor("clef",(function(t){this.width=t.readUint32(),this.height=t.readUint32()})),l.createFullBoxCtor("enof",(function(t){this.width=t.readUint32(),this.height=t.readUint32()})),l.createFullBoxCtor("prof",(function(t){this.width=t.readUint32(),this.height=t.readUint32()})),l.createContainerBoxCtor("tapt",null,["clef","prof","enof"]),l.createBoxCtor("rtp ",(function(t){this.descriptionformat=t.readString(4),this.sdptext=t.readString(this.size-this.hdr_size-4)})),l.createFullBoxCtor("saio",(function(t){1&this.flags&&(this.aux_info_type=t.readUint32(),this.aux_info_type_parameter=t.readUint32());var e=t.readUint32();this.offset=[];for(var i=0;i>7,this.avgRateFlag=e>>6&1,this.durationFlag&&(this.duration=t.readUint32()),this.avgRateFlag&&(this.accurateStatisticsFlag=t.readUint8(),this.avgBitRate=t.readUint16(),this.avgFrameRate=t.readUint16()),this.dependency=[];for(var i=t.readUint8(),s=0;s>7,this.num_leading_samples=127&e})),l.createSampleGroupCtor("rash",(function(t){if(this.operation_point_count=t.readUint16(),this.description_length!==2+(1===this.operation_point_count?2:6*this.operation_point_count)+9)r.warn("BoxParser","Mismatch in "+this.grouping_type+" sample group length"),this.data=t.readUint8Array(this.description_length-2);else{if(1===this.operation_point_count)this.target_rate_share=t.readUint16();else{this.target_rate_share=[],this.available_bitrate=[];for(var e=0;e>4,this.skip_byte_block=15&e,this.isProtected=t.readUint8(),this.Per_Sample_IV_Size=t.readUint8(),this.KID=l.parseHex16(t),this.constant_IV_size=0,this.constant_IV=0,1===this.isProtected&&0===this.Per_Sample_IV_Size&&(this.constant_IV_size=t.readUint8(),this.constant_IV=t.readUint8Array(this.constant_IV_size))})),l.createSampleGroupCtor("stsa",(function(t){r.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")})),l.createSampleGroupCtor("sync",(function(t){var e=t.readUint8();this.NAL_unit_type=63&e})),l.createSampleGroupCtor("tele",(function(t){var e=t.readUint8();this.level_independently_decodable=e>>7})),l.createSampleGroupCtor("tsas",(function(t){r.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")})),l.createSampleGroupCtor("tscl",(function(t){r.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")})),l.createSampleGroupCtor("vipr",(function(t){r.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")})),l.createFullBoxCtor("sbgp",(function(t){this.grouping_type=t.readString(4),1===this.version?this.grouping_type_parameter=t.readUint32():this.grouping_type_parameter=0,this.entries=[];for(var e=t.readUint32(),i=0;i>6,this.sample_depends_on[s]=e>>4&3,this.sample_is_depended_on[s]=e>>2&3,this.sample_has_redundancy[s]=3&e})),l.createFullBoxCtor("senc"),l.createFullBoxCtor("sgpd",(function(t){this.grouping_type=t.readString(4),r.debug("BoxParser","Found Sample Groups of type "+this.grouping_type),1===this.version?this.default_length=t.readUint32():this.default_length=0,this.version>=2&&(this.default_group_description_index=t.readUint32()),this.entries=[];for(var e=t.readUint32(),i=0;i>31&1,s.referenced_size=2147483647&r,s.subsegment_duration=t.readUint32(),r=t.readUint32(),s.starts_with_SAP=r>>31&1,s.SAP_type=r>>28&7,s.SAP_delta_time=268435455&r}})),l.SingleItemTypeReferenceBox=function(t,e,i,s){l.Box.call(this,t,e),this.hdr_size=i,this.start=s},l.SingleItemTypeReferenceBox.prototype=new l.Box,l.SingleItemTypeReferenceBox.prototype.parse=function(t){this.from_item_ID=t.readUint16();var e=t.readUint16();this.references=[];for(var i=0;i>4&15,this.sample_sizes[e+1]=15&s}else if(8===this.field_size)for(e=0;e0)for(i=0;i>4&15,this.default_skip_byte_block=15&e}this.default_isProtected=t.readUint8(),this.default_Per_Sample_IV_Size=t.readUint8(),this.default_KID=l.parseHex16(t),1===this.default_isProtected&&0===this.default_Per_Sample_IV_Size&&(this.default_constant_IV_size=t.readUint8(),this.default_constant_IV=t.readUint8Array(this.default_constant_IV_size))})),l.createFullBoxCtor("tfdt",(function(t){1==this.version?this.baseMediaDecodeTime=t.readUint64():this.baseMediaDecodeTime=t.readUint32()})),l.createFullBoxCtor("tfhd",(function(t){var e=0;this.track_id=t.readUint32(),this.size-this.hdr_size>e&&this.flags&l.TFHD_FLAG_BASE_DATA_OFFSET?(this.base_data_offset=t.readUint64(),e+=8):this.base_data_offset=0,this.size-this.hdr_size>e&&this.flags&l.TFHD_FLAG_SAMPLE_DESC?(this.default_sample_description_index=t.readUint32(),e+=4):this.default_sample_description_index=0,this.size-this.hdr_size>e&&this.flags&l.TFHD_FLAG_SAMPLE_DUR?(this.default_sample_duration=t.readUint32(),e+=4):this.default_sample_duration=0,this.size-this.hdr_size>e&&this.flags&l.TFHD_FLAG_SAMPLE_SIZE?(this.default_sample_size=t.readUint32(),e+=4):this.default_sample_size=0,this.size-this.hdr_size>e&&this.flags&l.TFHD_FLAG_SAMPLE_FLAGS?(this.default_sample_flags=t.readUint32(),e+=4):this.default_sample_flags=0})),l.createFullBoxCtor("tfra",(function(t){this.track_ID=t.readUint32(),t.readUint24();var e=t.readUint8();this.length_size_of_traf_num=e>>4&3,this.length_size_of_trun_num=e>>2&3,this.length_size_of_sample_num=3&e,this.entries=[];for(var i=t.readUint32(),s=0;s>8,t.readUint16(),this.matrix=t.readInt32Array(9),this.width=t.readUint32(),this.height=t.readUint32()})),l.createBoxCtor("tmax",(function(t){this.time=t.readUint32()})),l.createBoxCtor("tmin",(function(t){this.time=t.readUint32()})),l.createBoxCtor("totl",(function(t){this.bytessent=t.readUint32()})),l.createBoxCtor("tpay",(function(t){this.bytessent=t.readUint32()})),l.createBoxCtor("tpyl",(function(t){this.bytessent=t.readUint64()})),l.TrackGroupTypeBox.prototype.parse=function(t){this.parseFullHeader(t),this.track_group_id=t.readUint32()},l.createTrackGroupCtor("msrc"),l.TrackReferenceTypeBox=function(t,e,i,s){l.Box.call(this,t,e),this.hdr_size=i,this.start=s},l.TrackReferenceTypeBox.prototype=new l.Box,l.TrackReferenceTypeBox.prototype.parse=function(t){this.track_ids=t.readUint32Array((this.size-this.hdr_size)/4)},l.trefBox.prototype.parse=function(t){for(var e,i;t.getPosition()e&&this.flags&l.TRUN_FLAGS_DATA_OFFSET?(this.data_offset=t.readInt32(),e+=4):this.data_offset=0,this.size-this.hdr_size>e&&this.flags&l.TRUN_FLAGS_FIRST_FLAG?(this.first_sample_flags=t.readUint32(),e+=4):this.first_sample_flags=0,this.sample_duration=[],this.sample_size=[],this.sample_flags=[],this.sample_composition_time_offset=[],this.size-this.hdr_size>e)for(var i=0;i0&&(this.location=t.readCString())})),l.createUUIDBox("a5d40b30e81411ddba2f0800200c9a66",!0,!1,(function(t){this.LiveServerManifest=t.readString(this.size-this.hdr_size).replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")})),l.createUUIDBox("d08a4f1810f34a82b6c832d8aba183d3",!0,!1,(function(t){this.system_id=l.parseHex16(t);var e=t.readUint32();e>0&&(this.data=t.readUint8Array(e))})),l.createUUIDBox("a2394f525a9b4f14a2446c427c648df4",!0,!1),l.createUUIDBox("8974dbce7be74c5184f97148f9882554",!0,!1,(function(t){this.default_AlgorithmID=t.readUint24(),this.default_IV_size=t.readUint8(),this.default_KID=l.parseHex16(t)})),l.createUUIDBox("d4807ef2ca3946958e5426cb9e46a79f",!0,!1,(function(t){this.fragment_count=t.readUint8(),this.entries=[];for(var e=0;e>4,this.chromaSubsampling=e>>1&7,this.videoFullRangeFlag=1&e,this.colourPrimaries=t.readUint8(),this.transferCharacteristics=t.readUint8(),this.matrixCoefficients=t.readUint8(),this.codecIntializationDataSize=t.readUint16(),this.codecIntializationData=t.readUint8Array(this.codecIntializationDataSize)):(this.profile=t.readUint8(),this.level=t.readUint8(),e=t.readUint8(),this.bitDepth=e>>4&15,this.colorSpace=15&e,e=t.readUint8(),this.chromaSubsampling=e>>4&15,this.transferFunction=e>>1&7,this.videoFullRangeFlag=1&e,this.codecIntializationDataSize=t.readUint16(),this.codecIntializationData=t.readUint8Array(this.codecIntializationDataSize))})),l.createBoxCtor("vttC",(function(t){this.text=t.readString(this.size-this.hdr_size)})),l.SampleEntry.prototype.isVideo=function(){return!1},l.SampleEntry.prototype.isAudio=function(){return!1},l.SampleEntry.prototype.isSubtitle=function(){return!1},l.SampleEntry.prototype.isMetadata=function(){return!1},l.SampleEntry.prototype.isHint=function(){return!1},l.SampleEntry.prototype.getCodec=function(){return this.type.replace(".","")},l.SampleEntry.prototype.getWidth=function(){return""},l.SampleEntry.prototype.getHeight=function(){return""},l.SampleEntry.prototype.getChannelCount=function(){return""},l.SampleEntry.prototype.getSampleRate=function(){return""},l.SampleEntry.prototype.getSampleSize=function(){return""},l.VisualSampleEntry.prototype.isVideo=function(){return!0},l.VisualSampleEntry.prototype.getWidth=function(){return this.width},l.VisualSampleEntry.prototype.getHeight=function(){return this.height},l.AudioSampleEntry.prototype.isAudio=function(){return!0},l.AudioSampleEntry.prototype.getChannelCount=function(){return this.channel_count},l.AudioSampleEntry.prototype.getSampleRate=function(){return this.samplerate},l.AudioSampleEntry.prototype.getSampleSize=function(){return this.samplesize},l.SubtitleSampleEntry.prototype.isSubtitle=function(){return!0},l.MetadataSampleEntry.prototype.isMetadata=function(){return!0},l.decimalToHex=function(t,e){var i=Number(t).toString(16);for(e=null==e?e=2:e;i.length>=1;e+=l.decimalToHex(s,0),e+=".",0===this.hvcC.general_tier_flag?e+="L":e+="H",e+=this.hvcC.general_level_idc;var r=!1,n="";for(t=5;t>=0;t--)(this.hvcC.general_constraint_indicator[t]||r)&&(n="."+l.decimalToHex(this.hvcC.general_constraint_indicator[t],0)+n,r=!0);e+=n}return e},l.mp4aSampleEntry.prototype.getCodec=function(){var t=l.SampleEntry.prototype.getCodec.call(this);if(this.esds&&this.esds.esd){var e=this.esds.esd.getOTI(),i=this.esds.esd.getAudioConfig();return t+"."+l.decimalToHex(e)+(i?"."+i:"")}return t},l.stxtSampleEntry.prototype.getCodec=function(){var t=l.SampleEntry.prototype.getCodec.call(this);return this.mime_format?t+"."+this.mime_format:t},l.av01SampleEntry.prototype.getCodec=function(){var t,e=l.SampleEntry.prototype.getCodec.call(this);return 2===this.av1C.seq_profile&&1===this.av1C.high_bitdepth?t=1===this.av1C.twelve_bit?"12":"10":this.av1C.seq_profile<=2&&(t=1===this.av1C.high_bitdepth?"10":"08"),e+"."+this.av1C.seq_profile+"."+this.av1C.seq_level_idx_0+(this.av1C.seq_tier_0?"H":"M")+"."+t},l.Box.prototype.writeHeader=function(t,e){this.size+=8,this.size>o&&(this.size+=8),"uuid"===this.type&&(this.size+=16),r.debug("BoxWriter","Writing box "+this.type+" of size: "+this.size+" at position "+t.getPosition()+(e||"")),this.size>o?t.writeUint32(1):(this.sizePosition=t.getPosition(),t.writeUint32(this.size)),t.writeString(this.type,null,4),"uuid"===this.type&&t.writeUint8Array(this.uuid),this.size>o&&t.writeUint64(this.size)},l.FullBox.prototype.writeHeader=function(t){this.size+=4,l.Box.prototype.writeHeader.call(this,t," v="+this.version+" f="+this.flags),t.writeUint8(this.version),t.writeUint24(this.flags)},l.Box.prototype.write=function(t){"mdat"===this.type?this.data&&(this.size=this.data.length,this.writeHeader(t),t.writeUint8Array(this.data)):(this.size=this.data?this.data.length:0,this.writeHeader(t),this.data&&t.writeUint8Array(this.data))},l.ContainerBox.prototype.write=function(t){this.size=0,this.writeHeader(t);for(var e=0;e=2&&t.writeUint32(this.default_sample_description_index),t.writeUint32(this.entries.length),e=0;e0)for(e=0;e+1e?1:0,this.flags=0,this.size=4,1===this.version&&(this.size+=4),this.writeHeader(t),1===this.version?t.writeUint64(this.baseMediaDecodeTime):t.writeUint32(this.baseMediaDecodeTime)},l.tfhdBox.prototype.write=function(t){this.version=0,this.size=4,this.flags&l.TFHD_FLAG_BASE_DATA_OFFSET&&(this.size+=8),this.flags&l.TFHD_FLAG_SAMPLE_DESC&&(this.size+=4),this.flags&l.TFHD_FLAG_SAMPLE_DUR&&(this.size+=4),this.flags&l.TFHD_FLAG_SAMPLE_SIZE&&(this.size+=4),this.flags&l.TFHD_FLAG_SAMPLE_FLAGS&&(this.size+=4),this.writeHeader(t),t.writeUint32(this.track_id),this.flags&l.TFHD_FLAG_BASE_DATA_OFFSET&&t.writeUint64(this.base_data_offset),this.flags&l.TFHD_FLAG_SAMPLE_DESC&&t.writeUint32(this.default_sample_description_index),this.flags&l.TFHD_FLAG_SAMPLE_DUR&&t.writeUint32(this.default_sample_duration),this.flags&l.TFHD_FLAG_SAMPLE_SIZE&&t.writeUint32(this.default_sample_size),this.flags&l.TFHD_FLAG_SAMPLE_FLAGS&&t.writeUint32(this.default_sample_flags)},l.tkhdBox.prototype.write=function(t){this.version=0,this.size=80,this.writeHeader(t),t.writeUint32(this.creation_time),t.writeUint32(this.modification_time),t.writeUint32(this.track_id),t.writeUint32(0),t.writeUint32(this.duration),t.writeUint32(0),t.writeUint32(0),t.writeInt16(this.layer),t.writeInt16(this.alternate_group),t.writeInt16(this.volume<<8),t.writeUint16(0),t.writeInt32Array(this.matrix),t.writeUint32(this.width),t.writeUint32(this.height)},l.trexBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=20,this.writeHeader(t),t.writeUint32(this.track_id),t.writeUint32(this.default_sample_description_index),t.writeUint32(this.default_sample_duration),t.writeUint32(this.default_sample_size),t.writeUint32(this.default_sample_flags)},l.trunBox.prototype.write=function(t){this.version=0,this.size=4,this.flags&l.TRUN_FLAGS_DATA_OFFSET&&(this.size+=4),this.flags&l.TRUN_FLAGS_FIRST_FLAG&&(this.size+=4),this.flags&l.TRUN_FLAGS_DURATION&&(this.size+=4*this.sample_duration.length),this.flags&l.TRUN_FLAGS_SIZE&&(this.size+=4*this.sample_size.length),this.flags&l.TRUN_FLAGS_FLAGS&&(this.size+=4*this.sample_flags.length),this.flags&l.TRUN_FLAGS_CTS_OFFSET&&(this.size+=4*this.sample_composition_time_offset.length),this.writeHeader(t),t.writeUint32(this.sample_count),this.flags&l.TRUN_FLAGS_DATA_OFFSET&&(this.data_offset_position=t.getPosition(),t.writeInt32(this.data_offset)),this.flags&l.TRUN_FLAGS_FIRST_FLAG&&t.writeUint32(this.first_sample_flags);for(var e=0;e-1||t[i]instanceof l.Box||e[i]instanceof l.Box||void 0===t[i]||void 0===e[i]||"function"==typeof t[i]||"function"==typeof e[i]||t.subBoxNames&&t.subBoxNames.indexOf(i.slice(0,4))>-1||e.subBoxNames&&e.subBoxNames.indexOf(i.slice(0,4))>-1||"data"===i||"start"===i||"size"===i||"creation_time"===i||"modification_time"===i||l.DIFF_PRIMITIVE_ARRAY_PROP_NAMES.indexOf(i)>-1||t[i]===e[i]))return!1;return!0},l.boxEqual=function(t,e){if(!l.boxEqualFields(t,e))return!1;for(var i=0;i1)for(e=1;e-1&&this.fragmentedTracks.splice(e,1)},u.prototype.setExtractionOptions=function(t,e,i){var s=this.getTrackById(t);if(s){var r={};this.extractedTracks.push(r),r.id=t,r.user=e,r.trak=s,s.nextSample=0,r.nb_samples=1e3,r.samples=[],i&&i.nbSamples&&(r.nb_samples=i.nbSamples)}},u.prototype.unsetExtractionOptions=function(t){for(var e=-1,i=0;i-1&&this.extractedTracks.splice(e,1)},u.prototype.parse=function(){var t,e;if(!this.restoreParsePosition||this.restoreParsePosition())for(;;){if(this.hasIncompleteMdat&&this.hasIncompleteMdat()){if(this.processIncompleteMdat())continue;return}if(this.saveParsePosition&&this.saveParsePosition(),(t=l.parseOneBox(this.stream,false)).code===l.ERR_NOT_ENOUGH_DATA){if(this.processIncompleteBox){if(this.processIncompleteBox(t))continue;return}return}var i;switch(i="uuid"!==(e=t.box).type?e.type:e.uuid,this.boxes.push(e),i){case"mdat":this.mdats.push(e);break;case"moof":this.moofs.push(e);break;case"moov":this.moovStartFound=!0,0===this.mdats.length&&(this.isProgressive=!0);default:void 0!==this[i]&&r.warn("ISOFile","Duplicate Box of type: "+i+", overriding previous occurrence"),this[i]=e}this.updateUsedBytes&&this.updateUsedBytes(e,t)}},u.prototype.checkBuffer=function(t){if(null==t)throw"Buffer must be defined and non empty";if(void 0===t.fileStart)throw"Buffer must have a fileStart property";return 0===t.byteLength?(r.warn("ISOFile","Ignoring empty buffer (fileStart: "+t.fileStart+")"),this.stream.logBufferLevel(),!1):(r.info("ISOFile","Processing buffer (fileStart: "+t.fileStart+")"),t.usedBytes=0,this.stream.insertBuffer(t),this.stream.logBufferLevel(),!!this.stream.initialized()||(r.warn("ISOFile","Not ready to start parsing"),!1))},u.prototype.appendBuffer=function(t,e){var i;if(this.checkBuffer(t))return this.parse(),this.moovStartFound&&!this.moovStartSent&&(this.moovStartSent=!0,this.onMoovStart&&this.onMoovStart()),this.moov?(this.sampleListBuilt||(this.buildSampleLists(),this.sampleListBuilt=!0),this.updateSampleLists(),this.onReady&&!this.readySent&&(this.readySent=!0,this.onReady(this.getInfo())),this.processSamples(e),this.nextSeekPosition?(i=this.nextSeekPosition,this.nextSeekPosition=void 0):i=this.nextParsePosition,this.stream.getEndFilePositionAfter&&(i=this.stream.getEndFilePositionAfter(i))):i=this.nextParsePosition?this.nextParsePosition:0,this.sidx&&this.onSidx&&!this.sidxSent&&(this.onSidx(this.sidx),this.sidxSent=!0),this.meta&&(this.flattenItemInfo&&!this.itemListBuilt&&(this.flattenItemInfo(),this.itemListBuilt=!0),this.processItems&&this.processItems(this.onItem)),this.stream.cleanBuffers&&(r.info("ISOFile","Done processing buffer (fileStart: "+t.fileStart+") - next buffer to fetch should have a fileStart position of "+i),this.stream.logBufferLevel(),this.stream.cleanBuffers(),this.stream.logBufferLevel(!0),r.info("ISOFile","Sample data size in memory: "+this.getAllocatedSampleDataSize())),i},u.prototype.getInfo=function(){var t,e,i,s,r,n={},a=new Date("1904-01-01T00:00:00Z").getTime();if(this.moov)for(n.hasMoov=!0,n.duration=this.moov.mvhd.duration,n.timescale=this.moov.mvhd.timescale,n.isFragmented=null!=this.moov.mvex,n.isFragmented&&this.moov.mvex.mehd&&(n.fragment_duration=this.moov.mvex.mehd.fragment_duration),n.isProgressive=this.isProgressive,n.hasIOD=null!=this.moov.iods,n.brands=[],n.brands.push(this.ftyp.major_brand),n.brands=n.brands.concat(this.ftyp.compatible_brands),n.created=new Date(a+1e3*this.moov.mvhd.creation_time),n.modified=new Date(a+1e3*this.moov.mvhd.modification_time),n.tracks=[],n.audioTracks=[],n.videoTracks=[],n.subtitleTracks=[],n.metadataTracks=[],n.hintTracks=[],n.otherTracks=[],t=0;t0?n.mime+='video/mp4; codecs="':n.audioTracks&&n.audioTracks.length>0?n.mime+='audio/mp4; codecs="':n.mime+='application/mp4; codecs="',t=0;t=i.samples.length)&&(r.info("ISOFile","Sending fragmented data on track #"+s.id+" for samples ["+Math.max(0,i.nextSample-s.nb_samples)+","+(i.nextSample-1)+"]"),r.info("ISOFile","Sample data size in memory: "+this.getAllocatedSampleDataSize()),this.onSegment&&this.onSegment(s.id,s.user,s.segmentStream.buffer,i.nextSample,t||i.nextSample>=i.samples.length),s.segmentStream=null,s!==this.fragmentedTracks[e]))break}}if(null!==this.onSamples)for(e=0;e=i.samples.length)&&(r.debug("ISOFile","Sending samples on track #"+a.id+" for sample "+i.nextSample),this.onSamples&&this.onSamples(a.id,a.user,a.samples),a.samples=[],a!==this.extractedTracks[e]))break}}}},u.prototype.getBox=function(t){var e=this.getBoxes(t,!0);return e.length?e[0]:null},u.prototype.getBoxes=function(t,e){var i=[];return u._sweep.call(this,t,i,e),i},u._sweep=function(t,e,i){for(var s in this.type&&this.type==t&&e.push(this),this.boxes){if(e.length&&i)return;u._sweep.call(this.boxes[s],t,e,i)}},u.prototype.getTrackSamplesInfo=function(t){var e=this.getTrackById(t);return e?e.samples:void 0},u.prototype.getTrackSample=function(t,e){var i=this.getTrackById(t);return this.getSample(i,e)},u.prototype.releaseUsedSamples=function(t,e){var i=0,s=this.getTrackById(t);s.lastValidSample||(s.lastValidSample=0);for(var n=s.lastValidSample;nt*n.timescale){d=s-1;break}e&&n.is_sync&&(h=s)}for(e&&(d=h),t=i.samples[d].cts,i.nextSample=d;i.samples[d].alreadyRead===i.samples[d].size&&i.samples[d+1];)d++;return a=i.samples[d].offset+i.samples[d].alreadyRead,r.info("ISOFile","Seeking to "+(e?"RAP":"")+" sample #"+i.nextSample+" on track "+i.tkhd.track_id+", time "+r.getDurationString(t,o)+" and offset: "+a),{offset:a,time:t/o}},u.prototype.seek=function(t,e){var i,s,n,a=this.moov,o={offset:1/0,time:1/0};if(this.moov){for(n=0;n-1){o=h;break}switch(o){case"Visual":if(r.add("vmhd").set("graphicsmode",0).set("opcolor",[0,0,0]),a.set("width",e.width).set("height",e.height).set("horizresolution",72<<16).set("vertresolution",72<<16).set("frame_count",1).set("compressorname",e.type+" Compressor").set("depth",24),e.avcDecoderConfigRecord){var f=new l.avcCBox,u=new n(e.avcDecoderConfigRecord);f.parse(u),a.addBox(f)}break;case"Audio":r.add("smhd").set("balance",e.balance||0),a.set("channel_count",e.channel_count||2).set("samplesize",e.samplesize||16).set("samplerate",e.samplerate||65536);break;case"Hint":r.add("hmhd");break;case"Subtitle":if(r.add("sthd"),"stpp"===e.type)a.set("namespace",e.namespace||"nonamespace").set("schema_location",e.schema_location||"").set("auxiliary_mime_types",e.auxiliary_mime_types||"");break;default:r.add("nmhd")}e.description&&a.addBox(e.description),e.description_boxes&&e.description_boxes.forEach((function(t){a.addBox(t)})),r.add("dinf").add("dref").addEntry((new l["url Box"]).set("flags",1));var c=r.add("stbl");return c.add("stsd").addEntry(a),c.add("stts").set("sample_counts",[]).set("sample_deltas",[]),c.add("stsc").set("first_chunk",[]).set("samples_per_chunk",[]).set("sample_description_index",[]),c.add("stco").set("chunk_offsets",[]),c.add("stsz").set("sample_sizes",[]),this.moov.mvex.add("trex").set("track_id",e.id).set("default_sample_description_index",e.default_sample_description_index||1).set("default_sample_duration",e.default_sample_duration||0).set("default_sample_size",e.default_sample_size||0).set("default_sample_flags",e.default_sample_flags||0),this.buildTrakSampleLists(i),e.id}},l.Box.prototype.computeSize=function(t){var e=t||new a;e.endianness=a.BIG_ENDIAN,this.write(e)},u.prototype.addSample=function(t,e,i){var s=i||{},r={},n=this.getTrackById(t);if(null!==n){r.number=n.samples.length,r.track_id=n.tkhd.track_id,r.timescale=n.mdia.mdhd.timescale,r.description_index=s.sample_description_index?s.sample_description_index-1:0,r.description=n.mdia.minf.stbl.stsd.entries[r.description_index],r.data=e,r.size=e.byteLength,r.alreadyRead=r.size,r.duration=s.duration||1,r.cts=s.cts||0,r.dts=s.dts||0,r.is_sync=s.is_sync||!1,r.is_leading=s.is_leading||0,r.depends_on=s.depends_on||0,r.is_depended_on=s.is_depended_on||0,r.has_redundancy=s.has_redundancy||0,r.degradation_priority=s.degradation_priority||0,r.offset=0,r.subsamples=s.subsamples,n.samples.push(r),n.samples_size+=r.size,n.samples_duration+=r.duration,n.first_dts||(n.first_dts=s.dts),this.processSamples();var a=this.createSingleSampleMoof(r);return this.addBox(a),a.computeSize(),a.trafs[0].truns[0].data_offset=a.size+8,this.add("mdat").data=new Uint8Array(e),r}},u.prototype.createSingleSampleMoof=function(t){var e=0;e=t.is_sync?1<<25:65536;var i=new l.moofBox;i.add("mfhd").set("sequence_number",this.nextMoofNumber),this.nextMoofNumber++;var s=i.add("traf"),r=this.getTrackById(t.track_id);return s.add("tfhd").set("track_id",t.track_id).set("flags",l.TFHD_FLAG_DEFAULT_BASE_IS_MOOF),s.add("tfdt").set("baseMediaDecodeTime",t.dts-r.first_dts),s.add("trun").set("flags",l.TRUN_FLAGS_DATA_OFFSET|l.TRUN_FLAGS_DURATION|l.TRUN_FLAGS_SIZE|l.TRUN_FLAGS_FLAGS|l.TRUN_FLAGS_CTS_OFFSET).set("data_offset",0).set("first_sample_flags",0).set("sample_count",1).set("sample_duration",[t.duration]).set("sample_size",[t.size]).set("sample_flags",[e]).set("sample_composition_time_offset",[t.cts-t.dts]),i},u.prototype.lastMoofIndex=0,u.prototype.samplesDataSize=0,u.prototype.resetTables=function(){var t,e,i,s,r,n;for(this.initial_duration=this.moov.mvhd.duration,this.moov.mvhd.duration=0,t=0;t=2&&(h=r[a].grouping_type+"/0",(o=new d(r[a].grouping_type,0)).is_fragment=!0,e.sample_groups_info[h]||(e.sample_groups_info[h]=o))}else for(a=0;a=2&&(h=s[a].grouping_type+"/0",o=new d(s[a].grouping_type,0),t.sample_groups_info[h]||(t.sample_groups_info[h]=o))},u.setSampleGroupProperties=function(t,e,i,s){var r,n;for(r in e.sample_groups=[],s){var a;if(e.sample_groups[r]={},e.sample_groups[r].grouping_type=s[r].grouping_type,e.sample_groups[r].grouping_type_parameter=s[r].grouping_type_parameter,i>=s[r].last_sample_in_run&&(s[r].last_sample_in_run<0&&(s[r].last_sample_in_run=0),s[r].entry_index++,s[r].entry_index<=s[r].sbgp.entries.length-1&&(s[r].last_sample_in_run+=s[r].sbgp.entries[s[r].entry_index].sample_count)),s[r].entry_index<=s[r].sbgp.entries.length-1?e.sample_groups[r].group_description_index=s[r].sbgp.entries[s[r].entry_index].group_description_index:e.sample_groups[r].group_description_index=-1,0!==e.sample_groups[r].group_description_index)a=s[r].fragment_description?s[r].fragment_description:s[r].description,e.sample_groups[r].group_description_index>0?(n=e.sample_groups[r].group_description_index>65535?(e.sample_groups[r].group_description_index>>16)-1:e.sample_groups[r].group_description_index-1,a&&n>=0&&(e.sample_groups[r].description=a.entries[n])):a&&a.version>=2&&a.default_group_description_index>0&&(e.sample_groups[r].description=a.entries[a.default_group_description_index-1])}},u.process_sdtp=function(t,e,i){e&&(t?(e.is_leading=t.is_leading[i],e.depends_on=t.sample_depends_on[i],e.is_depended_on=t.sample_is_depended_on[i],e.has_redundancy=t.sample_has_redundancy[i]):(e.is_leading=0,e.depends_on=0,e.is_depended_on=0,e.has_redundancy=0))},u.prototype.buildSampleLists=function(){var t,e;for(t=0;tb&&(v++,b<0&&(b=0),b+=n.sample_counts[v]),e>0?(t.samples[e-1].duration=n.sample_deltas[v],t.samples_duration+=t.samples[e-1].duration,B.dts=t.samples[e-1].dts+t.samples[e-1].duration):B.dts=0,a?(e>=w&&(S++,w<0&&(w=0),w+=a.sample_counts[S]),B.cts=t.samples[e].dts+a.sample_offsets[S]):B.cts=B.dts,o?(e==o.sample_numbers[U]-1?(B.is_sync=!0,U++):(B.is_sync=!1,B.degradation_priority=0),d&&d.entries[x].sample_delta+E==e+1&&(B.subsamples=d.entries[x].subsamples,E+=d.entries[x].sample_delta,x++)):B.is_sync=!0,u.process_sdtp(t.mdia.minf.stbl.sdtp,B,B.number),B.degradation_priority=f?f.priority[e]:0,d&&d.entries[x].sample_delta+E==e&&(B.subsamples=d.entries[x].subsamples,E+=d.entries[x].sample_delta),(l.length>0||p.length>0)&&u.setSampleGroupProperties(t,B,e,t.sample_groups_info)}e>0&&(t.samples[e-1].duration=Math.max(t.mdia.mdhd.duration-t.samples[e-1].dts,0),t.samples_duration+=t.samples[e-1].duration)}},u.prototype.updateSampleLists=function(){var t,e,i,s,r,n,a,o,h,d,p,f,c,m,_;if(void 0!==this.moov)for(;this.lastMoofIndex0&&u.initSampleGroups(f,p,p.sbgps,f.mdia.minf.stbl.sgpds,p.sgpds),e=0;e0?m.dts=f.samples[f.samples.length-2].dts+f.samples[f.samples.length-2].duration:(p.tfdt?m.dts=p.tfdt.baseMediaDecodeTime:m.dts=0,f.first_traf_merged=!0),m.cts=m.dts,g.flags&l.TRUN_FLAGS_CTS_OFFSET&&(m.cts=m.dts+g.sample_composition_time_offset[i]),_=a,g.flags&l.TRUN_FLAGS_FLAGS?_=g.sample_flags[i]:0===i&&g.flags&l.TRUN_FLAGS_FIRST_FLAG&&(_=g.first_sample_flags),m.is_sync=!(_>>16&1),m.is_leading=_>>26&3,m.depends_on=_>>24&3,m.is_depended_on=_>>22&3,m.has_redundancy=_>>20&3,m.degradation_priority=65535&_;var y=!!(p.tfhd.flags&l.TFHD_FLAG_BASE_DATA_OFFSET),b=!!(p.tfhd.flags&l.TFHD_FLAG_DEFAULT_BASE_IS_MOOF),v=!!(g.flags&l.TRUN_FLAGS_DATA_OFFSET),w=0;w=y?p.tfhd.base_data_offset:b||0===e?d.start:o,m.offset=0===e&&0===i?v?w+g.data_offset:w:o,o=m.offset+m.size,(p.sbgps.length>0||p.sgpds.length>0||f.mdia.minf.stbl.sbgps.length>0||f.mdia.minf.stbl.sgpds.length>0)&&u.setSampleGroupProperties(f,m,m.number_in_traf,p.sample_groups_info)}}if(p.subs){f.has_fragment_subsamples=!0;var S=p.first_sample_index;for(e=0;e-1))return null;var o=(i=this.stream.buffers[n]).byteLength-(s.offset+s.alreadyRead-i.fileStart);if(s.size-s.alreadyRead<=o)return r.debug("ISOFile","Getting sample #"+e+" data (alreadyRead: "+s.alreadyRead+" offset: "+(s.offset+s.alreadyRead-i.fileStart)+" read size: "+(s.size-s.alreadyRead)+" full size: "+s.size+")"),a.memcpy(s.data.buffer,s.alreadyRead,i,s.offset+s.alreadyRead-i.fileStart,s.size-s.alreadyRead),i.usedBytes+=s.size-s.alreadyRead,this.stream.logBufferLevel(),s.alreadyRead=s.size,s;if(0===o)return null;r.debug("ISOFile","Getting sample #"+e+" partial data (alreadyRead: "+s.alreadyRead+" offset: "+(s.offset+s.alreadyRead-i.fileStart)+" read size: "+o+" full size: "+s.size+")"),a.memcpy(s.data.buffer,s.alreadyRead,i,s.offset+s.alreadyRead-i.fileStart,o),s.alreadyRead+=o,i.usedBytes+=o,this.stream.logBufferLevel()}},u.prototype.releaseSample=function(t,e){var i=t.samples[e];return i.data?(this.samplesDataSize-=i.size,i.data=null,i.alreadyRead=0,i.size):0},u.prototype.getAllocatedSampleDataSize=function(){return this.samplesDataSize},u.prototype.getCodecs=function(){var t,e="";for(t=0;t0&&(e+=","),e+=this.moov.traks[t].mdia.minf.stbl.stsd.entries[0].getCodec()}return e},u.prototype.getTrexById=function(t){var e;if(!this.moov||!this.moov.mvex)return null;for(e=0;e0&&(i.protection=n.ipro.protections[n.iinf.item_infos[t].protection_index-1]),n.iinf.item_infos[t].item_type?i.type=n.iinf.item_infos[t].item_type:i.type="mime",i.content_type=n.iinf.item_infos[t].content_type,i.content_encoding=n.iinf.item_infos[t].content_encoding;if(n.iloc)for(t=0;t0&&p.property_index-1-1))return null;var h=(e=this.stream.buffers[o]).byteLength-(n.offset+n.alreadyRead-e.fileStart);if(!(n.length-n.alreadyRead<=h))return r.debug("ISOFile","Getting item #"+t+" extent #"+s+" partial data (alreadyRead: "+n.alreadyRead+" offset: "+(n.offset+n.alreadyRead-e.fileStart)+" read size: "+h+" full extent size: "+n.length+" full item size: "+i.size+")"),a.memcpy(i.data.buffer,i.alreadyRead,e,n.offset+n.alreadyRead-e.fileStart,h),n.alreadyRead+=h,i.alreadyRead+=h,e.usedBytes+=h,this.stream.logBufferLevel(),null;r.debug("ISOFile","Getting item #"+t+" extent #"+s+" data (alreadyRead: "+n.alreadyRead+" offset: "+(n.offset+n.alreadyRead-e.fileStart)+" read size: "+(n.length-n.alreadyRead)+" full extent size: "+n.length+" full item size: "+i.size+")"),a.memcpy(i.data.buffer,i.alreadyRead,e,n.offset+n.alreadyRead-e.fileStart,n.length-n.alreadyRead),e.usedBytes+=n.length-n.alreadyRead,this.stream.logBufferLevel(),i.alreadyRead+=n.length-n.alreadyRead,n.alreadyRead=n.length}}return i.alreadyRead===i.size?i:null},u.prototype.releaseItem=function(t){var e=this.items[t];if(e.data){this.itemsDataSize-=e.size,e.data=null,e.alreadyRead=0;for(var i=0;i0?this.moov.traks[t].samples[0].duration:0),e.push(s)}return e},l.Box.prototype.printHeader=function(t){this.size+=8,this.size>o&&(this.size+=8),"uuid"===this.type&&(this.size+=16),t.log(t.indent+"size:"+this.size),t.log(t.indent+"type:"+this.type)},l.FullBox.prototype.printHeader=function(t){this.size+=4,l.Box.prototype.printHeader.call(this,t),t.log(t.indent+"version:"+this.version),t.log(t.indent+"flags:"+this.flags)},l.Box.prototype.print=function(t){this.printHeader(t)},l.ContainerBox.prototype.print=function(t){this.printHeader(t);for(var e=0;e>8)),t.log(t.indent+"matrix: "+this.matrix.join(", ")),t.log(t.indent+"next_track_id: "+this.next_track_id)},l.tkhdBox.prototype.print=function(t){l.FullBox.prototype.printHeader.call(this,t),t.log(t.indent+"creation_time: "+this.creation_time),t.log(t.indent+"modification_time: "+this.modification_time),t.log(t.indent+"track_id: "+this.track_id),t.log(t.indent+"duration: "+this.duration),t.log(t.indent+"volume: "+(this.volume>>8)),t.log(t.indent+"matrix: "+this.matrix.join(", ")),t.log(t.indent+"layer: "+this.layer),t.log(t.indent+"alternate_group: "+this.alternate_group),t.log(t.indent+"width: "+this.width),t.log(t.indent+"height: "+this.height)};var c={createFile:function(t,e){var i=void 0===t||t,s=new u(e);return s.discardMdatData=!i,s}};t.createFile=c.createFile}(n);class a{constructor(t){this.data=new Uint8Array(t),this.idx=0,this.size=t}getData(){if(this.idx!==this.size)throw new Error("Mismatch between size reserved and sized used");return this.data.slice(0,this.idx)}writeUint8(t){this.data.set([t],this.idx),this.idx+=1}writeUint16(t){const e=new Uint16Array(1);e[0]=t;const i=new Uint8Array(e.buffer);this.data.set([i[1],i[0]],this.idx),this.idx+=2}writeUint8Array(t){this.data.set(t,this.idx),this.idx+=t.length}}const o=(t,e,{VideoDecoder:i,EncodedVideoChunk:s,debug:r})=>new Promise(((o,h)=>{r&&console.info("Decoding video from",t);try{const d=n.createFile();let l;const p=new i({output:t=>{createImageBitmap(t,{resizeQuality:"low"}).then((i=>{e(i),t.close(),p.decodeQueueSize<=0&&setTimeout((()=>{"closed"!==p.state&&(p.close(),o())}),500)}))},error:t=>{console.error(t),h(t)}});d.onReady=t=>{if(t&&t.videoTracks&&t.videoTracks[0]){[{codec:l}]=t.videoTracks,r&&console.info("Video with codec:",l);const e=(t=>{let e,i=7;for(e=0;e{for(let t=0;t{const e=t.body.getReader();let i=0;return e.read().then((function t({done:s,value:r}){if(s)return d.flush(),null;const n=r.buffer;return n.fileStart=i,i+=n.byteLength,d.appendBuffer(n),e.read().then(t)}))}))}catch(t){h(t)}}));const h=(t,e=1)=>{const i=window.pageYOffset;return Math.abs(i-t){}),onChange:u=(()=>{}),debug:c=!1}){if("object"!=typeof document)return void console.error("ScrollyVideo must be initiated in a DOM context");if(!e)return void console.error("scrollyVideoContainer must be a valid DOM object");if(!t)return void console.error("Must provide valid video src to ScrollyVideo");if(e instanceof Element)this.container=e;else{if("string"!=typeof e)throw new Error("scrollyVideoContainer must be a valid DOM object");if(this.container=document.getElementById(e),!this.container)throw new Error("scrollyVideoContainer must be a valid DOM object")}this.src=t,this.transitionSpeed=d,this.frameThreshold=l,this.useWebCodecs=p,this.cover=i,this.sticky=s,this.trackScroll=a,this.onReady=f,this.onChange=u,this.debug=c,this.video=document.createElement("video"),this.video.src=t,this.video.preload="auto",this.video.tabIndex=0,this.video.autobuffer=!0,this.video.playsInline=!0,this.video.muted=!0,this.video.pause(),this.video.load(),this.videoPercentage=0,this.container.appendChild(this.video),s&&(this.container.style.display="block",this.container.style.position="sticky",this.container.style.top="0"),n&&(this.container.style.width="100%",this.container.style.height="100vh",this.container.style.overflow="hidden"),i&&this.setCoverStyle(this.video);const m=(new r).getEngine();this.isSafari="WebKit"===m.name,c&&this.isSafari&&console.info("Safari browser detected"),this.currentTime=0,this.targetTime=0,this.canvas=null,this.context=null,this.frames=[],this.frameRate=0;const _=function(t,e=0){let i;return function(...s){const r=this;clearTimeout(i),i=setTimeout((()=>{t.apply(r,s)}),e)}}((()=>{window.requestAnimationFrame((()=>{this.setScrollPercent(this.videoPercentage)}))}),100);this.updateScrollPercentage=t=>{const e=this.container.parentNode.getBoundingClientRect(),i=-e.top/(e.height-window.innerHeight);this.debug&&console.info("ScrollyVideo scrolled to",i),null==this.targetScrollPosition?(this.setTargetTimePercent(i,{jump:t}),this.onChange(i)):h(this.targetScrollPosition)?this.targetScrollPosition=null:o&&null!=this.targetScrollPosition&&_()},this.trackScroll?(window.addEventListener("scroll",this.updateScrollPercentage),this.video.addEventListener("loadedmetadata",(()=>this.updateScrollPercentage(!0)),{once:!0})):this.video.addEventListener("loadedmetadata",(()=>this.setTargetTimePercent(0,{jump:!0})),{once:!0}),this.resize=()=>{this.debug&&console.info("ScrollyVideo resizing..."),this.cover&&this.setCoverStyle(this.canvas||this.video),this.paintCanvasFrame(Math.floor(this.currentTime*this.frameRate))},window.addEventListener("resize",this.resize),this.video.addEventListener("progress",this.resize),this.decodeVideo()}setVideoPercentage(t,e={}){this.videoPercentage!==t&&(this.transitioningRaf&&window.cancelAnimationFrame(this.transitioningRaf),this.videoPercentage=t,this.onChange(t),this.trackScroll&&this.setScrollPercent(t),this.setTargetTimePercent(t,e))}setCoverStyle(t){if(this.cover){t.style.position="absolute",t.style.top="50%",t.style.left="50%",t.style.transform="translate(-50%, -50%)",t.style.minWidth="101%",t.style.minHeight="101%";const{width:e,height:i}=this.container.getBoundingClientRect(),s=t.videoWidth||t.width,r=t.videoHeight||t.height;this.debug&&console.info("Container dimensions:",[e,i]),this.debug&&console.info("Element dimensions:",[s,r]),e/i>s/r?(t.style.width="100%",t.style.height="auto"):(t.style.height="100%",t.style.width="auto")}}async decodeVideo(){if(this.useWebCodecs)if(this.src){try{await(t=this.src,e=t=>{this.frames.push(t)},i=this.debug,"function"==typeof VideoDecoder&&"function"==typeof EncodedVideoChunk?(i&&console.info("WebCodecs is natively supported, using native version..."),o(t,e,{VideoDecoder:VideoDecoder,EncodedVideoChunk:EncodedVideoChunk,debug:i})):(i&&console.info("WebCodecs is not available in this browser."),Promise.resolve()))}catch(t){this.debug&&console.error("Error encountered while decoding video",t),this.frames=[],this.video.load()}var t,e,i;if(0===this.frames.length)return this.debug&&console.error("No frames were received from webCodecs"),void this.onReady();this.frameRate=this.frames.length/this.video.duration,this.debug&&console.info("Received",this.frames.length,"frames"),this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),this.video.style.display="none",this.container.appendChild(this.canvas),this.cover&&this.setCoverStyle(this.canvas),this.paintCanvasFrame(Math.floor(this.currentTime*this.frameRate)),this.onReady()}else this.debug&&console.warn("Cannot perform video decode: no `src` found");else this.debug&&console.warn("Cannot perform video decode: `useWebCodes` disabled")}paintCanvasFrame(t){const e=this.frames[t];if(!this.canvas||!e)return;this.debug&&console.info("Painting frame",t),this.canvas.width=e.width,this.canvas.height=e.height;const{width:i,height:s}=this.container.getBoundingClientRect();i/s>e.width/e.height?(this.canvas.style.width="100%",this.canvas.style.height="auto"):(this.canvas.style.height="100%",this.canvas.style.width="auto"),this.context.drawImage(e,0,0,e.width,e.height)}transitionToTargetTime({jump:t,transitionSpeed:e=this.transitionSpeed,easing:i=null}){this.debug&&console.info("Transitioning targetTime:",this.targetTime,"currentTime:",this.currentTime);const s=this.targetTime-this.currentTime,r=Math.abs(s),n=1e3*r,a=s>0,o=({startCurrentTime:s,startTimestamp:h,timestamp:d})=>{const l=(d-h)/n,p=a?this.currentTime>=this.targetTime:this.currentTime<=this.targetTime;if(isNaN(this.targetTime)||Math.abs(this.targetTime-this.currentTime)this.video.duration&&(this.targetTime=this.video.duration),this.targetTime<0&&(this.targetTime=0);const f=this.targetTime-this.currentTime,u=i&&Number.isFinite(l)?i(l):null,c=a?s+u*Math.abs(r)*e:s-u*Math.abs(r)*e;if(this.canvas)t?this.currentTime=this.targetTime:u?this.currentTime=c:this.currentTime+=f/(256/e),this.paintCanvasFrame(Math.floor(this.currentTime*this.frameRate));else if(t||this.isSafari||!a)this.video.pause(),u?this.currentTime=c:this.currentTime+=f/(64/e),t&&(this.currentTime=this.targetTime),this.video.currentTime=this.currentTime;else{const t=Math.max(Math.min(4*f,e,16),1);this.debug&&console.info("ScrollyVideo playbackRate:",t),isNaN(t)||(this.video.playbackRate=t,this.video.play()),this.currentTime=this.video.currentTime}"function"==typeof requestAnimationFrame&&(this.transitioningRaf=requestAnimationFrame((t=>o({startCurrentTime:s,startTimestamp:h,timestamp:t}))))};"function"==typeof requestAnimationFrame&&(this.transitioningRaf=requestAnimationFrame((t=>{o({startCurrentTime:this.currentTime,startTimestamp:t,timestamp:t})})))}setTargetTimePercent(t,e={}){const i=this.frames.length&&this.frameRate?this.frames.length/this.frameRate:this.video.duration;this.targetTime=Math.max(Math.min(t,1),0)*i,!e.jump&&Math.abs(this.currentTime-this.targetTime) + sphere_shade(zscale = 10, texture = "imhof1") |> + add_shadow(mont_shadow, 0.5) |> + add_shadow(mont_amb, 0) -> +mont_scene +``` + +Now we'll render the movie as `rayshader.mp4`: + +```{r} +#| label: render-images +# tibble(angle = seq(0.01, 1, by = 0.01) * 360 + 45) |> +# mutate( +# n = 1:n(), +# fname = paste0("image", str_pad(n, 3, pad = "0")), +# render = map2(angle, fname, function(angle, fname) { +# plot_3d( +# mont_scene, montereybay, zscale = 50, fov = 0, theta = angle, phi = 45, +# windowsize = c(1000, 800), zoom = 0.75, water = TRUE, waterdepth = 0, +# wateralpha = 0.5, watercolor = "lightblue", waterlinecolor = "white", +# waterlinealpha = 0.5) +# Sys.sleep(0.5) +# render_snapshot(fname) +# })) +plot_3d( + mont_scene, montereybay, zscale = 50, fov = 0, phi = 45, + windowsize = c(1000, 800), zoom = 0.75, water = TRUE, waterdepth = 0, + wateralpha = 0.5, watercolor = "lightblue", waterlinecolor = "white", + waterlinealpha = 0.5) + +render_movie("rayshader.mp4") +``` + +Let's incorporate `rayshader.mp4` into a scrolly section: + +::::{.cr-section} + +Here's our rayshader video! [@cr-rayshader]{.scroll-video} + +We can keep talking about it for a while... @cr-rayshader + +... and a while longer! @cr-rayshader + +:::{#cr-rayshader} +::: + +:::: + + +:::{.counter style="position: fixed; top: 10px; right: 10px; background-color: skyblue; border-radius: 5px; padding: 18px 18px 0 18px; line-height: .8em; z-index: 1000"} +```{ojs} +md`Active sticky: ${crActiveSticky}` +md`Active trigger: ${crTriggerIndex}` +md`Trigger progress: ${(crTriggerProgress * 100).toFixed(1)}%` +md`Scroll direction: ${crDirection}` +md`Progress Block progress: ${(crProgressBlock * 100).toFixed(1)}%` +``` +::: diff --git a/docs/gallery/demos/videos/rayshader.mp4 b/docs/gallery/demos/videos/rayshader.mp4 new file mode 100644 index 0000000..b2e186f Binary files /dev/null and b/docs/gallery/demos/videos/rayshader.mp4 differ diff --git a/docs/gallery/demos/videos/ship.mp4 b/docs/gallery/demos/videos/ship.mp4 new file mode 100644 index 0000000..736fa6f Binary files /dev/null and b/docs/gallery/demos/videos/ship.mp4 differ diff --git a/docs/gallery/demos/videos/tea.mp4 b/docs/gallery/demos/videos/tea.mp4 new file mode 100644 index 0000000..a2c5d2c Binary files /dev/null and b/docs/gallery/demos/videos/tea.mp4 differ