@ts-videos/mp4 0.1.0 → 0.1.1

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.
@@ -0,0 +1,226 @@
1
+ export declare function readFourCC(view: DataView, offset: number): string;
2
+ export declare function writeFourCC(view: DataView, offset: number, value: string): void;
3
+ export declare function isVideoHandler(handlerType: string): boolean;
4
+ export declare function isAudioHandler(handlerType: string): boolean;
5
+ export declare function isSubtitleHandler(handlerType: string): boolean;
6
+ export declare function parseLanguageCode(code: number): string;
7
+ export declare function encodeLanguageCode(lang: string): number;
8
+ export declare const BOX_HEADER_SIZE: 8;
9
+ export declare const EXTENDED_BOX_HEADER_SIZE: 16;
10
+ export declare const CONTAINER_BOXES: Set<string>;
11
+ export declare const MP4_BRANDS: Set<string>;
12
+ export declare const MOV_BRANDS: Set<string>;
13
+ export declare const TIMESCALE_1904_TO_1970: 2082844800n;
14
+ /**
15
+ * ISOBMFF Box definitions and parsing utilities
16
+ */
17
+ export declare interface Box {
18
+ type: string
19
+ size: number
20
+ offset: number
21
+ data?: Uint8Array
22
+ children?: Box[]
23
+ }
24
+ export declare interface FtypBox extends Box {
25
+ type: 'ftyp'
26
+ majorBrand: string
27
+ minorVersion: number
28
+ compatibleBrands: string[]
29
+ }
30
+ export declare interface MvhdBox extends Box {
31
+ type: 'mvhd'
32
+ version: number
33
+ creationTime: bigint
34
+ modificationTime: bigint
35
+ timescale: number
36
+ duration: bigint
37
+ rate: number
38
+ volume: number
39
+ matrix: number[]
40
+ nextTrackId: number
41
+ }
42
+ export declare interface TkhdBox extends Box {
43
+ type: 'tkhd'
44
+ version: number
45
+ flags: number
46
+ creationTime: bigint
47
+ modificationTime: bigint
48
+ trackId: number
49
+ duration: bigint
50
+ layer: number
51
+ alternateGroup: number
52
+ volume: number
53
+ matrix: number[]
54
+ width: number
55
+ height: number
56
+ }
57
+ export declare interface MdhdBox extends Box {
58
+ type: 'mdhd'
59
+ version: number
60
+ creationTime: bigint
61
+ modificationTime: bigint
62
+ timescale: number
63
+ duration: bigint
64
+ language: string
65
+ }
66
+ export declare interface HdlrBox extends Box {
67
+ type: 'hdlr'
68
+ handlerType: string
69
+ name: string
70
+ }
71
+ export declare interface StsdBox extends Box {
72
+ type: 'stsd'
73
+ entryCount: number
74
+ entries: SampleEntry[]
75
+ }
76
+ export declare interface SampleEntry {
77
+ type: string
78
+ dataReferenceIndex: number
79
+ data: Uint8Array
80
+ }
81
+ export declare interface VideoSampleEntry extends SampleEntry {
82
+ width: number
83
+ height: number
84
+ horizResolution: number
85
+ vertResolution: number
86
+ frameCount: number
87
+ compressorName: string
88
+ depth: number
89
+ extensions: Box[]
90
+ }
91
+ export declare interface AudioSampleEntry extends SampleEntry {
92
+ channelCount: number
93
+ sampleSize: number
94
+ sampleRate: number
95
+ extensions: Box[]
96
+ }
97
+ export declare interface SttsBox extends Box {
98
+ type: 'stts'
99
+ entries: { sampleCount: number, sampleDelta: number }[]
100
+ }
101
+ export declare interface CttsBox extends Box {
102
+ type: 'ctts'
103
+ version: number
104
+ entries: { sampleCount: number, sampleOffset: number }[]
105
+ }
106
+ export declare interface StscBox extends Box {
107
+ type: 'stsc'
108
+ entries: { firstChunk: number, samplesPerChunk: number, sampleDescriptionIndex: number }[]
109
+ }
110
+ export declare interface StszBox extends Box {
111
+ type: 'stsz'
112
+ sampleSize: number
113
+ sampleCount: number
114
+ entrySizes: number[]
115
+ }
116
+ export declare interface StcoBox extends Box {
117
+ type: 'stco'
118
+ chunkOffsets: number[]
119
+ }
120
+ export declare interface Co64Box extends Box {
121
+ type: 'co64'
122
+ chunkOffsets: bigint[]
123
+ }
124
+ export declare interface StssBox extends Box {
125
+ type: 'stss'
126
+ sampleNumbers: number[]
127
+ }
128
+ export declare interface ElstBox extends Box {
129
+ type: 'elst'
130
+ version: number
131
+ entries: { segmentDuration: bigint, mediaTime: bigint, mediaRateInteger: number, mediaRateFraction: number }[]
132
+ }
133
+ export declare interface AvcCBox extends Box {
134
+ type: 'avcC'
135
+ configurationVersion: number
136
+ avcProfileIndication: number
137
+ profileCompatibility: number
138
+ avcLevelIndication: number
139
+ lengthSizeMinusOne: number
140
+ sps: Uint8Array[]
141
+ pps: Uint8Array[]
142
+ }
143
+ export declare interface HvcCBox extends Box {
144
+ type: 'hvcC'
145
+ configurationVersion: number
146
+ generalProfileSpace: number
147
+ generalTierFlag: number
148
+ generalProfileIdc: number
149
+ generalProfileCompatibilityFlags: number
150
+ generalConstraintIndicatorFlags: bigint
151
+ generalLevelIdc: number
152
+ minSpatialSegmentationIdc: number
153
+ parallelismType: number
154
+ chromaFormatIdc: number
155
+ bitDepthLumaMinus8: number
156
+ bitDepthChromaMinus8: number
157
+ avgFrameRate: number
158
+ constantFrameRate: number
159
+ numTemporalLayers: number
160
+ temporalIdNested: number
161
+ lengthSizeMinusOne: number
162
+ arrays: HvcCArray[]
163
+ }
164
+ export declare interface HvcCArray {
165
+ arrayCompleteness: number
166
+ nalUnitType: number
167
+ nalUnits: Uint8Array[]
168
+ }
169
+ export declare interface EsdsBox extends Box {
170
+ type: 'esds'
171
+ objectTypeIndication: number
172
+ streamType: number
173
+ bufferSizeDB: number
174
+ maxBitrate: number
175
+ avgBitrate: number
176
+ decoderSpecificInfo: Uint8Array
177
+ }
178
+ export declare interface MdatBox extends Box {
179
+ type: 'mdat'
180
+ dataOffset: number
181
+ dataSize: number
182
+ }
183
+ export declare interface MoofBox extends Box {
184
+ type: 'moof'
185
+ mfhd?: MfhdBox
186
+ trafs: TrafBox[]
187
+ }
188
+ export declare interface MfhdBox extends Box {
189
+ type: 'mfhd'
190
+ sequenceNumber: number
191
+ }
192
+ export declare interface TrafBox extends Box {
193
+ type: 'traf'
194
+ tfhd: TfhdBox
195
+ tfdt?: TfdtBox
196
+ truns: TrunBox[]
197
+ }
198
+ export declare interface TfhdBox extends Box {
199
+ type: 'tfhd'
200
+ flags: number
201
+ trackId: number
202
+ baseDataOffset?: bigint
203
+ sampleDescriptionIndex?: number
204
+ defaultSampleDuration?: number
205
+ defaultSampleSize?: number
206
+ defaultSampleFlags?: number
207
+ }
208
+ export declare interface TfdtBox extends Box {
209
+ type: 'tfdt'
210
+ version: number
211
+ baseMediaDecodeTime: bigint
212
+ }
213
+ export declare interface TrunBox extends Box {
214
+ type: 'trun'
215
+ flags: number
216
+ sampleCount: number
217
+ dataOffset?: number
218
+ firstSampleFlags?: number
219
+ samples: TrunSample[]
220
+ }
221
+ export declare interface TrunSample {
222
+ duration?: number
223
+ size?: number
224
+ flags?: number
225
+ compositionTimeOffset?: number
226
+ }
package/dist/boxes.js ADDED
@@ -0,0 +1 @@
1
+ import{A as l,B as m,p as a,q as b,r as c,s as d,t as e,u as f,v as g,w as h,x as i,y as j,z as k}from"./chunk-63shg4s1.js";export{d as writeFourCC,c as readFourCC,k as parseLanguageCode,h as isVideoHandler,j as isSubtitleHandler,i as isAudioHandler,l as encodeLanguageCode,m as TIMESCALE_1904_TO_1970,f as MP4_BRANDS,g as MOV_BRANDS,b as EXTENDED_BOX_HEADER_SIZE,e as CONTAINER_BOXES,a as BOX_HEADER_SIZE};
@@ -0,0 +1,2 @@
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};
@@ -0,0 +1,2 @@
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};
@@ -0,0 +1,2 @@
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};
@@ -0,0 +1,2 @@
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};
@@ -0,0 +1,2 @@
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};
@@ -0,0 +1,9 @@
1
+ import { Demuxer } from 'ts-videos/demuxer';
2
+ import type { EncodedPacket } from 'ts-videos/types';
3
+ export declare class Mp4Demuxer extends Demuxer {
4
+ get formatName(): string;
5
+ get mimeType(): string;
6
+ init(): Promise<void>;
7
+ readPacket(trackId: number): Promise<EncodedPacket | null>;
8
+ seek(timeInSeconds: number): Promise<void>;
9
+ }
@@ -0,0 +1 @@
1
+ import{n as a}from"./chunk-51x739sq.js";import"./chunk-63shg4s1.js";export{a as Mp4Demuxer};
@@ -0,0 +1,28 @@
1
+ import { Muxer } from 'ts-videos/muxer';
2
+ import type { EncodedPacket } from 'ts-videos/types';
3
+ import type { OutputVideoTrack, OutputAudioTrack, OutputSubtitleTrack } from 'ts-videos/muxer';
4
+ import type { Target } from 'ts-videos/writer';
5
+ /**
6
+ * Fragmented MP4 options
7
+ */
8
+ export declare interface FragmentedMp4Options {
9
+ fragmentDuration?: number
10
+ brand?: string
11
+ cmaf?: boolean
12
+ lowLatency?: boolean
13
+ }
14
+ /**
15
+ * FragmentedMp4Muxer - Generate fragmented MP4 files for streaming
16
+ */
17
+ export declare class FragmentedMp4Muxer extends Muxer {
18
+ constructor(target: Target, options?: FragmentedMp4Options);
19
+ get formatName(): string;
20
+ get mimeType(): string;
21
+ protected onTrackAdded(track: OutputVideoTrack | OutputAudioTrack | OutputSubtitleTrack): void;
22
+ protected writeHeader(): Promise<void>;
23
+ protected writeVideoPacket(track: OutputVideoTrack, packet: EncodedPacket): Promise<void>;
24
+ protected writeAudioPacket(track: OutputAudioTrack, packet: EncodedPacket): Promise<void>;
25
+ protected writeSubtitlePacket(track: OutputSubtitleTrack, packet: EncodedPacket): Promise<void>;
26
+ flushFragment(): Promise<void>;
27
+ protected writeTrailer(): Promise<void>;
28
+ }
@@ -0,0 +1 @@
1
+ import{o as a}from"./chunk-vetfxydj.js";import"./chunk-63shg4s1.js";export{a as FragmentedMp4Muxer};
@@ -0,0 +1,68 @@
1
+ import { Demuxer } from 'ts-videos/demuxer';
2
+ import { FragmentedMp4Muxer, type FragmentedMp4Options } from './fragmented';
3
+ import { InputFormat } from 'ts-videos/demuxer';
4
+ import { Mp4Demuxer } from './demuxer';
5
+ import { Mp4Muxer, type Mp4MuxerOptions } from './muxer';
6
+ import { Muxer } from 'ts-videos/muxer';
7
+ import { OutputFormat } from 'ts-videos/muxer';
8
+ import type { Source } from 'ts-videos/reader';
9
+ import type { Target } from 'ts-videos/writer';
10
+ export declare const MP4: Mp4InputFormat;
11
+ export declare const MOV: MovInputFormat;
12
+ export declare const MP4_OUTPUT: Mp4OutputFormat;
13
+ export declare const MOV_OUTPUT: MovOutputFormat;
14
+ export declare const FMP4_OUTPUT: FragmentedMp4OutputFormat;
15
+ export declare const CMAF_OUTPUT: CmafOutputFormat;
16
+ export declare class Mp4InputFormat extends InputFormat {
17
+ get name(): string;
18
+ get mimeType(): string;
19
+ get extensions(): string[];
20
+ canRead(source: Source): Promise<boolean>;
21
+ createDemuxer(source: Source): Demuxer;
22
+ }
23
+ export declare class MovInputFormat extends InputFormat {
24
+ get name(): string;
25
+ get mimeType(): string;
26
+ get extensions(): string[];
27
+ canRead(source: Source): Promise<boolean>;
28
+ createDemuxer(source: Source): Demuxer;
29
+ }
30
+ export declare class Mp4OutputFormat extends OutputFormat {
31
+ constructor(options?: Mp4MuxerOptions);
32
+ get name(): string;
33
+ get mimeType(): string;
34
+ get extension(): string;
35
+ createMuxer(target: Target): Muxer;
36
+ }
37
+ export declare class MovOutputFormat extends OutputFormat {
38
+ constructor(options?: Mp4MuxerOptions);
39
+ get name(): string;
40
+ get mimeType(): string;
41
+ get extension(): string;
42
+ createMuxer(target: Target): Muxer;
43
+ }
44
+ /**
45
+ * Fragmented MP4 output format for streaming
46
+ */
47
+ export declare class FragmentedMp4OutputFormat extends OutputFormat {
48
+ constructor(options?: FragmentedMp4Options);
49
+ get name(): string;
50
+ get mimeType(): string;
51
+ get extension(): string;
52
+ createMuxer(target: Target): Muxer;
53
+ }
54
+ /**
55
+ * CMAF (Common Media Application Format) output format
56
+ * Compatible with HLS and DASH streaming
57
+ */
58
+ export declare class CmafOutputFormat extends OutputFormat {
59
+ constructor(options?: Omit<FragmentedMp4Options, 'cmaf'>);
60
+ get name(): string;
61
+ get mimeType(): string;
62
+ get extension(): string;
63
+ createMuxer(target: Target): Muxer;
64
+ }
65
+ export { Mp4Demuxer } from './demuxer';
66
+ export { Mp4Muxer, type Mp4MuxerOptions } from './muxer';
67
+ export { FragmentedMp4Muxer, type FragmentedMp4Options } from './fragmented';
68
+ export * from './boxes';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{a as q,b as r,c as s,d as t,e as u,f as v,g as w,h as x,i as y,j as z,k as A,l as B}from"./chunk-zmpvp966.js";import{m as n}from"./chunk-wmd2bsvz.js";import{n as o}from"./chunk-51x739sq.js";import{o as p}from"./chunk-vetfxydj.js";import{A as l,B as m,p as a,q as b,r as c,s as d,t as e,u as f,v as g,w as h,x as i,y as j,z as k}from"./chunk-63shg4s1.js";export{d as writeFourCC,c as readFourCC,k as parseLanguageCode,h as isVideoHandler,j as isSubtitleHandler,i as isAudioHandler,l as encodeLanguageCode,m as TIMESCALE_1904_TO_1970,s as Mp4OutputFormat,n as Mp4Muxer,q as Mp4InputFormat,o as Mp4Demuxer,t as MovOutputFormat,r as MovInputFormat,y as MP4_OUTPUT,f as MP4_BRANDS,w as MP4,z as MOV_OUTPUT,g as MOV_BRANDS,x as MOV,u as FragmentedMp4OutputFormat,p as FragmentedMp4Muxer,A as FMP4_OUTPUT,b as EXTENDED_BOX_HEADER_SIZE,v as CmafOutputFormat,e as CONTAINER_BOXES,B as CMAF_OUTPUT,a as BOX_HEADER_SIZE};
@@ -0,0 +1,26 @@
1
+ import { Muxer } from 'ts-videos/muxer';
2
+ import type { EncodedPacket } from 'ts-videos/types';
3
+ import type { OutputVideoTrack, OutputAudioTrack, OutputSubtitleTrack } from 'ts-videos/muxer';
4
+ import type { Target } from 'ts-videos/writer';
5
+ export declare interface Mp4MuxerOptions {
6
+ fastStart?: boolean
7
+ fragmented?: boolean
8
+ brand?: string
9
+ }
10
+ export declare interface Mp4Chapter {
11
+ title: string
12
+ startTimeMs: number
13
+ }
14
+ export declare class Mp4Muxer extends Muxer {
15
+ constructor(target: Target, options?: Mp4MuxerOptions);
16
+ addChapter(title: string, startTimeMs: number): void;
17
+ setArtwork(data: Uint8Array, type?: 'jpeg' | 'png'): void;
18
+ get formatName(): string;
19
+ get mimeType(): string;
20
+ protected onTrackAdded(track: OutputVideoTrack | OutputAudioTrack | OutputSubtitleTrack): void;
21
+ protected writeHeader(): Promise<void>;
22
+ protected writeVideoPacket(track: OutputVideoTrack, packet: EncodedPacket): Promise<void>;
23
+ protected writeAudioPacket(track: OutputAudioTrack, packet: EncodedPacket): Promise<void>;
24
+ protected writeSubtitlePacket(track: OutputSubtitleTrack, packet: EncodedPacket): Promise<void>;
25
+ protected writeTrailer(): Promise<void>;
26
+ }
package/dist/muxer.js ADDED
@@ -0,0 +1 @@
1
+ import{m as a}from"./chunk-wmd2bsvz.js";import"./chunk-63shg4s1.js";export{a as Mp4Muxer};
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+ import{b as o}from"./chunk-zmpvp966.js";import{m as a}from"./chunk-wmd2bsvz.js";import"./chunk-51x739sq.js";import"./chunk-vetfxydj.js";import"./chunk-63shg4s1.js";import{describe as n,expect as c,test as m}from"bun:test";import{BufferTarget as s,Input as p}from"ts-videos";n("ProRes sample entries",()=>{m("round-trips the 4444 XQ profile through MOV metadata",async()=>{let r=new s,t=new a(r,{brand:"qt "}),i=t.addVideoTrack({codec:"prores",profile:"4444-xq",width:1920,height:1080,frameRate:24});await t.writePacket(i.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 p(r.buffer);e.setFormats([new o]),c(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.0",
4
+ "version": "0.1.1",
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.0"
60
+ "ts-videos": "0.1.1"
61
61
  }
62
62
  }