@ts-videos/mp4 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/boxes.js +1 -1
- package/dist/chunk-c9md36vm.js +2 -0
- package/dist/chunk-m7vh938z.js +2 -0
- package/dist/chunk-qmjyh9jc.js +2 -0
- package/dist/chunk-tghqqx5m.js +2 -0
- package/dist/chunk-yjtc1ksx.js +2 -0
- package/dist/demuxer.js +1 -1
- package/dist/fragmented.js +1 -1
- package/dist/index.js +1 -1
- package/dist/muxer.js +1 -1
- package/dist/prores.test.d.ts +1 -1
- package/dist/prores.test.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-51x739sq.js +0 -2
- package/dist/chunk-63shg4s1.js +0 -2
- package/dist/chunk-vetfxydj.js +0 -2
- package/dist/chunk-wmd2bsvz.js +0 -2
- package/dist/chunk-zmpvp966.js +0 -2
package/README.md
CHANGED
|
@@ -134,7 +134,7 @@ Made with 💙
|
|
|
134
134
|
[releases]: https://github.com/stacksjs/stacks/releases
|
|
135
135
|
[contributing-guide]: https://github.com/stacksjs/contributing
|
|
136
136
|
[discussions-on-github]: https://github.com/stacksjs/stacks/discussions
|
|
137
|
-
[join-the-stacks-discord-server]: https://
|
|
137
|
+
[join-the-stacks-discord-server]: https://stacksjs.com/discord
|
|
138
138
|
[jetbrains]: https://www.jetbrains.com/
|
|
139
139
|
[the-solana-foundation]: https://solana.com/
|
|
140
140
|
[chris-breuer]: https://github.com/chrisbbreuer
|
package/dist/boxes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{t,c,u,b,d,m,p,n,o,g,l,s,e}from"./chunk-qmjyh9jc.js";export{t as BOX_HEADER_SIZE,d as CONTAINER_BOXES,c as EXTENDED_BOX_HEADER_SIZE,p as MOV_BRANDS,m as MP4_BRANDS,e as TIMESCALE_1904_TO_1970,s as encodeLanguageCode,o as isAudioHandler,g as isSubtitleHandler,n as isVideoHandler,l as parseLanguageCode,u as readFourCC,b as writeFourCC};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{s,e}from"./chunk-qmjyh9jc.js";import{Muxer as Y}from"ts-videos/muxer";import{Writer as B}from"ts-videos/writer";var T=1000;class i extends Y{trackData=new Map;options;mdatStart=0;mdatSize=0;chapters=[];artwork=null;artworkType="jpeg";constructor(a,t={}){super(a);this.options={fastStart:t.fastStart??!0,fragmented:t.fragmented??!1,brand:t.brand??"isom"}}addChapter(a,t){this.chapters.push({title:a,startTimeMs:t})}setArtwork(a,t="jpeg"){this.artwork=a,this.artworkType=t}get formatName(){return"mp4"}get mimeType(){return"video/mp4"}onTrackAdded(a){let t=a.type==="video"?Math.round((a.config.frameRate??30)*1000):a.type==="audio"?a.config.sampleRate:1000;this.trackData.set(a.id,{track:a,timescale:t,samples:[],chunkOffsets:[],currentChunk:null})}async writeHeader(){if(await this.writeFtyp(),!this.options.fastStart)this.mdatStart=this.writer.position,await this.writeMdatHeader(0)}async writeFtyp(){let a=[this.options.brand,"isom","iso2","mp42"],t=16+a.length*4;await this.writer.writeU32BE(t),await this.writer.writeFourCC("ftyp"),await this.writer.writeFourCC(this.options.brand),await this.writer.writeU32BE(512);for(let r of a)await this.writer.writeFourCC(r)}async writeMdatHeader(a){if(a>4294967287)await this.writer.writeU32BE(1),await this.writer.writeFourCC("mdat"),await this.writer.writeU64BE(BigInt(a+16));else await this.writer.writeU32BE(a+8),await this.writer.writeFourCC("mdat")}async writeVideoPacket(a,t){await this.writeSample(a.id,t)}async writeAudioPacket(a,t){await this.writeSample(a.id,t)}async writeSubtitlePacket(a,t){await this.writeSample(a.id,t)}async writeSample(a,t){let r=this.trackData.get(a);if(!r)return;let w={data:t.data,timestamp:t.timestamp,duration:t.duration??0,isKeyframe:t.isKeyframe,compositionTimeOffset:t.compositionTimeOffset??0,size:t.data.byteLength};if(this.options.fastStart)r.samples.push(w);else{let n=this.writer.position;if(await this.writer.writeBytes(t.data),this.mdatSize+=t.data.byteLength,w.size=t.data.byteLength,r.samples.push(w),!r.currentChunk)r.currentChunk={samples:[],offset:n},r.chunkOffsets.push(n);r.currentChunk.samples.push(w)}}async writeTrailer(){if(this.options.fastStart){let a=await this.buildMoov(0);this.mdatStart=this.writer.position+a.byteLength+8,await this.adjustChunkOffsets(this.mdatStart);let t=await this.buildMoov(this.mdatStart);await this.writer.writeBytes(t);let r=this.chapters.length>0?this.buildChapterTextSamples():[],w=0;for(let n of this.trackData.values())for(let o of n.samples)w+=o.size;for(let n of r)w+=n.data.byteLength;await this.writeMdatHeader(w);for(let n of this.trackData.values())for(let o of n.samples)await this.writer.writeBytes(o.data);for(let n of r)await this.writer.writeBytes(n.data)}else{let a=await this.buildMoov(this.mdatStart+8);await this.writer.writeBytes(a)}}async adjustChunkOffsets(a){let t=a;for(let r of this.trackData.values()){r.chunkOffsets=[];for(let w of r.samples)r.chunkOffsets.push(t),t+=w.size}}async buildMoov(a){let t=new B,r=await this.buildMvhd(),w=[],n=0;for(let f of this.trackData.values())for(let y of f.samples)n+=y.size;let o=this.chapters.length>0,c=o?this.tracks.length+1:0,l=o?this.buildChapterTextSamples():[];for(let f of this.trackData.values()){let y=f.track.type==="audio"&&o?c:void 0,m=await this.buildTrak(f,a,y);w.push(m)}if(o&&l.length>0){let f=a+n,y=await this.buildChapterTrak(c,l,f);w.push(y)}let u=await this.buildUdta(),d=r.byteLength+w.reduce((f,y)=>f+y.byteLength,0);if(u)d+=u.byteLength;let U=d+8;await t.writeU32BE(U),await t.writeFourCC("moov"),await t.writeBytes(r);for(let f of w)await t.writeBytes(f);if(u)await t.writeBytes(u);return t.getBuffer()}async buildMvhd(){let a=new B,t=BigInt(Math.floor(Date.now()/1000))+e,r=0n;for(let o of this.trackData.values()){let c=o.samples[o.samples.length-1];if(c){let l=BigInt(Math.round((c.timestamp+c.duration)*T));if(l>r)r=l}}let w=108,n=this.chapters.length>0;await a.writeU32BE(w),await a.writeFourCC("mvhd"),await a.writeU8(0),await a.writeU8(0),await a.writeU8(0),await a.writeU8(0),await a.writeU32BE(Number(t&0xFFFFFFFFn)),await a.writeU32BE(Number(t&0xFFFFFFFFn)),await a.writeU32BE(T),await a.writeU32BE(Number(r&0xFFFFFFFFn)),await a.writeU32BE(65536),await a.writeU16BE(256),await a.writeU16BE(0),await a.writeU32BE(0),await a.writeU32BE(0),await a.writeU32BE(65536),await a.writeU32BE(0),await a.writeU32BE(0),await a.writeU32BE(0),await a.writeU32BE(65536),await a.writeU32BE(0),await a.writeU32BE(0),await a.writeU32BE(0),await a.writeU32BE(1073741824);for(let o=0;o<6;o++)await a.writeU32BE(0);return await a.writeU32BE(this.tracks.length+1+(n?1:0)),a.getBuffer()}async buildTrak(a,t,r){let w=new B,n=await this.buildTkhd(a),o=r?await this.buildTref(r):null,c=await this.buildMdia(a,t),l=8+n.byteLength+c.byteLength;if(o)l+=o.byteLength;if(await w.writeU32BE(l),await w.writeFourCC("trak"),await w.writeBytes(n),o)await w.writeBytes(o);return await w.writeBytes(c),w.getBuffer()}async buildTkhd(a){let t=new B,r=BigInt(Math.floor(Date.now()/1000))+e,w=a.samples[a.samples.length-1],n=w?BigInt(Math.round((w.timestamp+w.duration)*T)):0n,o=92,c=a.track,l=0,u=0,d=0;if(c.type==="video")l=c.config.width,u=c.config.height;else if(c.type==="audio")d=256;return await t.writeU32BE(92),await t.writeFourCC("tkhd"),await t.writeU8(0),await t.writeU8(0),await t.writeU8(0),await t.writeU8(3),await t.writeU32BE(Number(r&0xFFFFFFFFn)),await t.writeU32BE(Number(r&0xFFFFFFFFn)),await t.writeU32BE(c.id),await t.writeU32BE(0),await t.writeU32BE(Number(n&0xFFFFFFFFn)),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU16BE(0),await t.writeU16BE(0),await t.writeU16BE(d),await t.writeU16BE(0),await t.writeU32BE(65536),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU32BE(65536),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU32BE(1073741824),await t.writeU32BE(l<<16),await t.writeU32BE(u<<16),t.getBuffer()}async buildMdia(a,t){let r=new B,w=await this.buildMdhd(a),n=await this.buildHdlr(a),o=await this.buildMinf(a,t),c=8+w.byteLength+n.byteLength+o.byteLength;return await r.writeU32BE(c),await r.writeFourCC("mdia"),await r.writeBytes(w),await r.writeBytes(n),await r.writeBytes(o),r.getBuffer()}async buildMdhd(a){let t=new B,r=BigInt(Math.floor(Date.now()/1000))+e,w=a.samples[a.samples.length-1],n=w?BigInt(Math.round((w.timestamp+w.duration)*a.timescale)):0n,o=32;return await t.writeU32BE(32),await t.writeFourCC("mdhd"),await t.writeU8(0),await t.writeU8(0),await t.writeU8(0),await t.writeU8(0),await t.writeU32BE(Number(r&0xFFFFFFFFn)),await t.writeU32BE(Number(r&0xFFFFFFFFn)),await t.writeU32BE(a.timescale),await t.writeU32BE(Number(n&0xFFFFFFFFn)),await t.writeU16BE(s("und")),await t.writeU16BE(0),t.getBuffer()}async buildHdlr(a){let t=new B,r="",w="";if(a.track.type==="video")r="vide",w="VideoHandler";else if(a.track.type==="audio")r="soun",w="SoundHandler";else r="text",w="SubtitleHandler";let n=new TextEncoder().encode(`${w}\x00`),o=32+n.byteLength;return await t.writeU32BE(o),await t.writeFourCC("hdlr"),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeFourCC(r),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeBytes(n),t.getBuffer()}async buildMinf(a,t){let r=new B,w;if(a.track.type==="video")w=await this.buildVmhd();else if(a.track.type==="audio")w=await this.buildSmhd();else w=await this.buildNmhd();let n=await this.buildDinf(),o=await this.buildStbl(a,t),c=8+w.byteLength+n.byteLength+o.byteLength;return await r.writeU32BE(c),await r.writeFourCC("minf"),await r.writeBytes(w),await r.writeBytes(n),await r.writeBytes(o),r.getBuffer()}async buildVmhd(){let a=new B,t=20;return await a.writeU32BE(20),await a.writeFourCC("vmhd"),await a.writeU32BE(1),await a.writeU16BE(0),await a.writeU16BE(0),await a.writeU16BE(0),await a.writeU16BE(0),a.getBuffer()}async buildSmhd(){let a=new B,t=16;return await a.writeU32BE(16),await a.writeFourCC("smhd"),await a.writeU32BE(0),await a.writeU16BE(0),await a.writeU16BE(0),a.getBuffer()}async buildNmhd(){let a=new B,t=12;return await a.writeU32BE(12),await a.writeFourCC("nmhd"),await a.writeU32BE(0),a.getBuffer()}async buildDinf(){let a=new B,t=await this.buildDref(),r=8+t.byteLength;return await a.writeU32BE(r),await a.writeFourCC("dinf"),await a.writeBytes(t),a.getBuffer()}async buildDref(){let a=new B,t=28;return await a.writeU32BE(28),await a.writeFourCC("dref"),await a.writeU32BE(0),await a.writeU32BE(1),await a.writeU32BE(12),await a.writeFourCC("url "),await a.writeU32BE(1),a.getBuffer()}async buildStbl(a,t){let r=new B,w=await this.buildStsd(a),n=await this.buildStts(a),o=await this.buildStsc(a),c=await this.buildStsz(a),l=await this.buildStco(a,t),u=null,d=null;if(a.track.type==="video")u=await this.buildStss(a),d=await this.buildCtts(a);let U=8+w.byteLength+n.byteLength+o.byteLength+c.byteLength+l.byteLength;if(u)U+=u.byteLength;if(d)U+=d.byteLength;if(await r.writeU32BE(U),await r.writeFourCC("stbl"),await r.writeBytes(w),await r.writeBytes(n),d)await r.writeBytes(d);if(await r.writeBytes(o),await r.writeBytes(c),await r.writeBytes(l),u)await r.writeBytes(u);return r.getBuffer()}async buildStsd(a){let t=new B,r;if(a.track.type==="video")r=await this.buildVideoSampleEntry(a.track);else if(a.track.type==="audio")r=await this.buildAudioSampleEntry(a.track);else r=new Uint8Array(0);let w=16+r.byteLength;return await t.writeU32BE(w),await t.writeFourCC("stsd"),await t.writeU32BE(0),await t.writeU32BE(1),await t.writeBytes(r),t.getBuffer()}async buildVideoSampleEntry(a){let t=new B,r=a.config,w="";if(r.codec==="h264")w="avc1";else if(r.codec==="h265")w="hev1";else if(r.codec==="vp9")w="vp09";else if(r.codec==="av1")w="av01";else if(r.codec==="prores")w={proxy:"apco",lt:"apcs","422":"apcn",standard:"apcn",hq:"apch","4444":"ap4h","4444-xq":"ap4x"}[r.profile??"422"]??"apcn";else w="mp4v";let n=r.codecDescription??new Uint8Array(0),o=r.codec==="h264"?"avcC":r.codec==="h265"?"hvcC":r.codec==="vp9"?"vpcC":r.codec==="av1"?"av1C":void 0,c=o&&n.byteLength>0?8+n.byteLength:0,l=86+c;await t.writeU32BE(l),await t.writeFourCC(w),await t.writeU32BE(0),await t.writeU16BE(0),await t.writeU16BE(1),await t.writeU16BE(0),await t.writeU16BE(0),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU16BE(r.width),await t.writeU16BE(r.height),await t.writeU32BE(4718592),await t.writeU32BE(4718592),await t.writeU32BE(0),await t.writeU16BE(1);let u=new Uint8Array(32);if(await t.writeBytes(u),await t.writeU16BE(24),await t.writeI16BE(-1),c>0)await t.writeU32BE(c),await t.writeFourCC(o),await t.writeBytes(n);return t.getBuffer()}async buildAudioSampleEntry(a){let t=new B,r=a.config,w="mp4a";if(r.codec==="opus")w="Opus";else if(r.codec==="flac")w="fLaC";let n=r.codecDescription??new Uint8Array(0),o=n.byteLength>0?8+n.byteLength:0,c=36+o;if(await t.writeU32BE(c),await t.writeFourCC(w),await t.writeU32BE(0),await t.writeU16BE(0),await t.writeU16BE(1),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU16BE(r.channels),await t.writeU16BE(r.bitsPerSample??16),await t.writeU16BE(0),await t.writeU16BE(0),await t.writeU32BE(r.sampleRate<<16),o>0)await t.writeU32BE(o),await t.writeFourCC("esds"),await t.writeBytes(n);return t.getBuffer()}async buildStts(a){let t=new B,r=[],w=-1;for(let o of a.samples){let c=Math.round(o.duration*a.timescale);if(c===w&&r.length>0)r[r.length-1].sampleCount++;else r.push({sampleCount:1,sampleDelta:c}),w=c}let n=16+r.length*8;await t.writeU32BE(n),await t.writeFourCC("stts"),await t.writeU32BE(0),await t.writeU32BE(r.length);for(let o of r)await t.writeU32BE(o.sampleCount),await t.writeU32BE(o.sampleDelta);return t.getBuffer()}async buildCtts(a){let t=new B,r=[],w=Number.MIN_SAFE_INTEGER;for(let o of a.samples){let c=Math.round(o.compositionTimeOffset*a.timescale);if(c===w&&r.length>0)r[r.length-1].sampleCount++;else r.push({sampleCount:1,sampleOffset:c}),w=c}if(r.length===0||r.length===1&&r[0].sampleOffset===0)return new Uint8Array(0);let n=16+r.length*8;await t.writeU32BE(n),await t.writeFourCC("ctts"),await t.writeU32BE(0),await t.writeU32BE(r.length);for(let o of r)await t.writeU32BE(o.sampleCount),await t.writeU32BE(o.sampleOffset);return t.getBuffer()}async buildStsc(a){let t=new B,r=28;return await t.writeU32BE(28),await t.writeFourCC("stsc"),await t.writeU32BE(0),await t.writeU32BE(1),await t.writeU32BE(1),await t.writeU32BE(1),await t.writeU32BE(1),t.getBuffer()}async buildStsz(a){let t=new B,r=20+a.samples.length*4;await t.writeU32BE(r),await t.writeFourCC("stsz"),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU32BE(a.samples.length);for(let w of a.samples)await t.writeU32BE(w.size);return t.getBuffer()}async buildStco(a,t){let r=new B,w=t,n=[];for(let c of a.samples)n.push(w),w+=c.size;let o=16+n.length*4;await r.writeU32BE(o),await r.writeFourCC("stco"),await r.writeU32BE(0),await r.writeU32BE(n.length);for(let c of n)await r.writeU32BE(c);return r.getBuffer()}async buildStss(a){let t=new B,r=[];for(let n=0;n<a.samples.length;n++)if(a.samples[n].isKeyframe)r.push(n+1);if(r.length===a.samples.length)return new Uint8Array(0);let w=16+r.length*4;await t.writeU32BE(w),await t.writeFourCC("stss"),await t.writeU32BE(0),await t.writeU32BE(r.length);for(let n of r)await t.writeU32BE(n);return t.getBuffer()}async buildTref(a){let t=new B;return await t.writeU32BE(20),await t.writeFourCC("tref"),await t.writeU32BE(12),await t.writeFourCC("chap"),await t.writeU32BE(a),t.getBuffer()}buildChapterTextSamples(){if(this.chapters.length===0)return[];let a=0;for(let w of this.trackData.values()){let n=w.samples[w.samples.length-1];if(n)a=Math.max(a,Math.round((n.timestamp+n.duration)*1000))}let t=new TextEncoder,r=[];for(let w=0;w<this.chapters.length;w++){let n=this.chapters[w],o=w+1<this.chapters.length?this.chapters[w+1].startTimeMs:a,c=Math.max(1,Math.round(o-n.startTimeMs)),l=t.encode(n.title),u=new Uint8Array(2+l.length);u[0]=l.length>>8&255,u[1]=l.length&255,u.set(l,2),r.push({data:u,durationMs:c})}return r}async buildTextSampleEntry(){let a=new B;return await a.writeU32BE(59),await a.writeFourCC("text"),await a.writeU32BE(0),await a.writeU16BE(0),await a.writeU16BE(1),await a.writeU32BE(1),await a.writeU32BE(0),await a.writeU16BE(0),await a.writeU16BE(0),await a.writeU16BE(0),await a.writeU16BE(0),await a.writeU16BE(0),await a.writeU16BE(0),await a.writeU16BE(1),await a.writeU32BE(0),await a.writeU32BE(0),await a.writeU16BE(0),await a.writeU16BE(13),await a.writeFourCC("ftab"),await a.writeU16BE(1),await a.writeU16BE(1),await a.writeU8(0),a.getBuffer()}async buildChapterTrak(a,t,r){let w=new B,n=BigInt(Math.floor(Date.now()/1000))+e,o=1000,c=new TextEncoder,l=0;for(let E of t)l+=E.durationMs;let u=new B;await u.writeU32BE(92),await u.writeFourCC("tkhd"),await u.writeU8(0),await u.writeU8(0),await u.writeU8(0),await u.writeU8(1),await u.writeU32BE(Number(n&0xFFFFFFFFn)),await u.writeU32BE(Number(n&0xFFFFFFFFn)),await u.writeU32BE(a),await u.writeU32BE(0),await u.writeU32BE(l),await u.writeU32BE(0),await u.writeU32BE(0),await u.writeU16BE(0),await u.writeU16BE(0),await u.writeU16BE(0),await u.writeU16BE(0),await u.writeU32BE(65536),await u.writeU32BE(0),await u.writeU32BE(0),await u.writeU32BE(0),await u.writeU32BE(65536),await u.writeU32BE(0),await u.writeU32BE(0),await u.writeU32BE(0),await u.writeU32BE(1073741824),await u.writeU32BE(0),await u.writeU32BE(0);let d=u.getBuffer(),U=new B;await U.writeU32BE(32),await U.writeFourCC("mdhd"),await U.writeU32BE(0),await U.writeU32BE(Number(n&0xFFFFFFFFn)),await U.writeU32BE(Number(n&0xFFFFFFFFn)),await U.writeU32BE(1000),await U.writeU32BE(l),await U.writeU16BE(0),await U.writeU16BE(0);let f=U.getBuffer(),y=c.encode("ChapterHandler\x00"),m=new B;await m.writeU32BE(32+y.byteLength),await m.writeFourCC("hdlr"),await m.writeU32BE(0),await m.writeU32BE(0),await m.writeFourCC("text"),await m.writeU32BE(0),await m.writeU32BE(0),await m.writeU32BE(0),await m.writeBytes(y);let z=m.getBuffer(),g=new B;await g.writeU32BE(36),await g.writeFourCC("edts"),await g.writeU32BE(28),await g.writeFourCC("elst"),await g.writeU32BE(0),await g.writeU32BE(1),await g.writeU32BE(l),await g.writeU32BE(0),await g.writeU32BE(65536);let L=g.getBuffer(),h=new B;await h.writeU32BE(76),await h.writeFourCC("gmhd"),await h.writeU32BE(24),await h.writeFourCC("gmin"),await h.writeU32BE(0),await h.writeU16BE(64),await h.writeU16BE(32768),await h.writeU16BE(32768),await h.writeU16BE(32768),await h.writeU16BE(0),await h.writeU16BE(0),await h.writeU32BE(44),await h.writeFourCC("text"),await h.writeU32BE(65536),await h.writeU32BE(0),await h.writeU32BE(0),await h.writeU32BE(0),await h.writeU32BE(65536),await h.writeU32BE(0),await h.writeU32BE(0),await h.writeU32BE(0),await h.writeU32BE(1073741824);let D=h.getBuffer(),P=await this.buildDinf(),O=await this.buildTextSampleEntry(),k=new B;await k.writeU32BE(16+O.byteLength),await k.writeFourCC("stsd"),await k.writeU32BE(0),await k.writeU32BE(1),await k.writeBytes(O);let N=k.getBuffer(),C=[],I=-1;for(let E of t)if(E.durationMs===I&&C.length>0)C[C.length-1].count++;else C.push({count:1,delta:E.durationMs}),I=E.durationMs;let x=new B;await x.writeU32BE(16+C.length*8),await x.writeFourCC("stts"),await x.writeU32BE(0),await x.writeU32BE(C.length);for(let E of C)await x.writeU32BE(E.count),await x.writeU32BE(E.delta);let V=x.getBuffer(),b=new B;await b.writeU32BE(28),await b.writeFourCC("stsc"),await b.writeU32BE(0),await b.writeU32BE(1),await b.writeU32BE(1),await b.writeU32BE(1),await b.writeU32BE(1);let W=b.getBuffer(),v=new B;await v.writeU32BE(20+t.length*4),await v.writeFourCC("stsz"),await v.writeU32BE(0),await v.writeU32BE(0),await v.writeU32BE(t.length);for(let E of t)await v.writeU32BE(E.data.byteLength);let H=v.getBuffer(),M=new B;await M.writeU32BE(16+t.length*4),await M.writeFourCC("stco"),await M.writeU32BE(0),await M.writeU32BE(t.length);let j=r;for(let E of t)await M.writeU32BE(j),j+=E.data.byteLength;let R=M.getBuffer(),G=8+N.byteLength+V.byteLength+W.byteLength+H.byteLength+R.byteLength,F=new B;await F.writeU32BE(G),await F.writeFourCC("stbl"),await F.writeBytes(N),await F.writeBytes(V),await F.writeBytes(W),await F.writeBytes(H),await F.writeBytes(R);let _=F.getBuffer(),J=8+D.byteLength+P.byteLength+_.byteLength,A=new B;await A.writeU32BE(J),await A.writeFourCC("minf"),await A.writeBytes(D),await A.writeBytes(P),await A.writeBytes(_);let K=A.getBuffer(),Q=8+f.byteLength+z.byteLength+K.byteLength,S=new B;await S.writeU32BE(Q),await S.writeFourCC("mdia"),await S.writeBytes(f),await S.writeBytes(z),await S.writeBytes(K);let q=S.getBuffer(),X=8+d.byteLength+L.byteLength+q.byteLength;return await w.writeU32BE(X),await w.writeFourCC("trak"),await w.writeBytes(d),await w.writeBytes(L),await w.writeBytes(q),w.getBuffer()}async buildUdta(){let a=this.metadata&&Object.keys(this.metadata).length>0,t=this.artwork!==null,r=this.chapters.length>0;if(!a&&!t&&!r)return null;let w=new B,n=[];if(r)n.push(await this.buildChpl());if(a||t)n.push(await this.buildMeta());let o=n.reduce((c,l)=>c+l.byteLength,0);await w.writeU32BE(o+8),await w.writeFourCC("udta");for(let c of n)await w.writeBytes(c);return w.getBuffer()}async buildMeta(){let a=new B,t=await this.buildMetaHdlr(),r=await this.buildIlst(),w=4+t.byteLength+r.byteLength;return await a.writeU32BE(w+8),await a.writeFourCC("meta"),await a.writeU32BE(0),await a.writeBytes(t),await a.writeBytes(r),a.getBuffer()}async buildMetaHdlr(){let a=new B,t=33;return await a.writeU32BE(33),await a.writeFourCC("hdlr"),await a.writeU32BE(0),await a.writeU32BE(0),await a.writeFourCC("mdir"),await a.writeFourCC("appl"),await a.writeU32BE(0),await a.writeU32BE(0),await a.writeU8(0),a.getBuffer()}async buildIlst(){let a=new B,t=[],r=this.metadata;if(r.title)t.push(p("©nam",r.title));if(r.artist)t.push(p("©ART",r.artist));if(r.albumArtist)t.push(p("aART",r.albumArtist));if(r.album)t.push(p("©alb",r.album));if(r.genre)t.push(p("©gen",r.genre));if(r.year)t.push(p("©day",String(r.year)));if(r.composer)t.push(p("©wrt",r.composer));if(r.copyright)t.push(p("cprt",r.copyright));if(r.comment)t.push(p("©cmt",r.comment));if(r.encodedBy)t.push(p("©too",r.encodedBy));if(r.narrator)t.push(p("©nrt",r.narrator));if(r.publisher)t.push(p("©pub",r.publisher));if(r.description)t.push(p("desc",r.description));if(this.artwork){let n=this.artworkType==="png"?14:13;t.push(Z("covr",this.artwork,n))}let w=t.reduce((n,o)=>n+o.byteLength,0);await a.writeU32BE(w+8),await a.writeFourCC("ilst");for(let n of t)await a.writeBytes(n);return a.getBuffer()}async buildChpl(){let a=new B,t=new TextEncoder,r=[];for(let o of this.chapters){let c=t.encode(o.title),l=Math.min(c.length,255),u=BigInt(Math.round(o.startTimeMs*1e4)),d=new Uint8Array(9+l);new DataView(d.buffer).setBigUint64(0,u),d[8]=l,d.set(c.subarray(0,l),9),r.push(d)}let n=12+r.reduce((o,c)=>o+c.byteLength,0);await a.writeU32BE(n+8),await a.writeFourCC("chpl"),await a.writeU8(1),await a.writeU8(0),await a.writeU8(0),await a.writeU8(0),await a.writeU32BE(0),await a.writeU32BE(this.chapters.length);for(let o of r)await a.writeBytes(o);return a.getBuffer()}}function p(a,t){let w=new TextEncoder().encode(t),n=16+w.length,o=8+n,c=new Uint8Array(o),l=new DataView(c.buffer);return l.setUint32(0,o),c[4]=a.charCodeAt(0)&255,c[5]=a.charCodeAt(1)&255,c[6]=a.charCodeAt(2)&255,c[7]=a.charCodeAt(3)&255,l.setUint32(8,n),c[12]=100,c[13]=97,c[14]=116,c[15]=97,l.setUint32(16,1),l.setUint32(20,0),c.set(w,24),c}function Z(a,t,r){let w=16+t.length,n=8+w,o=new Uint8Array(n),c=new DataView(o.buffer);return c.setUint32(0,n),o[4]=a.charCodeAt(0)&255,o[5]=a.charCodeAt(1)&255,o[6]=a.charCodeAt(2)&255,o[7]=a.charCodeAt(3)&255,c.setUint32(8,w),o[12]=100,o[13]=97,o[14]=116,o[15]=97,c.setUint32(16,r),c.setUint32(20,0),o.set(t,24),o}
|
|
2
|
+
export{i};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{m,p}from"./chunk-qmjyh9jc.js";import{a}from"./chunk-yjtc1ksx.js";import{i}from"./chunk-c9md36vm.js";import{r}from"./chunk-tghqqx5m.js";import{InputFormat as u}from"ts-videos/demuxer";import{OutputFormat as s}from"ts-videos/muxer";import{Reader as c}from"ts-videos/reader";class f extends u{get name(){return"mp4"}get mimeType(){return"video/mp4"}get extensions(){return["mp4","m4v","m4a","f4v"]}async canRead(e){let t=c.fromSource(e);t.position=0;let n=await t.readU32BE();if(n===null||n<8)return!1;if(await t.readFourCC()!=="ftyp")return!1;let o=await t.readFourCC();if(!o)return!1;return m.has(o)}createDemuxer(e){return new a(e)}}class w extends u{get name(){return"mov"}get mimeType(){return"video/quicktime"}get extensions(){return["mov","qt"]}async canRead(e){let t=c.fromSource(e);t.position=0;let n=await t.readU32BE();if(n===null||n<8)return!1;if(await t.readFourCC()!=="ftyp")return!1;let o=await t.readFourCC();if(!o)return!1;return p.has(o)}createDemuxer(e){return new a(e)}}class h extends s{options;constructor(e={}){super();this.options=e}get name(){return"mp4"}get mimeType(){return"video/mp4"}get extension(){return"mp4"}createMuxer(e){return new i(e,this.options)}}class B extends s{options;constructor(e={}){super();this.options={...e,brand:"qt "}}get name(){return"mov"}get mimeType(){return"video/quicktime"}get extension(){return"mov"}createMuxer(e){return new i(e,this.options)}}class U extends s{options;constructor(e={}){super();this.options=e}get name(){return"fmp4"}get mimeType(){return"video/mp4"}get extension(){return"mp4"}createMuxer(e){return new r(e,this.options)}}class y extends s{options;constructor(e={}){super();this.options={...e,cmaf:!0}}get name(){return"cmaf"}get mimeType(){return"video/mp4"}get extension(){return"cmfv"}createMuxer(e){return new r(e,this.options)}}var E=new f,x=new w,C=new h,F=new B,v=new U,S=new y;
|
|
2
|
+
export{f,w,h,B,U,y,E,x,C,F,v,S};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var t=8,c=16;function u(r,i){return String.fromCharCode(r.getUint8(i),r.getUint8(i+1),r.getUint8(i+2),r.getUint8(i+3))}function b(r,i,x){for(let a=0;a<4;a++)r.setUint8(i+a,x.charCodeAt(a))}var d=new Set(["moov","trak","mdia","minf","stbl","dinf","edts","udta","meta","ilst","moof","traf","mvex","sinf","schi","rinf"]),m=new Set(["isom","iso2","iso3","iso4","iso5","iso6","mp41","mp42","mp71","avc1","av01","hev1","hvc1","M4A ","M4V ","M4P ","M4B ","f4v ","f4a ","dash","msdh","msix"]),p=new Set(["qt "]);function n(r){return r==="vide"}function o(r){return r==="soun"}function g(r){return r==="subt"||r==="text"||r==="sbtl"}function l(r){let i=(r>>10&31)+96,x=(r>>5&31)+96,a=(r&31)+96;return String.fromCharCode(i,x,a)}function s(r){if(r.length!==3)return 21956;let i=r.charCodeAt(0)-96&31,x=r.charCodeAt(1)-96&31,a=r.charCodeAt(2)-96&31;return i<<10|x<<5|a}var e=2082844800n;
|
|
2
|
+
export{t,c,u,b,d,m,p,n,o,g,l,s,e};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{s,e}from"./chunk-qmjyh9jc.js";import{Muxer as h}from"ts-videos/muxer";import{Writer as u}from"ts-videos/writer";var y=1000;class r extends h{trackData=new Map;options;sequenceNumber=1;fragmentStartTime=0;initialized=!1;constructor(i,t={}){super(i);if(this.options={fragmentDuration:t.fragmentDuration??2,brand:t.brand??"iso5",cmaf:t.cmaf??!1,lowLatency:t.lowLatency??!1},this.options.lowLatency)this.options.fragmentDuration=Math.min(0.5,this.options.fragmentDuration)}get formatName(){return"fmp4"}get mimeType(){return"video/mp4"}onTrackAdded(i){let t=i.type==="video"?Math.round((i.config.frameRate??30)*1000):i.type==="audio"?i.config.sampleRate:1000;this.trackData.set(i.id,{track:i,timescale:t,samples:[],baseMediaDecodeTime:0n,defaultSampleDuration:0,defaultSampleSize:0,defaultSampleFlags:i.type==="video"?65536:0})}async writeHeader(){await this.writeFtyp(),await this.writeMoov(),this.initialized=!0}async writeFtyp(){let i=this.options.cmaf?["cmfc","iso6","mp41"]:[this.options.brand,"iso5","iso6","mp41","avc1"],t=16+i.length*4;await this.writer.writeU32BE(t),await this.writer.writeFourCC("ftyp"),await this.writer.writeFourCC(this.options.cmaf?"cmfc":this.options.brand),await this.writer.writeU32BE(512);for(let a of i)await this.writer.writeFourCC(a)}async writeMoov(){let i=new u,t=await this.buildMvhd(),a=await this.buildMvex(),w=[];for(let o of this.trackData.values()){let m=await this.buildTrak(o);w.push(m)}let c=t.byteLength+a.byteLength+w.reduce((o,m)=>o+m.byteLength,0)+8;await i.writeU32BE(c),await i.writeFourCC("moov"),await i.writeBytes(t);for(let o of w)await i.writeBytes(o);await i.writeBytes(a),await this.writer.writeBytes(i.getBuffer())}async buildMvhd(){let i=new u,t=BigInt(Math.floor(Date.now()/1000))+e,a=116;await i.writeU32BE(116),await i.writeFourCC("mvhd"),await i.writeU8(0),await i.writeU8(0),await i.writeU8(0),await i.writeU8(0),await i.writeU32BE(Number(t&0xFFFFFFFFn)),await i.writeU32BE(Number(t&0xFFFFFFFFn)),await i.writeU32BE(y),await i.writeU32BE(0),await i.writeU32BE(65536),await i.writeU16BE(256),await i.writeU16BE(0),await i.writeU32BE(0),await i.writeU32BE(0),await i.writeU32BE(65536),await i.writeU32BE(0),await i.writeU32BE(0),await i.writeU32BE(0),await i.writeU32BE(65536),await i.writeU32BE(0),await i.writeU32BE(0),await i.writeU32BE(0),await i.writeU32BE(1073741824);for(let w=0;w<6;w++)await i.writeU32BE(0);return await i.writeU32BE(this.tracks.length+1),i.getBuffer()}async buildMvex(){let i=new u,t=[];for(let w of this.trackData.values())t.push(await this.buildTrex(w));let a=8+t.reduce((w,n)=>w+n.byteLength,0);await i.writeU32BE(a),await i.writeFourCC("mvex");for(let w of t)await i.writeBytes(w);return i.getBuffer()}async buildTrex(i){let t=new u,a=32;return await t.writeU32BE(32),await t.writeFourCC("trex"),await t.writeU32BE(0),await t.writeU32BE(i.track.id),await t.writeU32BE(1),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU32BE(i.defaultSampleFlags),t.getBuffer()}async buildTrak(i){let t=new u,a=await this.buildTkhd(i),w=await this.buildMdia(i),n=8+a.byteLength+w.byteLength;return await t.writeU32BE(n),await t.writeFourCC("trak"),await t.writeBytes(a),await t.writeBytes(w),t.getBuffer()}async buildTkhd(i){let t=new u,a=BigInt(Math.floor(Date.now()/1000))+e,w=92,n=i.track,c=0,o=0,m=0;if(n.type==="video")c=n.config.width,o=n.config.height;else if(n.type==="audio")m=256;return await t.writeU32BE(92),await t.writeFourCC("tkhd"),await t.writeU8(0),await t.writeU8(0),await t.writeU8(0),await t.writeU8(3),await t.writeU32BE(Number(a&0xFFFFFFFFn)),await t.writeU32BE(Number(a&0xFFFFFFFFn)),await t.writeU32BE(n.id),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU16BE(0),await t.writeU16BE(0),await t.writeU16BE(m),await t.writeU16BE(0),await t.writeU32BE(65536),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU32BE(65536),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU32BE(1073741824),await t.writeU32BE(c<<16),await t.writeU32BE(o<<16),t.getBuffer()}async buildMdia(i){let t=new u,a=await this.buildMdhd(i),w=await this.buildHdlr(i),n=await this.buildMinf(i),c=8+a.byteLength+w.byteLength+n.byteLength;return await t.writeU32BE(c),await t.writeFourCC("mdia"),await t.writeBytes(a),await t.writeBytes(w),await t.writeBytes(n),t.getBuffer()}async buildMdhd(i){let t=new u,a=BigInt(Math.floor(Date.now()/1000))+e,w=40;return await t.writeU32BE(40),await t.writeFourCC("mdhd"),await t.writeU8(0),await t.writeU8(0),await t.writeU8(0),await t.writeU8(0),await t.writeU32BE(Number(a&0xFFFFFFFFn)),await t.writeU32BE(Number(a&0xFFFFFFFFn)),await t.writeU32BE(i.timescale),await t.writeU32BE(0),await t.writeU16BE(s("und")),await t.writeU16BE(0),t.getBuffer()}async buildHdlr(i){let t=new u,a="",w="";if(i.track.type==="video")a="vide",w="VideoHandler";else if(i.track.type==="audio")a="soun",w="SoundHandler";else a="text",w="SubtitleHandler";let n=new TextEncoder().encode(`${w}\x00`),c=32+n.byteLength+8;return await t.writeU32BE(c),await t.writeFourCC("hdlr"),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeFourCC(a),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeBytes(n),t.getBuffer()}async buildMinf(i){let t=new u,a;if(i.track.type==="video")a=await this.buildVmhd();else if(i.track.type==="audio")a=await this.buildSmhd();else a=await this.buildNmhd();let w=await this.buildDinf(),n=await this.buildStbl(i),c=8+a.byteLength+w.byteLength+n.byteLength;return await t.writeU32BE(c),await t.writeFourCC("minf"),await t.writeBytes(a),await t.writeBytes(w),await t.writeBytes(n),t.getBuffer()}async buildVmhd(){let i=new u,t=20;return await i.writeU32BE(20),await i.writeFourCC("vmhd"),await i.writeU32BE(1),await i.writeU16BE(0),await i.writeU16BE(0),await i.writeU16BE(0),await i.writeU16BE(0),i.getBuffer()}async buildSmhd(){let i=new u,t=16;return await i.writeU32BE(16),await i.writeFourCC("smhd"),await i.writeU32BE(0),await i.writeU16BE(0),await i.writeU16BE(0),i.getBuffer()}async buildNmhd(){let i=new u,t=12;return await i.writeU32BE(12),await i.writeFourCC("nmhd"),await i.writeU32BE(0),i.getBuffer()}async buildDinf(){let i=new u,t=await this.buildDref(),a=8+t.byteLength;return await i.writeU32BE(a),await i.writeFourCC("dinf"),await i.writeBytes(t),i.getBuffer()}async buildDref(){let i=new u,t=28;return await i.writeU32BE(28),await i.writeFourCC("dref"),await i.writeU32BE(0),await i.writeU32BE(1),await i.writeU32BE(12),await i.writeFourCC("url "),await i.writeU32BE(1),i.getBuffer()}async buildStbl(i){let t=new u,a=await this.buildStsd(i),w=await this.buildEmptyAtom("stts"),n=await this.buildEmptyAtom("stsc"),c=await this.buildEmptyStsz(),o=await this.buildEmptyAtom("stco"),m=8+a.byteLength+w.byteLength+n.byteLength+c.byteLength+o.byteLength;return await t.writeU32BE(m),await t.writeFourCC("stbl"),await t.writeBytes(a),await t.writeBytes(w),await t.writeBytes(n),await t.writeBytes(c),await t.writeBytes(o),t.getBuffer()}async buildEmptyAtom(i){let t=new u;return await t.writeU32BE(16),await t.writeFourCC(i),await t.writeU32BE(0),await t.writeU32BE(0),t.getBuffer()}async buildEmptyStsz(){let i=new u;return await i.writeU32BE(20),await i.writeFourCC("stsz"),await i.writeU32BE(0),await i.writeU32BE(0),await i.writeU32BE(0),i.getBuffer()}async buildStsd(i){let t=new u,a;if(i.track.type==="video")a=await this.buildVideoSampleEntry(i.track);else if(i.track.type==="audio")a=await this.buildAudioSampleEntry(i.track);else a=new Uint8Array(0);let w=16+a.byteLength;return await t.writeU32BE(w),await t.writeFourCC("stsd"),await t.writeU32BE(0),await t.writeU32BE(1),await t.writeBytes(a),t.getBuffer()}async buildVideoSampleEntry(i){let t=new u,a=i.config,w="";if(a.codec==="h264")w="avc1";else if(a.codec==="h265")w="hev1";else if(a.codec==="vp9")w="vp09";else if(a.codec==="av1")w="av01";else w="mp4v";let n=a.codecDescription??new Uint8Array(0),c=a.codec==="h264"?"avcC":a.codec==="h265"?"hvcC":"avcC",o=n.byteLength>0?8+n.byteLength:0,m=86+o;await t.writeU32BE(m),await t.writeFourCC(w),await t.writeU32BE(0),await t.writeU16BE(0),await t.writeU16BE(1),await t.writeU16BE(0),await t.writeU16BE(0),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU16BE(a.width),await t.writeU16BE(a.height),await t.writeU32BE(4718592),await t.writeU32BE(4718592),await t.writeU32BE(0),await t.writeU16BE(1);let d=new Uint8Array(32);if(await t.writeBytes(d),await t.writeU16BE(24),await t.writeI16BE(-1),o>0)await t.writeU32BE(o),await t.writeFourCC(c),await t.writeBytes(n);return t.getBuffer()}async buildAudioSampleEntry(i){let t=new u,a=i.config,w="mp4a";if(a.codec==="opus")w="Opus";else if(a.codec==="flac")w="fLaC";let n=a.codecDescription??new Uint8Array(0),c=n.byteLength>0?8+n.byteLength:0,o=36+c;if(await t.writeU32BE(o),await t.writeFourCC(w),await t.writeU32BE(0),await t.writeU16BE(0),await t.writeU16BE(1),await t.writeU32BE(0),await t.writeU32BE(0),await t.writeU16BE(a.channels),await t.writeU16BE(a.bitsPerSample??16),await t.writeU16BE(0),await t.writeU16BE(0),await t.writeU32BE(a.sampleRate<<16),c>0)await t.writeU32BE(c),await t.writeFourCC("esds"),await t.writeBytes(n);return t.getBuffer()}async writeVideoPacket(i,t){await this.writeSample(i.id,t)}async writeAudioPacket(i,t){await this.writeSample(i.id,t)}async writeSubtitlePacket(i,t){await this.writeSample(i.id,t)}async writeSample(i,t){let a=this.trackData.get(i);if(!a)return;let w=[...this.trackData.values()].some((d)=>d.track.type==="video"),n=[...this.trackData.values()].some((d)=>d.samples.length>0),c=t.timestamp-this.fragmentStartTime>=this.options.fragmentDuration,o=a.track.type==="video"&&t.isKeyframe;if(n&&c&&(o||!w))await this.flushFragment();let m={data:t.data,timestamp:t.timestamp,duration:t.duration??0,isKeyframe:t.isKeyframe,compositionTimeOffset:t.compositionTimeOffset??0,size:t.data.byteLength};a.samples.push(m)}async flushFragment(){let i=!1;for(let n of this.trackData.values())if(n.samples.length>0){i=!0;break}if(!i)return;let t=await this.buildMoof(),a=await this.buildFragmentMdat();await this.writer.writeBytes(t),await this.writer.writeBytes(a),this.sequenceNumber++;let w=this.fragmentStartTime;for(let n of this.trackData.values()){if(n.samples.length>0){n.baseMediaDecodeTime+=n.samples.reduce((c,o)=>c+BigInt(Math.round(o.duration*n.timescale)),0n);for(let c of n.samples)w=Math.max(w,c.timestamp+c.duration)}n.samples=[]}this.fragmentStartTime=w}async buildMoof(){let i=new u,t=await this.buildMfhd(),a=[],w=8;for(let o of this.trackData.values())if(o.samples.length>0){a.push(await this.buildTraf(o,w));for(let m of o.samples)w+=m.size}let n=8+t.byteLength;for(let o of a)n+=o.byteLength;let c=[];w=n+8;for(let o of this.trackData.values())if(o.samples.length>0){c.push(await this.buildTraf(o,w));for(let m of o.samples)w+=m.size}n=8+t.byteLength;for(let o of c)n+=o.byteLength;await i.writeU32BE(n),await i.writeFourCC("moof"),await i.writeBytes(t);for(let o of c)await i.writeBytes(o);return i.getBuffer()}async buildMfhd(){let i=new u,t=16;return await i.writeU32BE(16),await i.writeFourCC("mfhd"),await i.writeU32BE(0),await i.writeU32BE(this.sequenceNumber),i.getBuffer()}async buildTraf(i,t){let a=new u,w=await this.buildTfhd(i),n=await this.buildTfdt(i),c=await this.buildTrun(i,t),o=8+w.byteLength+n.byteLength+c.byteLength;return await a.writeU32BE(o),await a.writeFourCC("traf"),await a.writeBytes(w),await a.writeBytes(n),await a.writeBytes(c),a.getBuffer()}async buildTfhd(i){let t=new u,a=0;if(i.samples.length>0){let c=Math.round(i.samples[0].duration*i.timescale);if(i.samples.every((m)=>Math.round(m.duration*i.timescale)===c))a=c}let w=131072|(a>0?8:0),n=16+(a>0?4:0);if(await t.writeU32BE(n),await t.writeFourCC("tfhd"),await t.writeU8(0),await t.writeU8(w>>16&255),await t.writeU8(w>>8&255),await t.writeU8(w&255),await t.writeU32BE(i.track.id),a>0)await t.writeU32BE(a);return t.getBuffer()}async buildTfdt(i){let t=new u,a=20;return await t.writeU32BE(20),await t.writeFourCC("tfdt"),await t.writeU8(1),await t.writeU8(0),await t.writeU8(0),await t.writeU8(0),await t.writeU64BE(i.baseMediaDecodeTime),t.getBuffer()}async buildTrun(i,t){let a=new u,w=!i.samples.every((f,l,U)=>l===0||Math.round(f.duration*i.timescale)===Math.round(U[0].duration*i.timescale)),n=!i.samples.every((f)=>f.size===i.samples[0].size),c=i.samples.some((f)=>f.isKeyframe!==i.samples[0].isKeyframe),o=i.samples.some((f)=>f.compositionTimeOffset!==0),m=1|(w?256:0)|(n?512:0)|(c?1024:0)|(o?2048:0),d=0;if(w)d+=4;if(n)d+=4;if(c)d+=4;if(o)d+=4;let B=20+i.samples.length*d;await a.writeU32BE(B),await a.writeFourCC("trun"),await a.writeU8(0),await a.writeU8(m>>16&255),await a.writeU8(m>>8&255),await a.writeU8(m&255),await a.writeU32BE(i.samples.length),await a.writeU32BE(t);for(let f of i.samples){if(w)await a.writeU32BE(Math.round(f.duration*i.timescale));if(n)await a.writeU32BE(f.size);if(c){let l=f.isKeyframe?0:65536;await a.writeU32BE(l)}if(o)await a.writeI32BE(Math.round(f.compositionTimeOffset*i.timescale))}return a.getBuffer()}async buildFragmentMdat(){let i=new u,t=0;for(let a of this.trackData.values())for(let w of a.samples)t+=w.size;await i.writeU32BE(t+8),await i.writeFourCC("mdat");for(let a of this.trackData.values())for(let w of a.samples)await i.writeBytes(w.data);return i.getBuffer()}async writeTrailer(){await this.flushFragment(),await this.writeMfra()}async writeMfra(){let i=new u,t=[],a=16,w=24;await i.writeU32BE(24),await i.writeFourCC("mfra"),await i.writeU32BE(16),await i.writeFourCC("mfro"),await i.writeU32BE(0),await i.writeU32BE(24),await this.writer.writeBytes(i.getBuffer())}}
|
|
2
|
+
export{r};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{t,c,u,d,n,o,l}from"./chunk-qmjyh9jc.js";import{Demuxer as j}from"ts-videos/demuxer";class a extends j{movieTimescale=1000;movieDuration=0n;trackInfos=[];moovBox=null;mdatOffset=0;fragmented=!1;_initialized=!1;majorBrand="";get formatName(){return this.majorBrand==="qt "?"mov":"mp4"}get mimeType(){let s=this._tracks?.find((p)=>p.type==="video"),e=this._tracks?.find((p)=>p.type==="audio"),r="";if(s&&e)r=`${this.getCodecString(s)}, ${this.getCodecString(e)}`;else if(s)r=this.getCodecString(s);else if(e)r=this.getCodecString(e);let i=this.majorBrand==="qt "?"video/quicktime":"video/mp4";return r?`${i}; codecs="${r}"`:i}getCodecString(s){if(s.type==="video"){let e=s;if(e.codec==="h264"&&e.codecDescription){let r=e.codecDescription;if(r.length>=4){let i=r[1].toString(16).padStart(2,"0"),p=r[2].toString(16).padStart(2,"0"),h=r[3].toString(16).padStart(2,"0");return`avc1.${i}${p}${h}`}return"avc1"}if(e.codec==="h265")return"hev1";if(e.codec==="vp9")return"vp09";if(e.codec==="av1")return"av01";return e.codec}if(s.type==="audio"){let e=s;if(e.codec==="aac")return"mp4a.40.2";if(e.codec==="mp3")return"mp4a.40.34";if(e.codec==="opus")return"opus";if(e.codec==="flac")return"flac";return e.codec}return"unknown"}async init(){if(this._initialized)return;this._initialized=!0,await this.parseTopLevelBoxes(),await this.buildTracks(),await this.buildSampleTables()}async parseTopLevelBoxes(){let s=await this.reader.getSize(),e=0;while(s===null||e<s){this.reader.position=e;let r=await this.reader.readU32BE();if(r===null)break;let i=await this.reader.readFourCC();if(!i)break;let p=r;if(p===1){let h=await this.reader.readU64BE();if(h===null)break;p=Number(h)}else if(p===0)p=(s??0)-e;if(i==="ftyp")await this.parseFtyp(e,p);else if(i==="moov")this.moovBox={type:i,size:p,offset:e},await this.parseMoov(e,p);else if(i==="mdat")this.mdatOffset=e+t;else if(i==="moof")this.fragmented=!0;e+=p}}async parseFtyp(s,e){this.reader.position=s+t,this.majorBrand=await this.reader.readFourCC()??"",await this.reader.readU32BE();let r=(e-16)/4;for(let i=0;i<r;i++)await this.reader.readFourCC()}async parseMoov(s,e){await this.parseContainerBox(s+t,e-t)}async parseContainerBox(s,e){let r=[],i=s,p=s+e;while(i<p){this.reader.position=i;let h=await this.reader.readU32BE();if(h===null)break;let f=await this.reader.readFourCC();if(!f)break;let B=h,v=t;if(B===1){let b=await this.reader.readU64BE();if(b===null)break;B=Number(b),v=c}else if(B===0)B=p-i;let k={type:f,size:B,offset:i};if(d.has(f))k.children=await this.parseContainerBox(i+v,B-v);r.push(k),i+=B}return r}async buildTracks(){if(!this.moovBox)throw Error("No moov box found");let s=await this.parseContainerBox(this.moovBox.offset+t,this.moovBox.size-t),e=s.find((i)=>i.type==="mvhd");if(e)await this.parseMvhd(e);let r=s.filter((i)=>i.type==="trak");this._tracks=[];for(let i=0;i<r.length;i++){let p=await this.parseTrack(r[i],i);if(p)this._tracks.push(p)}this._metadata=await this.parseMetadata(s),this._duration=Number(this.movieDuration)/this.movieTimescale}async parseMvhd(s){this.reader.position=s.offset+t;let e=await this.reader.readU8();if(e===null)return;if(await this.reader.skip(3),e===1)await this.reader.skip(16),this.movieTimescale=await this.reader.readU32BE()??1000,this.movieDuration=await this.reader.readU64BE()??0n;else await this.reader.skip(8),this.movieTimescale=await this.reader.readU32BE()??1000,this.movieDuration=BigInt(await this.reader.readU32BE()??0)}async parseTrack(s,e){let r=s.children??[],i=r.find((m)=>m.type==="tkhd"),p=r.find((m)=>m.type==="mdia");if(!i||!p)return null;let h=await this.parseTkhd(i),f=p.children??[],B=f.find((m)=>m.type==="mdhd"),v=f.find((m)=>m.type==="hdlr"),k=f.find((m)=>m.type==="minf");if(!B||!v||!k)return null;let b=await this.parseMdhd(B),y=await this.parseHdlr(v),U=(k.children??[]).find((m)=>m.type==="stbl");if(!U)return null;let x=(U.children??[]).find((m)=>m.type==="stsd");if(!x)return null;let g=await this.parseStsd(x,y.handlerType),S={id:h.trackId,index:e,type:n(y.handlerType)?"video":o(y.handlerType)?"audio":"subtitle",timescale:b.timescale,duration:b.duration,samples:[],currentSampleIndex:0};if(this.trackInfos.push(S),n(y.handlerType)&&g.entries.length>0){let m=g.entries[0];return{type:"video",id:h.trackId,index:e,codec:this.getVideoCodec(m.type),width:m.width,height:m.height,profile:this.getVideoProfile(m.type),frameRate:this.calculateFrameRate(S),isDefault:(h.flags&1)!==0,language:b.language,codecDescription:this.extractCodecDescription(m),colorSpace:this.extractColorSpace(m),rotation:this.getRotation(h.matrix)}}if(o(y.handlerType)&&g.entries.length>0){let m=g.entries[0];return{type:"audio",id:h.trackId,index:e,codec:this.getAudioCodec(m.type),sampleRate:m.sampleRate,channels:m.channelCount,bitsPerSample:m.sampleSize,isDefault:(h.flags&1)!==0,language:b.language,codecDescription:this.extractCodecDescription(m)}}return null}async parseTkhd(s){this.reader.position=s.offset+t;let e=await this.reader.readU8(),r=(await this.reader.readU8()??0)<<16|(await this.reader.readU8()??0)<<8|(await this.reader.readU8()??0),i=0;if(e===1)await this.reader.skip(16),i=await this.reader.readU32BE()??0,await this.reader.skip(12);else await this.reader.skip(8),i=await this.reader.readU32BE()??0,await this.reader.skip(8);await this.reader.skip(8);let p=[];for(let B=0;B<9;B++)p.push(await this.reader.readI32BE()??0);let h=(await this.reader.readU32BE()??0)/65536,f=(await this.reader.readU32BE()??0)/65536;return{trackId:i,flags:r,width:h,height:f,matrix:p}}async parseMdhd(s){this.reader.position=s.offset+t;let e=await this.reader.readU8();await this.reader.skip(3);let r=1000,i=0n;if(e===1)await this.reader.skip(16),r=await this.reader.readU32BE()??1000,i=await this.reader.readU64BE()??0n;else await this.reader.skip(8),r=await this.reader.readU32BE()??1000,i=BigInt(await this.reader.readU32BE()??0);let p=await this.reader.readU16BE()??0,h=l(p);return{timescale:r,duration:i,language:h}}async parseHdlr(s){this.reader.position=s.offset+t,await this.reader.skip(8);let e=await this.reader.readFourCC()??"";await this.reader.skip(12);let r=s.size-t-24,i=r>0?await this.reader.readString(r)??"":"";return{handlerType:e,name:i.replace(/\0/g,"")}}async parseStsd(s,e){this.reader.position=s.offset+t,await this.reader.skip(4);let r=await this.reader.readU32BE()??0,i=[];for(let p=0;p<r;p++){let h=await this.reader.readU32BE()??0,f=await this.reader.readFourCC()??"",B=this.reader.position;await this.reader.skip(6);let v=await this.reader.readU16BE()??0;if(n(e)){await this.reader.skip(16);let k=await this.reader.readU16BE()??0,b=await this.reader.readU16BE()??0,y=await this.reader.readU32BE()??0,E=await this.reader.readU32BE()??0;await this.reader.skip(4);let U=await this.reader.readU16BE()??1,C=await this.reader.readU8()??0,x=await this.reader.readString(31)??"",g=await this.reader.readU16BE()??24;await this.reader.skip(2);let S=await this.parseExtensions(B+h-8);i.push({type:f,dataReferenceIndex:v,width:k,height:b,horizResolution:y,vertResolution:E,frameCount:U,compressorName:x.slice(0,C),depth:g,extensions:S,data:new Uint8Array(0)})}else if(o(e)){await this.reader.skip(8);let k=await this.reader.readU16BE()??2,b=await this.reader.readU16BE()??16;await this.reader.skip(4);let y=(await this.reader.readU32BE()??-1404829696)>>16,E=await this.parseExtensions(B+h-8);i.push({type:f,dataReferenceIndex:v,channelCount:k,sampleSize:b,sampleRate:y,extensions:E,data:new Uint8Array(0)})}this.reader.position=B+h-8}return{entries:i}}async parseExtensions(s){let e=[];while(this.reader.position<s){let r=await this.reader.readU32BE()??0;if(r<8)break;let i=await this.reader.readFourCC()??"",p=await this.reader.readBytes(r-8);e.push({type:i,size:r,offset:this.reader.position-r,data:p??void 0})}return e}getVideoCodec(s){switch(s){case"avc1":case"avc3":return"h264";case"hev1":case"hvc1":return"h265";case"vp08":return"vp8";case"vp09":return"vp9";case"av01":return"av1";case"mp4v":return"mpeg4";case"apco":case"apcs":case"apcn":case"apch":case"ap4h":case"ap4x":return"prores";default:return"unknown"}}getVideoProfile(s){switch(s){case"apco":return"proxy";case"apcs":return"lt";case"apcn":return"422";case"apch":return"hq";case"ap4h":return"4444";case"ap4x":return"4444-xq";default:return}}extractColorSpace(s){let e=s.extensions.find((f)=>f.type==="colr")?.data;if(!e||e.length<11)return;let r=new DataView(e.buffer,e.byteOffset,e.byteLength);if(u(r,0)!=="nclx")return;let i=new Map([[1,"bt709"],[4,"bt470m"],[5,"bt470bg"],[6,"smpte170m"],[7,"smpte240m"],[8,"film"],[9,"bt2020"],[10,"smpte428"],[11,"smpte431"],[12,"smpte432"],[22,"ebu3213"]]).get(r.getUint16(4)),p=new Map([[1,"bt709"],[4,"bt470m"],[5,"bt470bg"],[6,"smpte170m"],[7,"smpte240m"],[8,"linear"],[9,"log100"],[10,"log316"],[11,"iec61966-2-4"],[12,"bt1361e"],[13,"iec61966-2-1"],[14,"bt2020-10"],[15,"bt2020-12"],[16,"smpte2084"],[17,"smpte428"],[18,"arib-std-b67"]]).get(r.getUint16(6)),h=new Map([[0,"rgb"],[1,"bt709"],[4,"fcc"],[5,"bt470bg"],[6,"smpte170m"],[7,"smpte240m"],[8,"ycocg"],[9,"bt2020nc"],[10,"bt2020c"],[11,"smpte2085"],[12,"chroma-derived-nc"],[13,"chroma-derived-c"],[14,"ictcp"]]).get(r.getUint16(8));if(!i&&!p&&!h)return;return{primaries:i,transfer:p,matrix:h,range:(e[10]&128)!==0?"full":"limited"}}getAudioCodec(s){switch(s){case"mp4a":return"aac";case".mp3":case"mp3 ":return"mp3";case"Opus":return"opus";case"fLaC":return"flac";case"alac":return"alac";case"ac-3":return"ac3";case"ec-3":return"eac3";default:return"unknown"}}extractCodecDescription(s){for(let e of s.extensions)if(e.type==="avcC"||e.type==="hvcC"||e.type==="av1C"||e.type==="esds")return e.data;return}getRotation(s){let e=s[0]/65536,r=s[1]/65536,i=s[3]/65536,p=s[4]/65536;if(Math.abs(e-1)<0.01&&Math.abs(p-1)<0.01)return 0;if(Math.abs(r-1)<0.01&&Math.abs(i+1)<0.01)return 90;if(Math.abs(e+1)<0.01&&Math.abs(p+1)<0.01)return 180;if(Math.abs(r+1)<0.01&&Math.abs(i-1)<0.01)return 270;return 0}calculateFrameRate(s){return}async parseMetadata(s){return{}}async buildSampleTables(){if(!this.moovBox)return;let e=(await this.parseContainerBox(this.moovBox.offset+t,this.moovBox.size-t)).filter((r)=>r.type==="trak");for(let r=0;r<e.length&&r<this.trackInfos.length;r++)await this.buildSampleTable(e[r],this.trackInfos[r])}async buildSampleTable(s,e){let i=(s.children??[]).find((w)=>w.type==="mdia");if(!i?.children)return;let p=i.children.find((w)=>w.type==="minf");if(!p?.children)return;let h=p.children.find((w)=>w.type==="stbl");if(!h?.children)return;let f=h.children,B=f.find((w)=>w.type==="stts"),v=f.find((w)=>w.type==="ctts"),k=f.find((w)=>w.type==="stsc"),b=f.find((w)=>w.type==="stsz"),y=f.find((w)=>w.type==="stco"),E=f.find((w)=>w.type==="co64"),U=f.find((w)=>w.type==="stss");if(!B||!k||!b||!y&&!E)return;let C=await this.parseStts(B),x=v?await this.parseCtts(v):null,g=await this.parseStsc(k),S=await this.parseStsz(b),m=y?await this.parseStco(y):await this.parseCo64(E),I=U?new Set(await this.parseStss(U)):null,z=0,A=0,P=0,D=C.length>0?C[0].sampleCount:0,T=0,M=x&&x.length>0?x[0].sampleCount:0;for(let w=0;w<m.length;w++){let V=m[w],F=this.getSamplesPerChunk(g,w+1),_=0;for(let O=0;O<F;O++){let N=S.sampleSize>0?S.sampleSize:S.entrySizes[z]??0,R=C[P]?.sampleDelta??0,H=x&&x[T]?x[T].sampleOffset:0,L=I===null||I.has(z+1);if(e.samples.push({offset:V+_,size:N,timestamp:A/e.timescale,duration:R/e.timescale,isKeyframe:L,compositionTimeOffset:H/e.timescale}),_+=N,A+=R,z++,D--,D===0&&P<C.length-1)P++,D=C[P].sampleCount;if(x){if(M--,M===0&&T<x.length-1)T++,M=x[T].sampleCount}}}}async parseStts(s){this.reader.position=s.offset+t,await this.reader.skip(4);let e=await this.reader.readU32BE()??0,r=[];for(let i=0;i<e;i++){let p=await this.reader.readU32BE()??0,h=await this.reader.readU32BE()??0;r.push({sampleCount:p,sampleDelta:h})}return r}async parseCtts(s){this.reader.position=s.offset+t;let e=await this.reader.readU8()??0;await this.reader.skip(3);let r=await this.reader.readU32BE()??0,i=[];for(let p=0;p<r;p++){let h=await this.reader.readU32BE()??0,f=e===1?await this.reader.readI32BE()??0:await this.reader.readU32BE()??0;i.push({sampleCount:h,sampleOffset:f})}return i}async parseStsc(s){this.reader.position=s.offset+t,await this.reader.skip(4);let e=await this.reader.readU32BE()??0,r=[];for(let i=0;i<e;i++){let p=await this.reader.readU32BE()??0,h=await this.reader.readU32BE()??0,f=await this.reader.readU32BE()??0;r.push({firstChunk:p,samplesPerChunk:h,sampleDescriptionIndex:f})}return r}async parseStsz(s){this.reader.position=s.offset+t,await this.reader.skip(4);let e=await this.reader.readU32BE()??0,r=await this.reader.readU32BE()??0,i=[];if(e===0)for(let p=0;p<r;p++)i.push(await this.reader.readU32BE()??0);return{sampleSize:e,sampleCount:r,entrySizes:i}}async parseStco(s){this.reader.position=s.offset+t,await this.reader.skip(4);let e=await this.reader.readU32BE()??0,r=[];for(let i=0;i<e;i++)r.push(await this.reader.readU32BE()??0);return r}async parseCo64(s){this.reader.position=s.offset+t,await this.reader.skip(4);let e=await this.reader.readU32BE()??0,r=[];for(let i=0;i<e;i++)r.push(Number(await this.reader.readU64BE()??0n));return r}async parseStss(s){this.reader.position=s.offset+t,await this.reader.skip(4);let e=await this.reader.readU32BE()??0,r=[];for(let i=0;i<e;i++)r.push(await this.reader.readU32BE()??0);return r}getSamplesPerChunk(s,e){for(let r=s.length-1;r>=0;r--)if(e>=s[r].firstChunk)return s[r].samplesPerChunk;return 1}async readPacket(s){let e=this.trackInfos.find((p)=>p.id===s);if(!e||e.currentSampleIndex>=e.samples.length)return null;let r=e.samples[e.currentSampleIndex];e.currentSampleIndex++,this.reader.position=r.offset;let i=await this.reader.readBytes(r.size);if(!i)return null;return{data:i,timestamp:r.timestamp,duration:r.duration,isKeyframe:r.isKeyframe,trackId:s,compositionTimeOffset:r.compositionTimeOffset}}async seek(s){for(let e of this.trackInfos){let r=0;for(let i=0;i<e.samples.length;i++){if(e.samples[i].timestamp>s)break;if(e.samples[i].isKeyframe)r=i}e.currentSampleIndex=r}}}
|
|
2
|
+
export{a};
|
package/dist/demuxer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{a}from"./chunk-yjtc1ksx.js";import"./chunk-qmjyh9jc.js";export{a as Mp4Demuxer};
|
package/dist/fragmented.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{r}from"./chunk-tghqqx5m.js";import"./chunk-qmjyh9jc.js";export{r as FragmentedMp4Muxer};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{f,w,h,B,U,y,E,x,C,F,v,S}from"./chunk-m7vh938z.js";import{a}from"./chunk-yjtc1ksx.js";import{i}from"./chunk-c9md36vm.js";import{r}from"./chunk-tghqqx5m.js";import{t,c,u,b,d,m,p,n,o,g,l,s,e}from"./chunk-qmjyh9jc.js";export{t as BOX_HEADER_SIZE,S as CMAF_OUTPUT,d as CONTAINER_BOXES,y as CmafOutputFormat,c as EXTENDED_BOX_HEADER_SIZE,v as FMP4_OUTPUT,r as FragmentedMp4Muxer,U as FragmentedMp4OutputFormat,x as MOV,p as MOV_BRANDS,F as MOV_OUTPUT,E as MP4,m as MP4_BRANDS,C as MP4_OUTPUT,w as MovInputFormat,B as MovOutputFormat,a as Mp4Demuxer,f as Mp4InputFormat,i as Mp4Muxer,h as Mp4OutputFormat,e as TIMESCALE_1904_TO_1970,s as encodeLanguageCode,o as isAudioHandler,g as isSubtitleHandler,n as isVideoHandler,l as parseLanguageCode,u as readFourCC,b as writeFourCC};
|
package/dist/muxer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{i}from"./chunk-c9md36vm.js";import"./chunk-qmjyh9jc.js";export{i as Mp4Muxer};
|
package/dist/prores.test.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
package/dist/prores.test.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import"./chunk-qmjyh9jc.js";import"./chunk-yjtc1ksx.js";import{i}from"./chunk-c9md36vm.js";import"./chunk-tghqqx5m.js";import{w}from"./chunk-m7vh938z.js";import{describe as o,expect as n,test as c}from"bun:test";import{BufferTarget as m,Input as s}from"ts-videos";o("ProRes sample entries",()=>{c("round-trips the 4444 XQ profile through MOV metadata",async()=>{let r=new m,t=new i(r,{brand:"qt "}),a=t.addVideoTrack({codec:"prores",profile:"4444-xq",width:1920,height:1080,frameRate:24});await t.writePacket(a.id,{data:new Uint8Array([0,0,0,8,105,99,112,102]),timestamp:0,duration:0.041666666666666664,isKeyframe:!0}),await t.finalize();let e=new s(r.buffer);e.setFormats([new w]),n(await e.getPrimaryVideoTrack()).toMatchObject({codec:"prores",profile:"4444-xq"}),await e.close()})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-videos/mp4",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"description": "MP4/MOV (ISOBMFF) codec support for ts-videos",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -57,6 +57,6 @@
|
|
|
57
57
|
"typecheck": "bunx tsc --noEmit"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"ts-videos": "0.1.
|
|
60
|
+
"ts-videos": "0.1.2"
|
|
61
61
|
}
|
|
62
62
|
}
|
package/dist/chunk-51x739sq.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{p as c,q as A,r as O,t as _,w as g,x as S,z as N}from"./chunk-63shg4s1.js";import{Demuxer as L}from"ts-videos/demuxer";class $ extends L{movieTimescale=1000;movieDuration=0n;trackInfos=[];moovBox=null;mdatOffset=0;fragmented=!1;_initialized=!1;majorBrand="";get formatName(){return this.majorBrand==="qt "?"mov":"mp4"}get mimeType(){let r=this._tracks?.find((i)=>i.type==="video"),e=this._tracks?.find((i)=>i.type==="audio"),t="";if(r&&e)t=`${this.getCodecString(r)}, ${this.getCodecString(e)}`;else if(r)t=this.getCodecString(r);else if(e)t=this.getCodecString(e);let a=this.majorBrand==="qt "?"video/quicktime":"video/mp4";return t?`${a}; codecs="${t}"`:a}getCodecString(r){if(r.type==="video"){let e=r;if(e.codec==="h264"&&e.codecDescription){let t=e.codecDescription;if(t.length>=4){let a=t[1].toString(16).padStart(2,"0"),i=t[2].toString(16).padStart(2,"0"),s=t[3].toString(16).padStart(2,"0");return`avc1.${a}${i}${s}`}return"avc1"}if(e.codec==="h265")return"hev1";if(e.codec==="vp9")return"vp09";if(e.codec==="av1")return"av01";return e.codec}if(r.type==="audio"){let e=r;if(e.codec==="aac")return"mp4a.40.2";if(e.codec==="mp3")return"mp4a.40.34";if(e.codec==="opus")return"opus";if(e.codec==="flac")return"flac";return e.codec}return"unknown"}async init(){if(this._initialized)return;this._initialized=!0,await this.parseTopLevelBoxes(),await this.buildTracks(),await this.buildSampleTables()}async parseTopLevelBoxes(){let r=await this.reader.getSize(),e=0;while(r===null||e<r){this.reader.position=e;let t=await this.reader.readU32BE();if(t===null)break;let a=await this.reader.readFourCC();if(!a)break;let i=t;if(i===1){let s=await this.reader.readU64BE();if(s===null)break;i=Number(s)}else if(i===0)i=(r??0)-e;if(a==="ftyp")await this.parseFtyp(e,i);else if(a==="moov")this.moovBox={type:a,size:i,offset:e},await this.parseMoov(e,i);else if(a==="mdat")this.mdatOffset=e+c;else if(a==="moof")this.fragmented=!0;e+=i}}async parseFtyp(r,e){this.reader.position=r+c,this.majorBrand=await this.reader.readFourCC()??"",await this.reader.readU32BE();let t=(e-16)/4;for(let a=0;a<t;a++)await this.reader.readFourCC()}async parseMoov(r,e){await this.parseContainerBox(r+c,e-c)}async parseContainerBox(r,e){let t=[],a=r,i=r+e;while(a<i){this.reader.position=a;let s=await this.reader.readU32BE();if(s===null)break;let o=await this.reader.readFourCC();if(!o)break;let p=s,u=c;if(p===1){let h=await this.reader.readU64BE();if(h===null)break;p=Number(h),u=A}else if(p===0)p=i-a;let f={type:o,size:p,offset:a};if(_.has(o))f.children=await this.parseContainerBox(a+u,p-u);t.push(f),a+=p}return t}async buildTracks(){if(!this.moovBox)throw Error("No moov box found");let r=await this.parseContainerBox(this.moovBox.offset+c,this.moovBox.size-c),e=r.find((a)=>a.type==="mvhd");if(e)await this.parseMvhd(e);let t=r.filter((a)=>a.type==="trak");this._tracks=[];for(let a=0;a<t.length;a++){let i=await this.parseTrack(t[a],a);if(i)this._tracks.push(i)}this._metadata=await this.parseMetadata(r),this._duration=Number(this.movieDuration)/this.movieTimescale}async parseMvhd(r){this.reader.position=r.offset+c;let e=await this.reader.readU8();if(e===null)return;if(await this.reader.skip(3),e===1)await this.reader.skip(16),this.movieTimescale=await this.reader.readU32BE()??1000,this.movieDuration=await this.reader.readU64BE()??0n;else await this.reader.skip(8),this.movieTimescale=await this.reader.readU32BE()??1000,this.movieDuration=BigInt(await this.reader.readU32BE()??0)}async parseTrack(r,e){let t=r.children??[],a=t.find((n)=>n.type==="tkhd"),i=t.find((n)=>n.type==="mdia");if(!a||!i)return null;let s=await this.parseTkhd(a),o=i.children??[],p=o.find((n)=>n.type==="mdhd"),u=o.find((n)=>n.type==="hdlr"),f=o.find((n)=>n.type==="minf");if(!p||!u||!f)return null;let h=await this.parseMdhd(p),m=await this.parseHdlr(u),y=(f.children??[]).find((n)=>n.type==="stbl");if(!y)return null;let l=(y.children??[]).find((n)=>n.type==="stsd");if(!l)return null;let B=await this.parseStsd(l,m.handlerType),b={id:s.trackId,index:e,type:g(m.handlerType)?"video":S(m.handlerType)?"audio":"subtitle",timescale:h.timescale,duration:h.duration,samples:[],currentSampleIndex:0};if(this.trackInfos.push(b),g(m.handlerType)&&B.entries.length>0){let n=B.entries[0];return{type:"video",id:s.trackId,index:e,codec:this.getVideoCodec(n.type),width:n.width,height:n.height,profile:this.getVideoProfile(n.type),frameRate:this.calculateFrameRate(b),isDefault:(s.flags&1)!==0,language:h.language,codecDescription:this.extractCodecDescription(n),colorSpace:this.extractColorSpace(n),rotation:this.getRotation(s.matrix)}}if(S(m.handlerType)&&B.entries.length>0){let n=B.entries[0];return{type:"audio",id:s.trackId,index:e,codec:this.getAudioCodec(n.type),sampleRate:n.sampleRate,channels:n.channelCount,bitsPerSample:n.sampleSize,isDefault:(s.flags&1)!==0,language:h.language,codecDescription:this.extractCodecDescription(n)}}return null}async parseTkhd(r){this.reader.position=r.offset+c;let e=await this.reader.readU8(),t=(await this.reader.readU8()??0)<<16|(await this.reader.readU8()??0)<<8|(await this.reader.readU8()??0),a=0;if(e===1)await this.reader.skip(16),a=await this.reader.readU32BE()??0,await this.reader.skip(12);else await this.reader.skip(8),a=await this.reader.readU32BE()??0,await this.reader.skip(8);await this.reader.skip(8);let i=[];for(let p=0;p<9;p++)i.push(await this.reader.readI32BE()??0);let s=(await this.reader.readU32BE()??0)/65536,o=(await this.reader.readU32BE()??0)/65536;return{trackId:a,flags:t,width:s,height:o,matrix:i}}async parseMdhd(r){this.reader.position=r.offset+c;let e=await this.reader.readU8();await this.reader.skip(3);let t=1000,a=0n;if(e===1)await this.reader.skip(16),t=await this.reader.readU32BE()??1000,a=await this.reader.readU64BE()??0n;else await this.reader.skip(8),t=await this.reader.readU32BE()??1000,a=BigInt(await this.reader.readU32BE()??0);let i=await this.reader.readU16BE()??0,s=N(i);return{timescale:t,duration:a,language:s}}async parseHdlr(r){this.reader.position=r.offset+c,await this.reader.skip(8);let e=await this.reader.readFourCC()??"";await this.reader.skip(12);let t=r.size-c-24,a=t>0?await this.reader.readString(t)??"":"";return{handlerType:e,name:a.replace(/\0/g,"")}}async parseStsd(r,e){this.reader.position=r.offset+c,await this.reader.skip(4);let t=await this.reader.readU32BE()??0,a=[];for(let i=0;i<t;i++){let s=await this.reader.readU32BE()??0,o=await this.reader.readFourCC()??"",p=this.reader.position;await this.reader.skip(6);let u=await this.reader.readU16BE()??0;if(g(e)){await this.reader.skip(16);let f=await this.reader.readU16BE()??0,h=await this.reader.readU16BE()??0,m=await this.reader.readU32BE()??0,x=await this.reader.readU32BE()??0;await this.reader.skip(4);let y=await this.reader.readU16BE()??1,w=await this.reader.readU8()??0,l=await this.reader.readString(31)??"",B=await this.reader.readU16BE()??24;await this.reader.skip(2);let b=await this.parseExtensions(p+s-8);a.push({type:o,dataReferenceIndex:u,width:f,height:h,horizResolution:m,vertResolution:x,frameCount:y,compressorName:l.slice(0,w),depth:B,extensions:b,data:new Uint8Array(0)})}else if(S(e)){await this.reader.skip(8);let f=await this.reader.readU16BE()??2,h=await this.reader.readU16BE()??16;await this.reader.skip(4);let m=(await this.reader.readU32BE()??-1404829696)>>16,x=await this.parseExtensions(p+s-8);a.push({type:o,dataReferenceIndex:u,channelCount:f,sampleSize:h,sampleRate:m,extensions:x,data:new Uint8Array(0)})}this.reader.position=p+s-8}return{entries:a}}async parseExtensions(r){let e=[];while(this.reader.position<r){let t=await this.reader.readU32BE()??0;if(t<8)break;let a=await this.reader.readFourCC()??"",i=await this.reader.readBytes(t-8);e.push({type:a,size:t,offset:this.reader.position-t,data:i??void 0})}return e}getVideoCodec(r){switch(r){case"avc1":case"avc3":return"h264";case"hev1":case"hvc1":return"h265";case"vp08":return"vp8";case"vp09":return"vp9";case"av01":return"av1";case"mp4v":return"mpeg4";case"apco":case"apcs":case"apcn":case"apch":case"ap4h":case"ap4x":return"prores";default:return"unknown"}}getVideoProfile(r){switch(r){case"apco":return"proxy";case"apcs":return"lt";case"apcn":return"422";case"apch":return"hq";case"ap4h":return"4444";case"ap4x":return"4444-xq";default:return}}extractColorSpace(r){let e=r.extensions.find((o)=>o.type==="colr")?.data;if(!e||e.length<11)return;let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(O(t,0)!=="nclx")return;let a=new Map([[1,"bt709"],[4,"bt470m"],[5,"bt470bg"],[6,"smpte170m"],[7,"smpte240m"],[8,"film"],[9,"bt2020"],[10,"smpte428"],[11,"smpte431"],[12,"smpte432"],[22,"ebu3213"]]).get(t.getUint16(4)),i=new Map([[1,"bt709"],[4,"bt470m"],[5,"bt470bg"],[6,"smpte170m"],[7,"smpte240m"],[8,"linear"],[9,"log100"],[10,"log316"],[11,"iec61966-2-4"],[12,"bt1361e"],[13,"iec61966-2-1"],[14,"bt2020-10"],[15,"bt2020-12"],[16,"smpte2084"],[17,"smpte428"],[18,"arib-std-b67"]]).get(t.getUint16(6)),s=new Map([[0,"rgb"],[1,"bt709"],[4,"fcc"],[5,"bt470bg"],[6,"smpte170m"],[7,"smpte240m"],[8,"ycocg"],[9,"bt2020nc"],[10,"bt2020c"],[11,"smpte2085"],[12,"chroma-derived-nc"],[13,"chroma-derived-c"],[14,"ictcp"]]).get(t.getUint16(8));if(!a&&!i&&!s)return;return{primaries:a,transfer:i,matrix:s,range:(e[10]&128)!==0?"full":"limited"}}getAudioCodec(r){switch(r){case"mp4a":return"aac";case".mp3":case"mp3 ":return"mp3";case"Opus":return"opus";case"fLaC":return"flac";case"alac":return"alac";case"ac-3":return"ac3";case"ec-3":return"eac3";default:return"unknown"}}extractCodecDescription(r){for(let e of r.extensions)if(e.type==="avcC"||e.type==="hvcC"||e.type==="av1C"||e.type==="esds")return e.data;return}getRotation(r){let e=r[0]/65536,t=r[1]/65536,a=r[3]/65536,i=r[4]/65536;if(Math.abs(e-1)<0.01&&Math.abs(i-1)<0.01)return 0;if(Math.abs(t-1)<0.01&&Math.abs(a+1)<0.01)return 90;if(Math.abs(e+1)<0.01&&Math.abs(i+1)<0.01)return 180;if(Math.abs(t+1)<0.01&&Math.abs(a-1)<0.01)return 270;return 0}calculateFrameRate(r){return}async parseMetadata(r){return{}}async buildSampleTables(){if(!this.moovBox)return;let e=(await this.parseContainerBox(this.moovBox.offset+c,this.moovBox.size-c)).filter((t)=>t.type==="trak");for(let t=0;t<e.length&&t<this.trackInfos.length;t++)await this.buildSampleTable(e[t],this.trackInfos[t])}async buildSampleTable(r,e){let a=(r.children??[]).find((d)=>d.type==="mdia");if(!a?.children)return;let i=a.children.find((d)=>d.type==="minf");if(!i?.children)return;let s=i.children.find((d)=>d.type==="stbl");if(!s?.children)return;let o=s.children,p=o.find((d)=>d.type==="stts"),u=o.find((d)=>d.type==="ctts"),f=o.find((d)=>d.type==="stsc"),h=o.find((d)=>d.type==="stsz"),m=o.find((d)=>d.type==="stco"),x=o.find((d)=>d.type==="co64"),y=o.find((d)=>d.type==="stss");if(!p||!f||!h||!m&&!x)return;let w=await this.parseStts(p),l=u?await this.parseCtts(u):null,B=await this.parseStsc(f),b=await this.parseStsz(h),n=m?await this.parseStco(m):await this.parseCo64(x),k=y?new Set(await this.parseStss(y)):null,E=0,I=0,C=0,U=w.length>0?w[0].sampleCount:0,v=0,T=l&&l.length>0?l[0].sampleCount:0;for(let d=0;d<n.length;d++){let V=n[d],R=this.getSamplesPerChunk(B,d+1),P=0;for(let z=0;z<R;z++){let M=b.sampleSize>0?b.sampleSize:b.entrySizes[E]??0,D=w[C]?.sampleDelta??0,F=l&&l[v]?l[v].sampleOffset:0,H=k===null||k.has(E+1);if(e.samples.push({offset:V+P,size:M,timestamp:I/e.timescale,duration:D/e.timescale,isKeyframe:H,compositionTimeOffset:F/e.timescale}),P+=M,I+=D,E++,U--,U===0&&C<w.length-1)C++,U=w[C].sampleCount;if(l){if(T--,T===0&&v<l.length-1)v++,T=l[v].sampleCount}}}}async parseStts(r){this.reader.position=r.offset+c,await this.reader.skip(4);let e=await this.reader.readU32BE()??0,t=[];for(let a=0;a<e;a++){let i=await this.reader.readU32BE()??0,s=await this.reader.readU32BE()??0;t.push({sampleCount:i,sampleDelta:s})}return t}async parseCtts(r){this.reader.position=r.offset+c;let e=await this.reader.readU8()??0;await this.reader.skip(3);let t=await this.reader.readU32BE()??0,a=[];for(let i=0;i<t;i++){let s=await this.reader.readU32BE()??0,o=e===1?await this.reader.readI32BE()??0:await this.reader.readU32BE()??0;a.push({sampleCount:s,sampleOffset:o})}return a}async parseStsc(r){this.reader.position=r.offset+c,await this.reader.skip(4);let e=await this.reader.readU32BE()??0,t=[];for(let a=0;a<e;a++){let i=await this.reader.readU32BE()??0,s=await this.reader.readU32BE()??0,o=await this.reader.readU32BE()??0;t.push({firstChunk:i,samplesPerChunk:s,sampleDescriptionIndex:o})}return t}async parseStsz(r){this.reader.position=r.offset+c,await this.reader.skip(4);let e=await this.reader.readU32BE()??0,t=await this.reader.readU32BE()??0,a=[];if(e===0)for(let i=0;i<t;i++)a.push(await this.reader.readU32BE()??0);return{sampleSize:e,sampleCount:t,entrySizes:a}}async parseStco(r){this.reader.position=r.offset+c,await this.reader.skip(4);let e=await this.reader.readU32BE()??0,t=[];for(let a=0;a<e;a++)t.push(await this.reader.readU32BE()??0);return t}async parseCo64(r){this.reader.position=r.offset+c,await this.reader.skip(4);let e=await this.reader.readU32BE()??0,t=[];for(let a=0;a<e;a++)t.push(Number(await this.reader.readU64BE()??0n));return t}async parseStss(r){this.reader.position=r.offset+c,await this.reader.skip(4);let e=await this.reader.readU32BE()??0,t=[];for(let a=0;a<e;a++)t.push(await this.reader.readU32BE()??0);return t}getSamplesPerChunk(r,e){for(let t=r.length-1;t>=0;t--)if(e>=r[t].firstChunk)return r[t].samplesPerChunk;return 1}async readPacket(r){let e=this.trackInfos.find((i)=>i.id===r);if(!e||e.currentSampleIndex>=e.samples.length)return null;let t=e.samples[e.currentSampleIndex];e.currentSampleIndex++,this.reader.position=t.offset;let a=await this.reader.readBytes(t.size);if(!a)return null;return{data:a,timestamp:t.timestamp,duration:t.duration,isKeyframe:t.isKeyframe,trackId:r,compositionTimeOffset:t.compositionTimeOffset}}async seek(r){for(let e of this.trackInfos){let t=0;for(let a=0;a<e.samples.length;a++){if(e.samples[a].timestamp>r)break;if(e.samples[a].isKeyframe)t=a}e.currentSampleIndex=t}}}
|
|
2
|
-
export{$ as n};
|
package/dist/chunk-63shg4s1.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var i=8,o=16;function a(e,t){return String.fromCharCode(e.getUint8(t),e.getUint8(t+1),e.getUint8(t+2),e.getUint8(t+3))}function s(e,t,r){for(let n=0;n<4;n++)e.setUint8(t+n,r.charCodeAt(n))}var m=new Set(["moov","trak","mdia","minf","stbl","dinf","edts","udta","meta","ilst","moof","traf","mvex","sinf","schi","rinf"]),u=new Set(["isom","iso2","iso3","iso4","iso5","iso6","mp41","mp42","mp71","avc1","av01","hev1","hvc1","M4A ","M4V ","M4P ","M4B ","f4v ","f4a ","dash","msdh","msix"]),x=new Set(["qt "]);function b(e){return e==="vide"}function p(e){return e==="soun"}function d(e){return e==="subt"||e==="text"||e==="sbtl"}function c(e){let t=(e>>10&31)+96,r=(e>>5&31)+96,n=(e&31)+96;return String.fromCharCode(t,r,n)}function f(e){if(e.length!==3)return 21956;let t=e.charCodeAt(0)-96&31,r=e.charCodeAt(1)-96&31,n=e.charCodeAt(2)-96&31;return t<<10|r<<5|n}var l=2082844800n;
|
|
2
|
-
export{i as p,o as q,a as r,s,m as t,u,x as v,b as w,p as x,d as y,c as z,f as A,l as B};
|
package/dist/chunk-vetfxydj.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{A as Q,B as G}from"./chunk-63shg4s1.js";import{Muxer as A}from"ts-videos/muxer";import{Writer as X}from"ts-videos/writer";var M=1000;class I extends A{trackData=new Map;options;sequenceNumber=1;fragmentStartTime=0;initialized=!1;constructor(q,j={}){super(q);if(this.options={fragmentDuration:j.fragmentDuration??2,brand:j.brand??"iso5",cmaf:j.cmaf??!1,lowLatency:j.lowLatency??!1},this.options.lowLatency)this.options.fragmentDuration=Math.min(0.5,this.options.fragmentDuration)}get formatName(){return"fmp4"}get mimeType(){return"video/mp4"}onTrackAdded(q){let j=q.type==="video"?Math.round((q.config.frameRate??30)*1000):q.type==="audio"?q.config.sampleRate:1000;this.trackData.set(q.id,{track:q,timescale:j,samples:[],baseMediaDecodeTime:0n,defaultSampleDuration:0,defaultSampleSize:0,defaultSampleFlags:q.type==="video"?65536:0})}async writeHeader(){await this.writeFtyp(),await this.writeMoov(),this.initialized=!0}async writeFtyp(){let q=this.options.cmaf?["cmfc","iso6","mp41"]:[this.options.brand,"iso5","iso6","mp41","avc1"],j=16+q.length*4;await this.writer.writeU32BE(j),await this.writer.writeFourCC("ftyp"),await this.writer.writeFourCC(this.options.cmaf?"cmfc":this.options.brand),await this.writer.writeU32BE(512);for(let H of q)await this.writer.writeFourCC(H)}async writeMoov(){let q=new X,j=await this.buildMvhd(),H=await this.buildMvex(),J=[];for(let R of this.trackData.values()){let Y=await this.buildTrak(R);J.push(Y)}let U=j.byteLength+H.byteLength+J.reduce((R,Y)=>R+Y.byteLength,0)+8;await q.writeU32BE(U),await q.writeFourCC("moov"),await q.writeBytes(j);for(let R of J)await q.writeBytes(R);await q.writeBytes(H),await this.writer.writeBytes(q.getBuffer())}async buildMvhd(){let q=new X,j=BigInt(Math.floor(Date.now()/1000))+G,H=116;await q.writeU32BE(116),await q.writeFourCC("mvhd"),await q.writeU8(0),await q.writeU8(0),await q.writeU8(0),await q.writeU8(0),await q.writeU32BE(Number(j&0xFFFFFFFFn)),await q.writeU32BE(Number(j&0xFFFFFFFFn)),await q.writeU32BE(M),await q.writeU32BE(0),await q.writeU32BE(65536),await q.writeU16BE(256),await q.writeU16BE(0),await q.writeU32BE(0),await q.writeU32BE(0),await q.writeU32BE(65536),await q.writeU32BE(0),await q.writeU32BE(0),await q.writeU32BE(0),await q.writeU32BE(65536),await q.writeU32BE(0),await q.writeU32BE(0),await q.writeU32BE(0),await q.writeU32BE(1073741824);for(let J=0;J<6;J++)await q.writeU32BE(0);return await q.writeU32BE(this.tracks.length+1),q.getBuffer()}async buildMvex(){let q=new X,j=[];for(let J of this.trackData.values())j.push(await this.buildTrex(J));let H=8+j.reduce((J,P)=>J+P.byteLength,0);await q.writeU32BE(H),await q.writeFourCC("mvex");for(let J of j)await q.writeBytes(J);return q.getBuffer()}async buildTrex(q){let j=new X,H=32;return await j.writeU32BE(32),await j.writeFourCC("trex"),await j.writeU32BE(0),await j.writeU32BE(q.track.id),await j.writeU32BE(1),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU32BE(q.defaultSampleFlags),j.getBuffer()}async buildTrak(q){let j=new X,H=await this.buildTkhd(q),J=await this.buildMdia(q),P=8+H.byteLength+J.byteLength;return await j.writeU32BE(P),await j.writeFourCC("trak"),await j.writeBytes(H),await j.writeBytes(J),j.getBuffer()}async buildTkhd(q){let j=new X,H=BigInt(Math.floor(Date.now()/1000))+G,J=92,P=q.track,U=0,R=0,Y=0;if(P.type==="video")U=P.config.width,R=P.config.height;else if(P.type==="audio")Y=256;return await j.writeU32BE(92),await j.writeFourCC("tkhd"),await j.writeU8(0),await j.writeU8(0),await j.writeU8(0),await j.writeU8(3),await j.writeU32BE(Number(H&0xFFFFFFFFn)),await j.writeU32BE(Number(H&0xFFFFFFFFn)),await j.writeU32BE(P.id),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU16BE(0),await j.writeU16BE(0),await j.writeU16BE(Y),await j.writeU16BE(0),await j.writeU32BE(65536),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU32BE(65536),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU32BE(1073741824),await j.writeU32BE(U<<16),await j.writeU32BE(R<<16),j.getBuffer()}async buildMdia(q){let j=new X,H=await this.buildMdhd(q),J=await this.buildHdlr(q),P=await this.buildMinf(q),U=8+H.byteLength+J.byteLength+P.byteLength;return await j.writeU32BE(U),await j.writeFourCC("mdia"),await j.writeBytes(H),await j.writeBytes(J),await j.writeBytes(P),j.getBuffer()}async buildMdhd(q){let j=new X,H=BigInt(Math.floor(Date.now()/1000))+G,J=40;return await j.writeU32BE(40),await j.writeFourCC("mdhd"),await j.writeU8(0),await j.writeU8(0),await j.writeU8(0),await j.writeU8(0),await j.writeU32BE(Number(H&0xFFFFFFFFn)),await j.writeU32BE(Number(H&0xFFFFFFFFn)),await j.writeU32BE(q.timescale),await j.writeU32BE(0),await j.writeU16BE(Q("und")),await j.writeU16BE(0),j.getBuffer()}async buildHdlr(q){let j=new X,H="",J="";if(q.track.type==="video")H="vide",J="VideoHandler";else if(q.track.type==="audio")H="soun",J="SoundHandler";else H="text",J="SubtitleHandler";let P=new TextEncoder().encode(`${J}\x00`),U=32+P.byteLength+8;return await j.writeU32BE(U),await j.writeFourCC("hdlr"),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeFourCC(H),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeBytes(P),j.getBuffer()}async buildMinf(q){let j=new X,H;if(q.track.type==="video")H=await this.buildVmhd();else if(q.track.type==="audio")H=await this.buildSmhd();else H=await this.buildNmhd();let J=await this.buildDinf(),P=await this.buildStbl(q),U=8+H.byteLength+J.byteLength+P.byteLength;return await j.writeU32BE(U),await j.writeFourCC("minf"),await j.writeBytes(H),await j.writeBytes(J),await j.writeBytes(P),j.getBuffer()}async buildVmhd(){let q=new X,j=20;return await q.writeU32BE(20),await q.writeFourCC("vmhd"),await q.writeU32BE(1),await q.writeU16BE(0),await q.writeU16BE(0),await q.writeU16BE(0),await q.writeU16BE(0),q.getBuffer()}async buildSmhd(){let q=new X,j=16;return await q.writeU32BE(16),await q.writeFourCC("smhd"),await q.writeU32BE(0),await q.writeU16BE(0),await q.writeU16BE(0),q.getBuffer()}async buildNmhd(){let q=new X,j=12;return await q.writeU32BE(12),await q.writeFourCC("nmhd"),await q.writeU32BE(0),q.getBuffer()}async buildDinf(){let q=new X,j=await this.buildDref(),H=8+j.byteLength;return await q.writeU32BE(H),await q.writeFourCC("dinf"),await q.writeBytes(j),q.getBuffer()}async buildDref(){let q=new X,j=28;return await q.writeU32BE(28),await q.writeFourCC("dref"),await q.writeU32BE(0),await q.writeU32BE(1),await q.writeU32BE(12),await q.writeFourCC("url "),await q.writeU32BE(1),q.getBuffer()}async buildStbl(q){let j=new X,H=await this.buildStsd(q),J=await this.buildEmptyAtom("stts"),P=await this.buildEmptyAtom("stsc"),U=await this.buildEmptyStsz(),R=await this.buildEmptyAtom("stco"),Y=8+H.byteLength+J.byteLength+P.byteLength+U.byteLength+R.byteLength;return await j.writeU32BE(Y),await j.writeFourCC("stbl"),await j.writeBytes(H),await j.writeBytes(J),await j.writeBytes(P),await j.writeBytes(U),await j.writeBytes(R),j.getBuffer()}async buildEmptyAtom(q){let j=new X;return await j.writeU32BE(16),await j.writeFourCC(q),await j.writeU32BE(0),await j.writeU32BE(0),j.getBuffer()}async buildEmptyStsz(){let q=new X;return await q.writeU32BE(20),await q.writeFourCC("stsz"),await q.writeU32BE(0),await q.writeU32BE(0),await q.writeU32BE(0),q.getBuffer()}async buildStsd(q){let j=new X,H;if(q.track.type==="video")H=await this.buildVideoSampleEntry(q.track);else if(q.track.type==="audio")H=await this.buildAudioSampleEntry(q.track);else H=new Uint8Array(0);let J=16+H.byteLength;return await j.writeU32BE(J),await j.writeFourCC("stsd"),await j.writeU32BE(0),await j.writeU32BE(1),await j.writeBytes(H),j.getBuffer()}async buildVideoSampleEntry(q){let j=new X,H=q.config,J="";if(H.codec==="h264")J="avc1";else if(H.codec==="h265")J="hev1";else if(H.codec==="vp9")J="vp09";else if(H.codec==="av1")J="av01";else J="mp4v";let P=H.codecDescription??new Uint8Array(0),U=H.codec==="h264"?"avcC":H.codec==="h265"?"hvcC":"avcC",R=P.byteLength>0?8+P.byteLength:0,Y=86+R;await j.writeU32BE(Y),await j.writeFourCC(J),await j.writeU32BE(0),await j.writeU16BE(0),await j.writeU16BE(1),await j.writeU16BE(0),await j.writeU16BE(0),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU16BE(H.width),await j.writeU16BE(H.height),await j.writeU32BE(4718592),await j.writeU32BE(4718592),await j.writeU32BE(0),await j.writeU16BE(1);let $=new Uint8Array(32);if(await j.writeBytes($),await j.writeU16BE(24),await j.writeI16BE(-1),R>0)await j.writeU32BE(R),await j.writeFourCC(U),await j.writeBytes(P);return j.getBuffer()}async buildAudioSampleEntry(q){let j=new X,H=q.config,J="mp4a";if(H.codec==="opus")J="Opus";else if(H.codec==="flac")J="fLaC";let P=H.codecDescription??new Uint8Array(0),U=P.byteLength>0?8+P.byteLength:0,R=36+U;if(await j.writeU32BE(R),await j.writeFourCC(J),await j.writeU32BE(0),await j.writeU16BE(0),await j.writeU16BE(1),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU16BE(H.channels),await j.writeU16BE(H.bitsPerSample??16),await j.writeU16BE(0),await j.writeU16BE(0),await j.writeU32BE(H.sampleRate<<16),U>0)await j.writeU32BE(U),await j.writeFourCC("esds"),await j.writeBytes(P);return j.getBuffer()}async writeVideoPacket(q,j){await this.writeSample(q.id,j)}async writeAudioPacket(q,j){await this.writeSample(q.id,j)}async writeSubtitlePacket(q,j){await this.writeSample(q.id,j)}async writeSample(q,j){let H=this.trackData.get(q);if(!H)return;let J=[...this.trackData.values()].some(($)=>$.track.type==="video"),P=[...this.trackData.values()].some(($)=>$.samples.length>0),U=j.timestamp-this.fragmentStartTime>=this.options.fragmentDuration,R=H.track.type==="video"&&j.isKeyframe;if(P&&U&&(R||!J))await this.flushFragment();let Y={data:j.data,timestamp:j.timestamp,duration:j.duration??0,isKeyframe:j.isKeyframe,compositionTimeOffset:j.compositionTimeOffset??0,size:j.data.byteLength};H.samples.push(Y)}async flushFragment(){let q=!1;for(let P of this.trackData.values())if(P.samples.length>0){q=!0;break}if(!q)return;let j=await this.buildMoof(),H=await this.buildFragmentMdat();await this.writer.writeBytes(j),await this.writer.writeBytes(H),this.sequenceNumber++;let J=this.fragmentStartTime;for(let P of this.trackData.values()){if(P.samples.length>0){P.baseMediaDecodeTime+=P.samples.reduce((U,R)=>U+BigInt(Math.round(R.duration*P.timescale)),0n);for(let U of P.samples)J=Math.max(J,U.timestamp+U.duration)}P.samples=[]}this.fragmentStartTime=J}async buildMoof(){let q=new X,j=await this.buildMfhd(),H=[],J=8;for(let R of this.trackData.values())if(R.samples.length>0){H.push(await this.buildTraf(R,J));for(let Y of R.samples)J+=Y.size}let P=8+j.byteLength;for(let R of H)P+=R.byteLength;let U=[];J=P+8;for(let R of this.trackData.values())if(R.samples.length>0){U.push(await this.buildTraf(R,J));for(let Y of R.samples)J+=Y.size}P=8+j.byteLength;for(let R of U)P+=R.byteLength;await q.writeU32BE(P),await q.writeFourCC("moof"),await q.writeBytes(j);for(let R of U)await q.writeBytes(R);return q.getBuffer()}async buildMfhd(){let q=new X,j=16;return await q.writeU32BE(16),await q.writeFourCC("mfhd"),await q.writeU32BE(0),await q.writeU32BE(this.sequenceNumber),q.getBuffer()}async buildTraf(q,j){let H=new X,J=await this.buildTfhd(q),P=await this.buildTfdt(q),U=await this.buildTrun(q,j),R=8+J.byteLength+P.byteLength+U.byteLength;return await H.writeU32BE(R),await H.writeFourCC("traf"),await H.writeBytes(J),await H.writeBytes(P),await H.writeBytes(U),H.getBuffer()}async buildTfhd(q){let j=new X,H=0;if(q.samples.length>0){let U=Math.round(q.samples[0].duration*q.timescale);if(q.samples.every((Y)=>Math.round(Y.duration*q.timescale)===U))H=U}let J=131072|(H>0?8:0),P=16+(H>0?4:0);if(await j.writeU32BE(P),await j.writeFourCC("tfhd"),await j.writeU8(0),await j.writeU8(J>>16&255),await j.writeU8(J>>8&255),await j.writeU8(J&255),await j.writeU32BE(q.track.id),H>0)await j.writeU32BE(H);return j.getBuffer()}async buildTfdt(q){let j=new X,H=20;return await j.writeU32BE(20),await j.writeFourCC("tfdt"),await j.writeU8(1),await j.writeU8(0),await j.writeU8(0),await j.writeU8(0),await j.writeU64BE(q.baseMediaDecodeTime),j.getBuffer()}async buildTrun(q,j){let H=new X,J=!q.samples.every((Z,N,K)=>N===0||Math.round(Z.duration*q.timescale)===Math.round(K[0].duration*q.timescale)),P=!q.samples.every((Z)=>Z.size===q.samples[0].size),U=q.samples.some((Z)=>Z.isKeyframe!==q.samples[0].isKeyframe),R=q.samples.some((Z)=>Z.compositionTimeOffset!==0),Y=1|(J?256:0)|(P?512:0)|(U?1024:0)|(R?2048:0),$=0;if(J)$+=4;if(P)$+=4;if(U)$+=4;if(R)$+=4;let F=20+q.samples.length*$;await H.writeU32BE(F),await H.writeFourCC("trun"),await H.writeU8(0),await H.writeU8(Y>>16&255),await H.writeU8(Y>>8&255),await H.writeU8(Y&255),await H.writeU32BE(q.samples.length),await H.writeU32BE(j);for(let Z of q.samples){if(J)await H.writeU32BE(Math.round(Z.duration*q.timescale));if(P)await H.writeU32BE(Z.size);if(U){let N=Z.isKeyframe?0:65536;await H.writeU32BE(N)}if(R)await H.writeI32BE(Math.round(Z.compositionTimeOffset*q.timescale))}return H.getBuffer()}async buildFragmentMdat(){let q=new X,j=0;for(let H of this.trackData.values())for(let J of H.samples)j+=J.size;await q.writeU32BE(j+8),await q.writeFourCC("mdat");for(let H of this.trackData.values())for(let J of H.samples)await q.writeBytes(J.data);return q.getBuffer()}async writeTrailer(){await this.flushFragment(),await this.writeMfra()}async writeMfra(){let q=new X,j=[],H=16,J=24;await q.writeU32BE(24),await q.writeFourCC("mfra"),await q.writeU32BE(16),await q.writeFourCC("mfro"),await q.writeU32BE(0),await q.writeU32BE(24),await this.writer.writeBytes(q.getBuffer())}}
|
|
2
|
-
export{I as o};
|
package/dist/chunk-wmd2bsvz.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{A as m,B as y}from"./chunk-63shg4s1.js";import{Muxer as i}from"ts-videos/muxer";import{Writer as V}from"ts-videos/writer";var T=1000;class e extends i{trackData=new Map;options;mdatStart=0;mdatSize=0;chapters=[];artwork=null;artworkType="jpeg";constructor(q,j={}){super(q);this.options={fastStart:j.fastStart??!0,fragmented:j.fragmented??!1,brand:j.brand??"isom"}}addChapter(q,j){this.chapters.push({title:q,startTimeMs:j})}setArtwork(q,j="jpeg"){this.artwork=q,this.artworkType=j}get formatName(){return"mp4"}get mimeType(){return"video/mp4"}onTrackAdded(q){let j=q.type==="video"?Math.round((q.config.frameRate??30)*1000):q.type==="audio"?q.config.sampleRate:1000;this.trackData.set(q.id,{track:q,timescale:j,samples:[],chunkOffsets:[],currentChunk:null})}async writeHeader(){if(await this.writeFtyp(),!this.options.fastStart)this.mdatStart=this.writer.position,await this.writeMdatHeader(0)}async writeFtyp(){let q=[this.options.brand,"isom","iso2","mp42"],j=16+q.length*4;await this.writer.writeU32BE(j),await this.writer.writeFourCC("ftyp"),await this.writer.writeFourCC(this.options.brand),await this.writer.writeU32BE(512);for(let H of q)await this.writer.writeFourCC(H)}async writeMdatHeader(q){if(q>4294967287)await this.writer.writeU32BE(1),await this.writer.writeFourCC("mdat"),await this.writer.writeU64BE(BigInt(q+16));else await this.writer.writeU32BE(q+8),await this.writer.writeFourCC("mdat")}async writeVideoPacket(q,j){await this.writeSample(q.id,j)}async writeAudioPacket(q,j){await this.writeSample(q.id,j)}async writeSubtitlePacket(q,j){await this.writeSample(q.id,j)}async writeSample(q,j){let H=this.trackData.get(q);if(!H)return;let J={data:j.data,timestamp:j.timestamp,duration:j.duration??0,isKeyframe:j.isKeyframe,compositionTimeOffset:j.compositionTimeOffset??0,size:j.data.byteLength};if(this.options.fastStart)H.samples.push(J);else{let K=this.writer.position;if(await this.writer.writeBytes(j.data),this.mdatSize+=j.data.byteLength,J.size=j.data.byteLength,H.samples.push(J),!H.currentChunk)H.currentChunk={samples:[],offset:K},H.chunkOffsets.push(K);H.currentChunk.samples.push(J)}}async writeTrailer(){if(this.options.fastStart){let q=await this.buildMoov(0);this.mdatStart=this.writer.position+q.byteLength+8,await this.adjustChunkOffsets(this.mdatStart);let j=await this.buildMoov(this.mdatStart);await this.writer.writeBytes(j);let H=this.chapters.length>0?this.buildChapterTextSamples():[],J=0;for(let K of this.trackData.values())for(let P of K.samples)J+=P.size;for(let K of H)J+=K.data.byteLength;await this.writeMdatHeader(J);for(let K of this.trackData.values())for(let P of K.samples)await this.writer.writeBytes(P.data);for(let K of H)await this.writer.writeBytes(K.data)}else{let q=await this.buildMoov(this.mdatStart+8);await this.writer.writeBytes(q)}}async adjustChunkOffsets(q){let j=q;for(let H of this.trackData.values()){H.chunkOffsets=[];for(let J of H.samples)H.chunkOffsets.push(j),j+=J.size}}async buildMoov(q){let j=new V,H=await this.buildMvhd(),J=[],K=0;for(let F of this.trackData.values())for(let A of F.samples)K+=A.size;let P=this.chapters.length>0,Q=P?this.tracks.length+1:0,X=P?this.buildChapterTextSamples():[];for(let F of this.trackData.values()){let A=F.track.type==="audio"&&P?Q:void 0,G=await this.buildTrak(F,q,A);J.push(G)}if(P&&X.length>0){let F=q+K,A=await this.buildChapterTrak(Q,X,F);J.push(A)}let R=await this.buildUdta(),Z=H.byteLength+J.reduce((F,A)=>F+A.byteLength,0);if(R)Z+=R.byteLength;let $=Z+8;await j.writeU32BE($),await j.writeFourCC("moov"),await j.writeBytes(H);for(let F of J)await j.writeBytes(F);if(R)await j.writeBytes(R);return j.getBuffer()}async buildMvhd(){let q=new V,j=BigInt(Math.floor(Date.now()/1000))+y,H=0n;for(let P of this.trackData.values()){let Q=P.samples[P.samples.length-1];if(Q){let X=BigInt(Math.round((Q.timestamp+Q.duration)*T));if(X>H)H=X}}let J=108,K=this.chapters.length>0;await q.writeU32BE(J),await q.writeFourCC("mvhd"),await q.writeU8(0),await q.writeU8(0),await q.writeU8(0),await q.writeU8(0),await q.writeU32BE(Number(j&0xFFFFFFFFn)),await q.writeU32BE(Number(j&0xFFFFFFFFn)),await q.writeU32BE(T),await q.writeU32BE(Number(H&0xFFFFFFFFn)),await q.writeU32BE(65536),await q.writeU16BE(256),await q.writeU16BE(0),await q.writeU32BE(0),await q.writeU32BE(0),await q.writeU32BE(65536),await q.writeU32BE(0),await q.writeU32BE(0),await q.writeU32BE(0),await q.writeU32BE(65536),await q.writeU32BE(0),await q.writeU32BE(0),await q.writeU32BE(0),await q.writeU32BE(1073741824);for(let P=0;P<6;P++)await q.writeU32BE(0);return await q.writeU32BE(this.tracks.length+1+(K?1:0)),q.getBuffer()}async buildTrak(q,j,H){let J=new V,K=await this.buildTkhd(q),P=H?await this.buildTref(H):null,Q=await this.buildMdia(q,j),X=8+K.byteLength+Q.byteLength;if(P)X+=P.byteLength;if(await J.writeU32BE(X),await J.writeFourCC("trak"),await J.writeBytes(K),P)await J.writeBytes(P);return await J.writeBytes(Q),J.getBuffer()}async buildTkhd(q){let j=new V,H=BigInt(Math.floor(Date.now()/1000))+y,J=q.samples[q.samples.length-1],K=J?BigInt(Math.round((J.timestamp+J.duration)*T)):0n,P=92,Q=q.track,X=0,R=0,Z=0;if(Q.type==="video")X=Q.config.width,R=Q.config.height;else if(Q.type==="audio")Z=256;return await j.writeU32BE(92),await j.writeFourCC("tkhd"),await j.writeU8(0),await j.writeU8(0),await j.writeU8(0),await j.writeU8(3),await j.writeU32BE(Number(H&0xFFFFFFFFn)),await j.writeU32BE(Number(H&0xFFFFFFFFn)),await j.writeU32BE(Q.id),await j.writeU32BE(0),await j.writeU32BE(Number(K&0xFFFFFFFFn)),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU16BE(0),await j.writeU16BE(0),await j.writeU16BE(Z),await j.writeU16BE(0),await j.writeU32BE(65536),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU32BE(65536),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU32BE(1073741824),await j.writeU32BE(X<<16),await j.writeU32BE(R<<16),j.getBuffer()}async buildMdia(q,j){let H=new V,J=await this.buildMdhd(q),K=await this.buildHdlr(q),P=await this.buildMinf(q,j),Q=8+J.byteLength+K.byteLength+P.byteLength;return await H.writeU32BE(Q),await H.writeFourCC("mdia"),await H.writeBytes(J),await H.writeBytes(K),await H.writeBytes(P),H.getBuffer()}async buildMdhd(q){let j=new V,H=BigInt(Math.floor(Date.now()/1000))+y,J=q.samples[q.samples.length-1],K=J?BigInt(Math.round((J.timestamp+J.duration)*q.timescale)):0n,P=32;return await j.writeU32BE(32),await j.writeFourCC("mdhd"),await j.writeU8(0),await j.writeU8(0),await j.writeU8(0),await j.writeU8(0),await j.writeU32BE(Number(H&0xFFFFFFFFn)),await j.writeU32BE(Number(H&0xFFFFFFFFn)),await j.writeU32BE(q.timescale),await j.writeU32BE(Number(K&0xFFFFFFFFn)),await j.writeU16BE(m("und")),await j.writeU16BE(0),j.getBuffer()}async buildHdlr(q){let j=new V,H="",J="";if(q.track.type==="video")H="vide",J="VideoHandler";else if(q.track.type==="audio")H="soun",J="SoundHandler";else H="text",J="SubtitleHandler";let K=new TextEncoder().encode(`${J}\x00`),P=32+K.byteLength;return await j.writeU32BE(P),await j.writeFourCC("hdlr"),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeFourCC(H),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeBytes(K),j.getBuffer()}async buildMinf(q,j){let H=new V,J;if(q.track.type==="video")J=await this.buildVmhd();else if(q.track.type==="audio")J=await this.buildSmhd();else J=await this.buildNmhd();let K=await this.buildDinf(),P=await this.buildStbl(q,j),Q=8+J.byteLength+K.byteLength+P.byteLength;return await H.writeU32BE(Q),await H.writeFourCC("minf"),await H.writeBytes(J),await H.writeBytes(K),await H.writeBytes(P),H.getBuffer()}async buildVmhd(){let q=new V,j=20;return await q.writeU32BE(20),await q.writeFourCC("vmhd"),await q.writeU32BE(1),await q.writeU16BE(0),await q.writeU16BE(0),await q.writeU16BE(0),await q.writeU16BE(0),q.getBuffer()}async buildSmhd(){let q=new V,j=16;return await q.writeU32BE(16),await q.writeFourCC("smhd"),await q.writeU32BE(0),await q.writeU16BE(0),await q.writeU16BE(0),q.getBuffer()}async buildNmhd(){let q=new V,j=12;return await q.writeU32BE(12),await q.writeFourCC("nmhd"),await q.writeU32BE(0),q.getBuffer()}async buildDinf(){let q=new V,j=await this.buildDref(),H=8+j.byteLength;return await q.writeU32BE(H),await q.writeFourCC("dinf"),await q.writeBytes(j),q.getBuffer()}async buildDref(){let q=new V,j=28;return await q.writeU32BE(28),await q.writeFourCC("dref"),await q.writeU32BE(0),await q.writeU32BE(1),await q.writeU32BE(12),await q.writeFourCC("url "),await q.writeU32BE(1),q.getBuffer()}async buildStbl(q,j){let H=new V,J=await this.buildStsd(q),K=await this.buildStts(q),P=await this.buildStsc(q),Q=await this.buildStsz(q),X=await this.buildStco(q,j),R=null,Z=null;if(q.track.type==="video")R=await this.buildStss(q),Z=await this.buildCtts(q);let $=8+J.byteLength+K.byteLength+P.byteLength+Q.byteLength+X.byteLength;if(R)$+=R.byteLength;if(Z)$+=Z.byteLength;if(await H.writeU32BE($),await H.writeFourCC("stbl"),await H.writeBytes(J),await H.writeBytes(K),Z)await H.writeBytes(Z);if(await H.writeBytes(P),await H.writeBytes(Q),await H.writeBytes(X),R)await H.writeBytes(R);return H.getBuffer()}async buildStsd(q){let j=new V,H;if(q.track.type==="video")H=await this.buildVideoSampleEntry(q.track);else if(q.track.type==="audio")H=await this.buildAudioSampleEntry(q.track);else H=new Uint8Array(0);let J=16+H.byteLength;return await j.writeU32BE(J),await j.writeFourCC("stsd"),await j.writeU32BE(0),await j.writeU32BE(1),await j.writeBytes(H),j.getBuffer()}async buildVideoSampleEntry(q){let j=new V,H=q.config,J="";if(H.codec==="h264")J="avc1";else if(H.codec==="h265")J="hev1";else if(H.codec==="vp9")J="vp09";else if(H.codec==="av1")J="av01";else if(H.codec==="prores")J={proxy:"apco",lt:"apcs","422":"apcn",standard:"apcn",hq:"apch","4444":"ap4h","4444-xq":"ap4x"}[H.profile??"422"]??"apcn";else J="mp4v";let K=H.codecDescription??new Uint8Array(0),P=H.codec==="h264"?"avcC":H.codec==="h265"?"hvcC":H.codec==="vp9"?"vpcC":H.codec==="av1"?"av1C":void 0,Q=P&&K.byteLength>0?8+K.byteLength:0,X=86+Q;await j.writeU32BE(X),await j.writeFourCC(J),await j.writeU32BE(0),await j.writeU16BE(0),await j.writeU16BE(1),await j.writeU16BE(0),await j.writeU16BE(0),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU16BE(H.width),await j.writeU16BE(H.height),await j.writeU32BE(4718592),await j.writeU32BE(4718592),await j.writeU32BE(0),await j.writeU16BE(1);let R=new Uint8Array(32);if(await j.writeBytes(R),await j.writeU16BE(24),await j.writeI16BE(-1),Q>0)await j.writeU32BE(Q),await j.writeFourCC(P),await j.writeBytes(K);return j.getBuffer()}async buildAudioSampleEntry(q){let j=new V,H=q.config,J="mp4a";if(H.codec==="opus")J="Opus";else if(H.codec==="flac")J="fLaC";let K=H.codecDescription??new Uint8Array(0),P=K.byteLength>0?8+K.byteLength:0,Q=36+P;if(await j.writeU32BE(Q),await j.writeFourCC(J),await j.writeU32BE(0),await j.writeU16BE(0),await j.writeU16BE(1),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU16BE(H.channels),await j.writeU16BE(H.bitsPerSample??16),await j.writeU16BE(0),await j.writeU16BE(0),await j.writeU32BE(H.sampleRate<<16),P>0)await j.writeU32BE(P),await j.writeFourCC("esds"),await j.writeBytes(K);return j.getBuffer()}async buildStts(q){let j=new V,H=[],J=-1;for(let P of q.samples){let Q=Math.round(P.duration*q.timescale);if(Q===J&&H.length>0)H[H.length-1].sampleCount++;else H.push({sampleCount:1,sampleDelta:Q}),J=Q}let K=16+H.length*8;await j.writeU32BE(K),await j.writeFourCC("stts"),await j.writeU32BE(0),await j.writeU32BE(H.length);for(let P of H)await j.writeU32BE(P.sampleCount),await j.writeU32BE(P.sampleDelta);return j.getBuffer()}async buildCtts(q){let j=new V,H=[],J=Number.MIN_SAFE_INTEGER;for(let P of q.samples){let Q=Math.round(P.compositionTimeOffset*q.timescale);if(Q===J&&H.length>0)H[H.length-1].sampleCount++;else H.push({sampleCount:1,sampleOffset:Q}),J=Q}if(H.length===0||H.length===1&&H[0].sampleOffset===0)return new Uint8Array(0);let K=16+H.length*8;await j.writeU32BE(K),await j.writeFourCC("ctts"),await j.writeU32BE(0),await j.writeU32BE(H.length);for(let P of H)await j.writeU32BE(P.sampleCount),await j.writeU32BE(P.sampleOffset);return j.getBuffer()}async buildStsc(q){let j=new V,H=28;return await j.writeU32BE(28),await j.writeFourCC("stsc"),await j.writeU32BE(0),await j.writeU32BE(1),await j.writeU32BE(1),await j.writeU32BE(1),await j.writeU32BE(1),j.getBuffer()}async buildStsz(q){let j=new V,H=20+q.samples.length*4;await j.writeU32BE(H),await j.writeFourCC("stsz"),await j.writeU32BE(0),await j.writeU32BE(0),await j.writeU32BE(q.samples.length);for(let J of q.samples)await j.writeU32BE(J.size);return j.getBuffer()}async buildStco(q,j){let H=new V,J=j,K=[];for(let Q of q.samples)K.push(J),J+=Q.size;let P=16+K.length*4;await H.writeU32BE(P),await H.writeFourCC("stco"),await H.writeU32BE(0),await H.writeU32BE(K.length);for(let Q of K)await H.writeU32BE(Q);return H.getBuffer()}async buildStss(q){let j=new V,H=[];for(let K=0;K<q.samples.length;K++)if(q.samples[K].isKeyframe)H.push(K+1);if(H.length===q.samples.length)return new Uint8Array(0);let J=16+H.length*4;await j.writeU32BE(J),await j.writeFourCC("stss"),await j.writeU32BE(0),await j.writeU32BE(H.length);for(let K of H)await j.writeU32BE(K);return j.getBuffer()}async buildTref(q){let j=new V;return await j.writeU32BE(20),await j.writeFourCC("tref"),await j.writeU32BE(12),await j.writeFourCC("chap"),await j.writeU32BE(q),j.getBuffer()}buildChapterTextSamples(){if(this.chapters.length===0)return[];let q=0;for(let J of this.trackData.values()){let K=J.samples[J.samples.length-1];if(K)q=Math.max(q,Math.round((K.timestamp+K.duration)*1000))}let j=new TextEncoder,H=[];for(let J=0;J<this.chapters.length;J++){let K=this.chapters[J],P=J+1<this.chapters.length?this.chapters[J+1].startTimeMs:q,Q=Math.max(1,Math.round(P-K.startTimeMs)),X=j.encode(K.title),R=new Uint8Array(2+X.length);R[0]=X.length>>8&255,R[1]=X.length&255,R.set(X,2),H.push({data:R,durationMs:Q})}return H}async buildTextSampleEntry(){let q=new V;return await q.writeU32BE(59),await q.writeFourCC("text"),await q.writeU32BE(0),await q.writeU16BE(0),await q.writeU16BE(1),await q.writeU32BE(1),await q.writeU32BE(0),await q.writeU16BE(0),await q.writeU16BE(0),await q.writeU16BE(0),await q.writeU16BE(0),await q.writeU16BE(0),await q.writeU16BE(0),await q.writeU16BE(1),await q.writeU32BE(0),await q.writeU32BE(0),await q.writeU16BE(0),await q.writeU16BE(13),await q.writeFourCC("ftab"),await q.writeU16BE(1),await q.writeU16BE(1),await q.writeU8(0),q.getBuffer()}async buildChapterTrak(q,j,H){let J=new V,K=BigInt(Math.floor(Date.now()/1000))+y,P=1000,Q=new TextEncoder,X=0;for(let N of j)X+=N.durationMs;let R=new V;await R.writeU32BE(92),await R.writeFourCC("tkhd"),await R.writeU8(0),await R.writeU8(0),await R.writeU8(0),await R.writeU8(1),await R.writeU32BE(Number(K&0xFFFFFFFFn)),await R.writeU32BE(Number(K&0xFFFFFFFFn)),await R.writeU32BE(q),await R.writeU32BE(0),await R.writeU32BE(X),await R.writeU32BE(0),await R.writeU32BE(0),await R.writeU16BE(0),await R.writeU16BE(0),await R.writeU16BE(0),await R.writeU16BE(0),await R.writeU32BE(65536),await R.writeU32BE(0),await R.writeU32BE(0),await R.writeU32BE(0),await R.writeU32BE(65536),await R.writeU32BE(0),await R.writeU32BE(0),await R.writeU32BE(0),await R.writeU32BE(1073741824),await R.writeU32BE(0),await R.writeU32BE(0);let Z=R.getBuffer(),$=new V;await $.writeU32BE(32),await $.writeFourCC("mdhd"),await $.writeU32BE(0),await $.writeU32BE(Number(K&0xFFFFFFFFn)),await $.writeU32BE(Number(K&0xFFFFFFFFn)),await $.writeU32BE(1000),await $.writeU32BE(X),await $.writeU16BE(0),await $.writeU16BE(0);let F=$.getBuffer(),A=Q.encode("ChapterHandler\x00"),G=new V;await G.writeU32BE(32+A.byteLength),await G.writeFourCC("hdlr"),await G.writeU32BE(0),await G.writeU32BE(0),await G.writeFourCC("text"),await G.writeU32BE(0),await G.writeU32BE(0),await G.writeU32BE(0),await G.writeBytes(A);let I=G.getBuffer(),L=new V;await L.writeU32BE(36),await L.writeFourCC("edts"),await L.writeU32BE(28),await L.writeFourCC("elst"),await L.writeU32BE(0),await L.writeU32BE(1),await L.writeU32BE(X),await L.writeU32BE(0),await L.writeU32BE(65536);let b=L.getBuffer(),Y=new V;await Y.writeU32BE(76),await Y.writeFourCC("gmhd"),await Y.writeU32BE(24),await Y.writeFourCC("gmin"),await Y.writeU32BE(0),await Y.writeU16BE(64),await Y.writeU16BE(32768),await Y.writeU16BE(32768),await Y.writeU16BE(32768),await Y.writeU16BE(0),await Y.writeU16BE(0),await Y.writeU32BE(44),await Y.writeFourCC("text"),await Y.writeU32BE(65536),await Y.writeU32BE(0),await Y.writeU32BE(0),await Y.writeU32BE(0),await Y.writeU32BE(65536),await Y.writeU32BE(0),await Y.writeU32BE(0),await Y.writeU32BE(0),await Y.writeU32BE(1073741824);let z=Y.getBuffer(),u=await this.buildDinf(),S=await this.buildTextSampleEntry(),D=new V;await D.writeU32BE(16+S.byteLength),await D.writeFourCC("stsd"),await D.writeU32BE(0),await D.writeU32BE(1),await D.writeBytes(S);let g=D.getBuffer(),E=[],k=-1;for(let N of j)if(N.durationMs===k&&E.length>0)E[E.length-1].count++;else E.push({count:1,delta:N.durationMs}),k=N.durationMs;let _=new V;await _.writeU32BE(16+E.length*8),await _.writeFourCC("stts"),await _.writeU32BE(0),await _.writeU32BE(E.length);for(let N of E)await _.writeU32BE(N.count),await _.writeU32BE(N.delta);let p=_.getBuffer(),M=new V;await M.writeU32BE(28),await M.writeFourCC("stsc"),await M.writeU32BE(0),await M.writeU32BE(1),await M.writeU32BE(1),await M.writeU32BE(1),await M.writeU32BE(1);let f=M.getBuffer(),v=new V;await v.writeU32BE(20+j.length*4),await v.writeFourCC("stsz"),await v.writeU32BE(0),await v.writeU32BE(0),await v.writeU32BE(j.length);for(let N of j)await v.writeU32BE(N.data.byteLength);let n=v.getBuffer(),O=new V;await O.writeU32BE(16+j.length*4),await O.writeFourCC("stco"),await O.writeU32BE(0),await O.writeU32BE(j.length);let h=H;for(let N of j)await O.writeU32BE(h),h+=N.data.byteLength;let o=O.getBuffer(),w=8+g.byteLength+p.byteLength+f.byteLength+n.byteLength+o.byteLength,C=new V;await C.writeU32BE(w),await C.writeFourCC("stbl"),await C.writeBytes(g),await C.writeBytes(p),await C.writeBytes(f),await C.writeBytes(n),await C.writeBytes(o);let W=C.getBuffer(),d=8+z.byteLength+u.byteLength+W.byteLength,B=new V;await B.writeU32BE(d),await B.writeFourCC("minf"),await B.writeBytes(z),await B.writeBytes(u),await B.writeBytes(W);let l=B.getBuffer(),s=8+F.byteLength+I.byteLength+l.byteLength,x=new V;await x.writeU32BE(s),await x.writeFourCC("mdia"),await x.writeBytes(F),await x.writeBytes(I),await x.writeBytes(l);let c=x.getBuffer(),a=8+Z.byteLength+b.byteLength+c.byteLength;return await J.writeU32BE(a),await J.writeFourCC("trak"),await J.writeBytes(Z),await J.writeBytes(b),await J.writeBytes(c),J.getBuffer()}async buildUdta(){let q=this.metadata&&Object.keys(this.metadata).length>0,j=this.artwork!==null,H=this.chapters.length>0;if(!q&&!j&&!H)return null;let J=new V,K=[];if(H)K.push(await this.buildChpl());if(q||j)K.push(await this.buildMeta());let P=K.reduce((Q,X)=>Q+X.byteLength,0);await J.writeU32BE(P+8),await J.writeFourCC("udta");for(let Q of K)await J.writeBytes(Q);return J.getBuffer()}async buildMeta(){let q=new V,j=await this.buildMetaHdlr(),H=await this.buildIlst(),J=4+j.byteLength+H.byteLength;return await q.writeU32BE(J+8),await q.writeFourCC("meta"),await q.writeU32BE(0),await q.writeBytes(j),await q.writeBytes(H),q.getBuffer()}async buildMetaHdlr(){let q=new V,j=33;return await q.writeU32BE(33),await q.writeFourCC("hdlr"),await q.writeU32BE(0),await q.writeU32BE(0),await q.writeFourCC("mdir"),await q.writeFourCC("appl"),await q.writeU32BE(0),await q.writeU32BE(0),await q.writeU8(0),q.getBuffer()}async buildIlst(){let q=new V,j=[],H=this.metadata;if(H.title)j.push(U("©nam",H.title));if(H.artist)j.push(U("©ART",H.artist));if(H.albumArtist)j.push(U("aART",H.albumArtist));if(H.album)j.push(U("©alb",H.album));if(H.genre)j.push(U("©gen",H.genre));if(H.year)j.push(U("©day",String(H.year)));if(H.composer)j.push(U("©wrt",H.composer));if(H.copyright)j.push(U("cprt",H.copyright));if(H.comment)j.push(U("©cmt",H.comment));if(H.encodedBy)j.push(U("©too",H.encodedBy));if(H.narrator)j.push(U("©nrt",H.narrator));if(H.publisher)j.push(U("©pub",H.publisher));if(H.description)j.push(U("desc",H.description));if(this.artwork){let K=this.artworkType==="png"?14:13;j.push(r("covr",this.artwork,K))}let J=j.reduce((K,P)=>K+P.byteLength,0);await q.writeU32BE(J+8),await q.writeFourCC("ilst");for(let K of j)await q.writeBytes(K);return q.getBuffer()}async buildChpl(){let q=new V,j=new TextEncoder,H=[];for(let P of this.chapters){let Q=j.encode(P.title),X=Math.min(Q.length,255),R=BigInt(Math.round(P.startTimeMs*1e4)),Z=new Uint8Array(9+X);new DataView(Z.buffer).setBigUint64(0,R),Z[8]=X,Z.set(Q.subarray(0,X),9),H.push(Z)}let K=12+H.reduce((P,Q)=>P+Q.byteLength,0);await q.writeU32BE(K+8),await q.writeFourCC("chpl"),await q.writeU8(1),await q.writeU8(0),await q.writeU8(0),await q.writeU8(0),await q.writeU32BE(0),await q.writeU32BE(this.chapters.length);for(let P of H)await q.writeBytes(P);return q.getBuffer()}}function U(q,j){let J=new TextEncoder().encode(j),K=16+J.length,P=8+K,Q=new Uint8Array(P),X=new DataView(Q.buffer);return X.setUint32(0,P),Q[4]=q.charCodeAt(0)&255,Q[5]=q.charCodeAt(1)&255,Q[6]=q.charCodeAt(2)&255,Q[7]=q.charCodeAt(3)&255,X.setUint32(8,K),Q[12]=100,Q[13]=97,Q[14]=116,Q[15]=97,X.setUint32(16,1),X.setUint32(20,0),Q.set(J,24),Q}function r(q,j,H){let J=16+j.length,K=8+J,P=new Uint8Array(K),Q=new DataView(P.buffer);return Q.setUint32(0,K),P[4]=q.charCodeAt(0)&255,P[5]=q.charCodeAt(1)&255,P[6]=q.charCodeAt(2)&255,P[7]=q.charCodeAt(3)&255,Q.setUint32(8,J),P[12]=100,P[13]=97,P[14]=116,P[15]=97,Q.setUint32(16,H),Q.setUint32(20,0),P.set(j,24),P}
|
|
2
|
-
export{e as m};
|
package/dist/chunk-zmpvp966.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{m as E}from"./chunk-wmd2bsvz.js";import{n as G}from"./chunk-51x739sq.js";import{o as J}from"./chunk-vetfxydj.js";import{u as Q,v as T}from"./chunk-63shg4s1.js";import{InputFormat as U}from"ts-videos/demuxer";import{OutputFormat as K}from"ts-videos/muxer";import{Reader as W}from"ts-videos/reader";class X extends U{get name(){return"mp4"}get mimeType(){return"video/mp4"}get extensions(){return["mp4","m4v","m4a","f4v"]}async canRead(j){let k=W.fromSource(j);k.position=0;let q=await k.readU32BE();if(q===null||q<8)return!1;if(await k.readFourCC()!=="ftyp")return!1;let y=await k.readFourCC();if(!y)return!1;return Q.has(y)}createDemuxer(j){return new G(j)}}class Y extends U{get name(){return"mov"}get mimeType(){return"video/quicktime"}get extensions(){return["mov","qt"]}async canRead(j){let k=W.fromSource(j);k.position=0;let q=await k.readU32BE();if(q===null||q<8)return!1;if(await k.readFourCC()!=="ftyp")return!1;let y=await k.readFourCC();if(!y)return!1;return T.has(y)}createDemuxer(j){return new G(j)}}class Z extends K{options;constructor(j={}){super();this.options=j}get name(){return"mp4"}get mimeType(){return"video/mp4"}get extension(){return"mp4"}createMuxer(j){return new E(j,this.options)}}class $ extends K{options;constructor(j={}){super();this.options={...j,brand:"qt "}}get name(){return"mov"}get mimeType(){return"video/quicktime"}get extension(){return"mov"}createMuxer(j){return new E(j,this.options)}}class h extends K{options;constructor(j={}){super();this.options=j}get name(){return"fmp4"}get mimeType(){return"video/mp4"}get extension(){return"mp4"}createMuxer(j){return new J(j,this.options)}}class w extends K{options;constructor(j={}){super();this.options={...j,cmaf:!0}}get name(){return"cmaf"}get mimeType(){return"video/mp4"}get extension(){return"cmfv"}createMuxer(j){return new J(j,this.options)}}var R=new X,S=new Y,f=new Z,D=new $,A=new h,C=new w;
|
|
2
|
-
export{X as a,Y as b,Z as c,$ as d,h as e,w as f,R as g,S as h,f as i,D as j,A as k,C as l};
|