UNPKG

mp4box

Version:

JavaScript version of GPAC's MP4Box tool

75 lines (68 loc) 2.31 kB
BoxParser.SampleEntry.prototype.writeHeader = function(stream) { this.size = 8; BoxParser.Box.prototype.writeHeader.call(this, stream); stream.writeUint8(0); stream.writeUint8(0); stream.writeUint8(0); stream.writeUint8(0); stream.writeUint8(0); stream.writeUint8(0); stream.writeUint16(this.data_reference_index); } BoxParser.SampleEntry.prototype.writeFooter = function(stream) { for (var i=0; i<this.boxes.length; i++) { this.boxes[i].write(stream); this.size += this.boxes[i].size; } Log.debug("BoxWriter", "Adjusting box "+this.type+" with new size "+this.size); stream.adjustUint32(this.sizePosition, this.size); } BoxParser.SampleEntry.prototype.write = function(stream) { this.writeHeader(stream); stream.writeUint8Array(this.data); this.size += this.data.length; Log.debug("BoxWriter", "Adjusting box "+this.type+" with new size "+this.size); stream.adjustUint32(this.sizePosition, this.size); } BoxParser.VisualSampleEntry.prototype.write = function(stream) { this.writeHeader(stream); this.size += 2*7+6*4+32; stream.writeUint16(0); stream.writeUint16(0); stream.writeUint32(0); stream.writeUint32(0); stream.writeUint32(0); stream.writeUint16(this.width); stream.writeUint16(this.height); stream.writeUint32(this.horizresolution); stream.writeUint32(this.vertresolution); stream.writeUint32(0); stream.writeUint16(this.frame_count); stream.writeUint8(Math.min(31, this.compressorname.length)); stream.writeString(this.compressorname, null, 31); stream.writeUint16(this.depth); stream.writeInt16(-1); this.writeFooter(stream); } BoxParser.AudioSampleEntry.prototype.write = function(stream) { this.writeHeader(stream); this.size += 2*4+3*4; stream.writeUint32(0); stream.writeUint32(0); stream.writeUint16(this.channel_count); stream.writeUint16(this.samplesize); stream.writeUint16(0); stream.writeUint16(0); stream.writeUint32(this.samplerate<<16); this.writeFooter(stream); } BoxParser.stppSampleEntry.prototype.write = function(stream) { this.writeHeader(stream); this.size += this.namespace.length+1+ this.schema_location.length+1+ this.auxiliary_mime_types.length+1; stream.writeCString(this.namespace); stream.writeCString(this.schema_location); stream.writeCString(this.auxiliary_mime_types); this.writeFooter(stream); }