@meframe/core 0.0.16 → 0.0.18
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/dist/cache/CacheManager.d.ts +1 -1
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.js +2 -2
- package/dist/cache/CacheManager.js.map +1 -1
- package/dist/cache/l1/AudioL1Cache.d.ts +1 -1
- package/dist/cache/l1/AudioL1Cache.d.ts.map +1 -1
- package/dist/cache/l1/AudioL1Cache.js +3 -2
- package/dist/cache/l1/AudioL1Cache.js.map +1 -1
- package/dist/controllers/PlaybackController.d.ts +1 -1
- package/dist/controllers/PlaybackController.d.ts.map +1 -1
- package/dist/controllers/PlaybackController.js +1 -3
- package/dist/controllers/PlaybackController.js.map +1 -1
- package/dist/model/CompositionModel.d.ts +1 -1
- package/dist/model/CompositionModel.d.ts.map +1 -1
- package/dist/model/CompositionModel.js +19 -6
- package/dist/model/CompositionModel.js.map +1 -1
- package/dist/model/patch.js +3 -1
- package/dist/model/patch.js.map +1 -1
- package/dist/model/types.d.ts +9 -0
- package/dist/model/types.d.ts.map +1 -1
- package/dist/model/types.js +4 -0
- package/dist/model/types.js.map +1 -1
- package/dist/orchestrator/CompositionPlanner.d.ts.map +1 -1
- package/dist/orchestrator/CompositionPlanner.js +2 -1
- package/dist/orchestrator/CompositionPlanner.js.map +1 -1
- package/dist/{stages/compose → orchestrator}/GlobalAudioSession.d.ts +13 -7
- package/dist/orchestrator/GlobalAudioSession.d.ts.map +1 -0
- package/dist/{stages/compose → orchestrator}/GlobalAudioSession.js +117 -24
- package/dist/orchestrator/GlobalAudioSession.js.map +1 -0
- package/dist/orchestrator/Orchestrator.d.ts +2 -8
- package/dist/orchestrator/Orchestrator.d.ts.map +1 -1
- package/dist/orchestrator/Orchestrator.js +30 -10
- package/dist/orchestrator/Orchestrator.js.map +1 -1
- package/dist/orchestrator/VideoClipSession.d.ts +7 -0
- package/dist/orchestrator/VideoClipSession.d.ts.map +1 -1
- package/dist/orchestrator/VideoClipSession.js +69 -5
- package/dist/orchestrator/VideoClipSession.js.map +1 -1
- package/dist/stages/compose/OfflineAudioMixer.d.ts.map +1 -1
- package/dist/stages/compose/OfflineAudioMixer.js +21 -6
- package/dist/stages/compose/OfflineAudioMixer.js.map +1 -1
- package/dist/stages/decode/AudioChunkDecoder.d.ts +8 -1
- package/dist/stages/decode/AudioChunkDecoder.d.ts.map +1 -1
- package/dist/stages/decode/AudioChunkDecoder.js +169 -0
- package/dist/stages/decode/AudioChunkDecoder.js.map +1 -0
- package/dist/stages/demux/MP4Demuxer.d.ts +10 -4
- package/dist/stages/demux/MP4Demuxer.d.ts.map +1 -1
- package/dist/stages/demux/types.d.ts +6 -0
- package/dist/stages/demux/types.d.ts.map +1 -1
- package/dist/stages/mux/MuxManager.d.ts +1 -1
- package/dist/stages/mux/MuxManager.d.ts.map +1 -1
- package/dist/stages/mux/MuxManager.js.map +1 -1
- package/dist/workers/MP4Demuxer.js +65 -29
- package/dist/workers/MP4Demuxer.js.map +1 -1
- package/dist/workers/stages/decode/audio-decode.worker.js +101 -7
- package/dist/workers/stages/decode/audio-decode.worker.js.map +1 -1
- package/dist/workers/stages/demux/video-demux.worker.js +110 -39
- package/dist/workers/stages/demux/video-demux.worker.js.map +1 -1
- package/package.json +1 -1
- package/dist/stages/compose/GlobalAudioSession.d.ts.map +0 -1
- package/dist/stages/compose/GlobalAudioSession.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MP4Demuxer.d.ts","sourceRoot":"","sources":["../../../src/stages/demux/MP4Demuxer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEtD;;;GAGG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,UAAU,CAAM;IACxB,MAAM,yBAAgC;IACtC,OAAO,UAAS;IAChB,OAAO,CAAC,eAAe,CAAC,
|
|
1
|
+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export interface DemuxConfig {
|
|
|
2
2
|
codec?: string;
|
|
3
3
|
trackId?: string;
|
|
4
4
|
container?: 'mp4' | 'webm';
|
|
5
|
+
/**
|
|
6
|
+
* When true, the demux worker will emit the audio stream directly to the main thread
|
|
7
|
+
* via the worker channel, even if there is no audio downstream port connected.
|
|
8
|
+
* This is used for L2 audio caching without spinning up an AudioDecode worker.
|
|
9
|
+
*/
|
|
10
|
+
emitAudioToMain?: boolean;
|
|
5
11
|
highWaterMark?: number;
|
|
6
12
|
streaming?: {
|
|
7
13
|
batchSize?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/stages/demux/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/stages/demux/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAC3B;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAG1B,aAAa,CAAC,EAAE,MAAM,CAAC;IAGvB,SAAS,CAAC,EAAE;QAEV,SAAS,CAAC,EAAE,MAAM,CAAC;QAEnB,aAAa,CAAC,EAAE,MAAM,CAAC;QAEvB,YAAY,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;QAEjC,WAAW,CAAC,EAAE,OAAO,CAAC;QAEtB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;IAGF,WAAW,CAAC,EAAE;QAEZ,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAE3B,SAAS,CAAC,EA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CAAC,IAAI,CAAC,CAAC;IAC9C,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IACxC,KAAK,IAAI,IAAI,CAAC;IACd,KAAK,IAAI,IAAI,CAAC;IACd,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,EAAE,IAAI,CAAC;IACd,QAAQ,EAAE,IAAI,CAAC;IACf,MAAM,EAAE,SAAS,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,CAAC;CACxC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CompositionModel } from '../../model/CompositionModel';
|
|
2
2
|
import { ExportOptions } from '../../types';
|
|
3
|
-
import { GlobalAudioSession } from '
|
|
3
|
+
import { GlobalAudioSession } from '../../orchestrator/GlobalAudioSession';
|
|
4
4
|
import { CacheManager } from '../../cache/CacheManager';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MuxManager.d.ts","sourceRoot":"","sources":["../../../src/stages/mux/MuxManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"MuxManager.d.ts","sourceRoot":"","sources":["../../../src/stages/mux/MuxManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAE3E,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD;;;GAGG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,kBAAkB,CAAqB;IAC/C,OAAO,CAAC,kBAAkB,CAAkD;IAC5E,OAAO,CAAC,eAAe,CAAkC;gBAGvD,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,kBAAkB,EAChC,kBAAkB,EAAE,kBAAkB;IAOlC,MAAM,CAAC,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IA+C5E;;;OAGG;YACW,iBAAiB;YAoCjB,gBAAgB;YAkDhB,gBAAgB;YAwDhB,eAAe;CAkB9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MuxManager.js","sources":["../../../src/stages/mux/MuxManager.ts"],"sourcesContent":["import type { CompositionModel } from '../../model/CompositionModel';\nimport type { ExportOptions } from '../../types';\nimport { GlobalAudioSession } from '../compose/GlobalAudioSession';\nimport { MP4Muxer } from './MP4Muxer';\nimport { CacheManager } from '@/cache/CacheManager';\n\n/**\n * MuxManager: Main thread muxing service\n * Reads encoded chunks from L2 cache and muxes into final video file\n */\nexport class MuxManager {\n private cacheManager: CacheManager;\n private audioSession: GlobalAudioSession;\n private audioEncoderConfig: AudioEncoderConfig;\n private audioEncodedStream: ReadableStream<EncodedAudioChunk> | null = null;\n private audioFirstChunk: EncodedAudioChunk | null = null;\n\n constructor(\n cacheManager: CacheManager,\n audioSession: GlobalAudioSession,\n audioEncoderConfig: AudioEncoderConfig\n ) {\n this.cacheManager = cacheManager;\n this.audioSession = audioSession;\n this.audioEncoderConfig = audioEncoderConfig;\n }\n\n async export(model: CompositionModel, options: ExportOptions): Promise<Blob> {\n const videoTrack = model.tracks.find((t) => t.kind === 'video');\n if (!videoTrack || videoTrack.clips.length === 0) {\n throw new Error('No video clips in composition');\n }\n\n const sortedClips = [...videoTrack.clips].sort((a, b) => a.startUs - b.startUs);\n await this.checkL2Coverage(sortedClips);\n\n const width = options.width || (model as any).renderConfig?.width || 720;\n const height = options.height || (model as any).renderConfig?.height || 1280;\n const fps = options.fps || model.fps || 30;\n\n // Get video metadata from L2 cache (first clip)\n const videoChunkMeta = sortedClips[0]\n ? await this.cacheManager.getL2Metadata(sortedClips[0].id, 'video')\n : null;\n\n if (!videoChunkMeta) {\n console.warn('[MuxManager] No videoChunkMeta available, export may fail');\n }\n\n const audioTrack = model.tracks.find((t) => t.kind === 'audio');\n\n // Get audio metadata from first chunk if audio exists\n let audioChunkMeta: any = undefined;\n if (audioTrack?.clips.length) {\n audioChunkMeta = await this.getAudioChunkMeta();\n }\n\n const muxer = new MP4Muxer({\n width,\n height,\n fps,\n fastStart: 'in-memory',\n videoChunkMeta,\n audioChunkMeta,\n });\n\n await this.writeVideoChunks(muxer, sortedClips);\n if (audioTrack?.clips.length) {\n await this.writeAudioChunks(muxer);\n }\n\n return muxer.finalize();\n }\n\n /**\n * Get audio chunk metadata by reading first chunk from encoder\n * Caches the stream and first chunk for later use\n */\n private async getAudioChunkMeta(): Promise<any> {\n const audioEncoderConfig = this.audioEncoderConfig;\n let metadata: any = null;\n\n this.audioEncodedStream = await this.audioSession.createExportEncodedStream(\n audioEncoderConfig,\n (meta) => {\n // Extract decoderConfig from first chunk metadata\n if (meta.decoderConfig) {\n metadata = meta.decoderConfig;\n }\n }\n );\n\n if (!this.audioEncodedStream) {\n return null;\n }\n\n // Read first chunk to trigger metadata extraction and cache it\n const reader = this.audioEncodedStream.getReader();\n try {\n const { done, value } = await reader.read();\n if (!done && value) {\n this.audioFirstChunk = value;\n }\n reader.releaseLock();\n } catch (error) {\n console.error('[MuxManager] Failed to read first audio chunk:', error);\n reader.releaseLock();\n this.audioEncodedStream = null;\n return null;\n }\n\n return metadata;\n }\n\n private async writeVideoChunks(muxer: MP4Muxer, sortedClips: any[]): Promise<void> {\n let firstKeyframeWritten = false;\n let exportTimeUs = 0;\n\n for (const clip of sortedClips) {\n const stream = await this.cacheManager.createL2ReadStream(clip.id, 'video');\n if (!stream) {\n console.warn(`[MuxManager] No video stream for clip ${clip.id}`);\n continue;\n }\n\n const reader = stream.getReader();\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n const originalChunk = value as EncodedVideoChunk;\n\n // Copy chunk data\n const buffer = new ArrayBuffer(originalChunk.byteLength);\n originalChunk.copyTo(buffer);\n\n // Rewrite timestamp to export timeline (tight concatenation)\n const remappedChunk = new EncodedVideoChunk({\n type: originalChunk.type,\n timestamp: exportTimeUs,\n duration: originalChunk.duration ?? undefined,\n data: buffer,\n });\n\n // Ensure first chunk in export is a keyframe\n if (!firstKeyframeWritten) {\n if (remappedChunk.type !== 'key') {\n console.warn(`[MuxManager] Skipping non-keyframe at start of clip ${clip.id}`);\n exportTimeUs += originalChunk.duration || 0;\n continue;\n }\n firstKeyframeWritten = true;\n }\n\n muxer.writeVideoChunk(remappedChunk);\n exportTimeUs += originalChunk.duration || 0;\n }\n } finally {\n reader.releaseLock();\n }\n }\n }\n\n private async writeAudioChunks(muxer: MP4Muxer): Promise<void> {\n // Use cached stream from getAudioChunkMeta()\n if (!this.audioEncodedStream) {\n console.warn('[MuxManager] No audio stream available');\n return;\n }\n\n let exportTimeUs = 0;\n\n // Write the cached first chunk with remapped timestamp\n if (this.audioFirstChunk) {\n const buffer = new ArrayBuffer(this.audioFirstChunk.byteLength);\n this.audioFirstChunk.copyTo(buffer);\n\n const remappedChunk = new EncodedAudioChunk({\n type: this.audioFirstChunk.type,\n timestamp: exportTimeUs,\n duration: this.audioFirstChunk.duration ?? undefined,\n data: buffer,\n });\n muxer.writeAudioChunk(remappedChunk);\n exportTimeUs += this.audioFirstChunk.duration || 0;\n }\n\n // Continue reading remaining chunks\n const reader = this.audioEncodedStream.getReader();\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n const originalChunk = value as EncodedAudioChunk;\n\n // Copy chunk data\n const buffer = new ArrayBuffer(originalChunk.byteLength);\n originalChunk.copyTo(buffer);\n\n // Rewrite timestamp to export timeline\n const remappedChunk = new EncodedAudioChunk({\n type: originalChunk.type,\n timestamp: exportTimeUs,\n duration: originalChunk.duration ?? undefined,\n data: buffer,\n });\n\n muxer.writeAudioChunk(remappedChunk);\n exportTimeUs += originalChunk.duration || 0;\n }\n } finally {\n reader.releaseLock();\n // Clean up cached state\n this.audioEncodedStream = null;\n this.audioFirstChunk = null;\n }\n }\n\n private async checkL2Coverage(clips: any[]): Promise<void> {\n const missingClips: string[] = [];\n for (const clip of clips) {\n const inL2 = await this.cacheManager.hasClipInL2(clip.id, 'video');\n if (!inL2) {\n missingClips.push(clip.id);\n }\n }\n\n if (missingClips.length > 0) {\n const clipList = missingClips.slice(0, 3).join(', ');\n const moreText = missingClips.length > 3 ? ` and ${missingClips.length - 3} more` : '';\n throw new Error(\n `Export failed: ${missingClips.length} clip(s) not cached (${clipList}${moreText}). ` +\n `Please start PreRenderService and wait for background caching to complete.`\n );\n }\n }\n}\n"],"names":[],"mappings":";AAUO,MAAM,WAAW;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA,qBAA+D;AAAA,EAC/D,kBAA4C;AAAA,EAEpD,YACE,cACA,cACA,oBACA;AACA,SAAK,eAAe;AACpB,SAAK,eAAe;AACpB,SAAK,qBAAqB;AAAA,EAC5B;AAAA,EAEA,MAAM,OAAO,OAAyB,SAAuC;AAC3E,UAAM,aAAa,MAAM,OAAO,KAAK,CAAC,MAAM,EAAE,SAAS,OAAO;AAC9D,QAA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AI,CAAC,MAAM;AACT,qBAAa,KAAK,KAAK,EAAE;AAAA,MAC3B;AAAA,IACF;AAEA,QAAI,aAAa,SAAS,GAAG;AAC3B,YAAM,WAAW,aAAa,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI;AACnD,YAAM,WAAW,aAAa,SAAS,IAAI,QAAQ,aAAa,SAAS,CAAC,UAAU;AACpF,YAAM,IAAI;AAAA,QACR,kBAAkB,aAAa,MAAM,wBAAwB,QAAQ,GAAG,QAAQ;AAAA,MAAA;AAAA,IAGpF;AAAA,EACF;AACF;"}
|
|
1
|
+
{"version":3,"file":"MuxManager.js","sources":["../../../src/stages/mux/MuxManager.ts"],"sourcesContent":["import type { CompositionModel } from '../../model/CompositionModel';\nimport type { ExportOptions } from '../../types';\nimport { GlobalAudioSession } from '../../orchestrator/GlobalAudioSession';\nimport { MP4Muxer } from './MP4Muxer';\nimport { CacheManager } from '@/cache/CacheManager';\n\n/**\n * MuxManager: Main thread muxing service\n * Reads encoded chunks from L2 cache and muxes into final video file\n */\nexport class MuxManager {\n private cacheManager: CacheManager;\n private audioSession: GlobalAudioSession;\n private audioEncoderConfig: AudioEncoderConfig;\n private audioEncodedStream: ReadableStream<EncodedAudioChunk> | null = null;\n private audioFirstChunk: EncodedAudioChunk | null = null;\n\n constructor(\n cacheManager: CacheManager,\n audioSession: GlobalAudioSession,\n audioEncoderConfig: AudioEncoderConfig\n ) {\n this.cacheManager = cacheManager;\n this.audioSession = audioSession;\n this.audioEncoderConfig = audioEncoderConfig;\n }\n\n async export(model: CompositionModel, options: ExportOptions): Promise<Blob> {\n const videoTrack = model.tracks.find((t) => t.kind === 'video');\n if (!videoTrack || videoTrack.clips.length === 0) {\n throw new Error('No video clips in composition');\n }\n\n const sortedClips = [...videoTrack.clips].sort((a, b) => a.startUs - b.startUs);\n await this.checkL2Coverage(sortedClips);\n\n const width = options.width || (model as any).renderConfig?.width || 720;\n const height = options.height || (model as any).renderConfig?.height || 1280;\n const fps = options.fps || model.fps || 30;\n\n // Get video metadata from L2 cache (first clip)\n const videoChunkMeta = sortedClips[0]\n ? await this.cacheManager.getL2Metadata(sortedClips[0].id, 'video')\n : null;\n\n if (!videoChunkMeta) {\n console.warn('[MuxManager] No videoChunkMeta available, export may fail');\n }\n\n const audioTrack = model.tracks.find((t) => t.kind === 'audio');\n\n // Get audio metadata from first chunk if audio exists\n let audioChunkMeta: any = undefined;\n if (audioTrack?.clips.length) {\n audioChunkMeta = await this.getAudioChunkMeta();\n }\n\n const muxer = new MP4Muxer({\n width,\n height,\n fps,\n fastStart: 'in-memory',\n videoChunkMeta,\n audioChunkMeta,\n });\n\n await this.writeVideoChunks(muxer, sortedClips);\n if (audioTrack?.clips.length) {\n await this.writeAudioChunks(muxer);\n }\n\n return muxer.finalize();\n }\n\n /**\n * Get audio chunk metadata by reading first chunk from encoder\n * Caches the stream and first chunk for later use\n */\n private async getAudioChunkMeta(): Promise<any> {\n const audioEncoderConfig = this.audioEncoderConfig;\n let metadata: any = null;\n\n this.audioEncodedStream = await this.audioSession.createExportEncodedStream(\n audioEncoderConfig,\n (meta) => {\n // Extract decoderConfig from first chunk metadata\n if (meta.decoderConfig) {\n metadata = meta.decoderConfig;\n }\n }\n );\n\n if (!this.audioEncodedStream) {\n return null;\n }\n\n // Read first chunk to trigger metadata extraction and cache it\n const reader = this.audioEncodedStream.getReader();\n try {\n const { done, value } = await reader.read();\n if (!done && value) {\n this.audioFirstChunk = value;\n }\n reader.releaseLock();\n } catch (error) {\n console.error('[MuxManager] Failed to read first audio chunk:', error);\n reader.releaseLock();\n this.audioEncodedStream = null;\n return null;\n }\n\n return metadata;\n }\n\n private async writeVideoChunks(muxer: MP4Muxer, sortedClips: any[]): Promise<void> {\n let firstKeyframeWritten = false;\n let exportTimeUs = 0;\n\n for (const clip of sortedClips) {\n const stream = await this.cacheManager.createL2ReadStream(clip.id, 'video');\n if (!stream) {\n console.warn(`[MuxManager] No video stream for clip ${clip.id}`);\n continue;\n }\n\n const reader = stream.getReader();\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n const originalChunk = value as EncodedVideoChunk;\n\n // Copy chunk data\n const buffer = new ArrayBuffer(originalChunk.byteLength);\n originalChunk.copyTo(buffer);\n\n // Rewrite timestamp to export timeline (tight concatenation)\n const remappedChunk = new EncodedVideoChunk({\n type: originalChunk.type,\n timestamp: exportTimeUs,\n duration: originalChunk.duration ?? undefined,\n data: buffer,\n });\n\n // Ensure first chunk in export is a keyframe\n if (!firstKeyframeWritten) {\n if (remappedChunk.type !== 'key') {\n console.warn(`[MuxManager] Skipping non-keyframe at start of clip ${clip.id}`);\n exportTimeUs += originalChunk.duration || 0;\n continue;\n }\n firstKeyframeWritten = true;\n }\n\n muxer.writeVideoChunk(remappedChunk);\n exportTimeUs += originalChunk.duration || 0;\n }\n } finally {\n reader.releaseLock();\n }\n }\n }\n\n private async writeAudioChunks(muxer: MP4Muxer): Promise<void> {\n // Use cached stream from getAudioChunkMeta()\n if (!this.audioEncodedStream) {\n console.warn('[MuxManager] No audio stream available');\n return;\n }\n\n let exportTimeUs = 0;\n\n // Write the cached first chunk with remapped timestamp\n if (this.audioFirstChunk) {\n const buffer = new ArrayBuffer(this.audioFirstChunk.byteLength);\n this.audioFirstChunk.copyTo(buffer);\n\n const remappedChunk = new EncodedAudioChunk({\n type: this.audioFirstChunk.type,\n timestamp: exportTimeUs,\n duration: this.audioFirstChunk.duration ?? undefined,\n data: buffer,\n });\n muxer.writeAudioChunk(remappedChunk);\n exportTimeUs += this.audioFirstChunk.duration || 0;\n }\n\n // Continue reading remaining chunks\n const reader = this.audioEncodedStream.getReader();\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n const originalChunk = value as EncodedAudioChunk;\n\n // Copy chunk data\n const buffer = new ArrayBuffer(originalChunk.byteLength);\n originalChunk.copyTo(buffer);\n\n // Rewrite timestamp to export timeline\n const remappedChunk = new EncodedAudioChunk({\n type: originalChunk.type,\n timestamp: exportTimeUs,\n duration: originalChunk.duration ?? undefined,\n data: buffer,\n });\n\n muxer.writeAudioChunk(remappedChunk);\n exportTimeUs += originalChunk.duration || 0;\n }\n } finally {\n reader.releaseLock();\n // Clean up cached state\n this.audioEncodedStream = null;\n this.audioFirstChunk = null;\n }\n }\n\n private async checkL2Coverage(clips: any[]): Promise<void> {\n const missingClips: string[] = [];\n for (const clip of clips) {\n const inL2 = await this.cacheManager.hasClipInL2(clip.id, 'video');\n if (!inL2) {\n missingClips.push(clip.id);\n }\n }\n\n if (missingClips.length > 0) {\n const clipList = missingClips.slice(0, 3).join(', ');\n const moreText = missingClips.length > 3 ? ` and ${missingClips.length - 3} more` : '';\n throw new Error(\n `Export failed: ${missingClips.length} clip(s) not cached (${clipList}${moreText}). ` +\n `Please start PreRenderService and wait for background caching to complete.`\n );\n }\n }\n}\n"],"names":[],"mappings":";AAUO,MAAM,WAAW;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA,qBAA+D;AAAA,EAC/D,kBAA4C;AAAA,EAEpD,YACE,cACA,cACA,oBACA;AACA,SAAK,eAAe;AACpB,SAAK,eAAe;AACpB,SAAK,qBAAqB;AAAA,EAC5B;AAAA,EAEA,MAAM,OAAO,OAAyB,SAAuC;AAC3E,UAAM,aAAa,MAAM,OAAO,KAAK,CAAC,MAAM,EAAE,SAAS,OAAO;AAC9D,QAAI,CAAC,cAAc,WAAW,MAAM,WAAW,GAAG;AAChD,YAAM,IAAI,MAAM,+BAA+B;AAAA,IACjD;AAEA,UAAM,cAAc,CAAC,GAAG,WAAW,KAAK,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,OAAO;AAC9E,UAAM,KAAK,gBAAgB,WAAW;AAEtC,UAAM,QAAQ,QAAQ,SAAU,MAAc,cAAc,SAAS;AACrE,UAAM,SAAS,QAAQ,UAAW,MAAc,cAAc,UAAU;AACxE,UAAM,MAAM,QAAQ,OAAO,MAAM,OAAO;AAGxC,UAAM,iBAAiB,YAAY,CAAC,IAChC,MAA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
7054
|
fileOffset = 0;
|
|
7055
7055
|
videoTimestampOffset = null;
|
|
7056
7056
|
audioTimestampOffset = null;
|
|
7057
|
+
skipAudio = false;
|
|
7057
7058
|
constructor(config = {}) {
|
|
7058
7059
|
this.mp4boxFile = mp4box_all.createFile();
|
|
7059
7060
|
this.onReadyCallback = config.onReady;
|
|
7061
|
+
this.skipAudio = config.skipAudio ?? false;
|
|
7060
7062
|
const DEFAULT_HIGH_WATER_MARK = 10;
|
|
7061
7063
|
this.demuxHighWaterMark = config.highWaterMark ?? DEFAULT_HIGH_WATER_MARK;
|
|
7062
7064
|
this.setupHandlers();
|
|
@@ -7129,7 +7131,12 @@ class MP4Demuxer {
|
|
|
7129
7131
|
data: sample.data
|
|
7130
7132
|
});
|
|
7131
7133
|
this.videoController.enqueue(chunk);
|
|
7132
|
-
} else if (track.type === "audio"
|
|
7134
|
+
} else if (track.type === "audio") {
|
|
7135
|
+
if (!this.audioController) {
|
|
7136
|
+
const last2 = samples[samples.length - 1].number;
|
|
7137
|
+
this.mp4boxFile.releaseUsedSamples(trackId, last2 + 1);
|
|
7138
|
+
return;
|
|
7139
|
+
}
|
|
7133
7140
|
if (this.audioTimestampOffset === null) {
|
|
7134
7141
|
this.audioTimestampOffset = rawTimestamp;
|
|
7135
7142
|
}
|
|
@@ -7175,9 +7182,27 @@ class MP4Demuxer {
|
|
|
7175
7182
|
try {
|
|
7176
7183
|
const fullTrack = this.mp4boxFile.getTrackById(track.id);
|
|
7177
7184
|
for (const entry of fullTrack.mdia.minf.stbl.stsd.entries) {
|
|
7178
|
-
if (entry.esds
|
|
7179
|
-
const
|
|
7180
|
-
|
|
7185
|
+
if (entry.esds) {
|
|
7186
|
+
const decConfigDesc = entry.esds.esd?.descs?.[0];
|
|
7187
|
+
const decSpecInfo = decConfigDesc?.descs?.[0];
|
|
7188
|
+
if (decSpecInfo?.data) {
|
|
7189
|
+
const data = decSpecInfo.data;
|
|
7190
|
+
if (data instanceof Uint8Array) {
|
|
7191
|
+
const buffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
7192
|
+
return buffer instanceof ArrayBuffer ? buffer : void 0;
|
|
7193
|
+
} else if (Array.isArray(data)) {
|
|
7194
|
+
return new Uint8Array(data).buffer;
|
|
7195
|
+
}
|
|
7196
|
+
}
|
|
7197
|
+
console.warn("[MP4Demuxer] Could not extract AudioSpecificConfig from esds structure");
|
|
7198
|
+
return void 0;
|
|
7199
|
+
} else if (entry.dOps) {
|
|
7200
|
+
const stream = new mp4box_all.DataStream(
|
|
7201
|
+
void 0,
|
|
7202
|
+
0,
|
|
7203
|
+
mp4box_all.DataStream.BIG_ENDIAN
|
|
7204
|
+
);
|
|
7205
|
+
entry.dOps.write(stream);
|
|
7181
7206
|
return new Uint8Array(stream.buffer.slice(8)).buffer;
|
|
7182
7207
|
}
|
|
7183
7208
|
}
|
|
@@ -7187,56 +7212,67 @@ class MP4Demuxer {
|
|
|
7187
7212
|
return void 0;
|
|
7188
7213
|
}
|
|
7189
7214
|
/**
|
|
7190
|
-
* Create
|
|
7215
|
+
* Create readable stream for video chunks (output only)
|
|
7191
7216
|
*/
|
|
7192
7217
|
createVideoStream() {
|
|
7193
|
-
return new
|
|
7218
|
+
return new ReadableStream(
|
|
7194
7219
|
{
|
|
7195
|
-
start: (
|
|
7196
|
-
this.videoController =
|
|
7197
|
-
},
|
|
7198
|
-
transform: (chunk, _controller) => {
|
|
7199
|
-
const chunkData = new Uint8Array(chunk);
|
|
7200
|
-
this.appendBuffer(chunkData);
|
|
7201
|
-
this.mp4boxFile.flush();
|
|
7220
|
+
start: (ctrl) => {
|
|
7221
|
+
this.videoController = ctrl;
|
|
7202
7222
|
},
|
|
7203
|
-
|
|
7204
|
-
this.
|
|
7205
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
7223
|
+
cancel: () => {
|
|
7224
|
+
this.videoController = void 0;
|
|
7206
7225
|
}
|
|
7207
7226
|
},
|
|
7208
|
-
// Queuing strategy: use configuration
|
|
7209
7227
|
{
|
|
7210
7228
|
highWaterMark: this.demuxHighWaterMark,
|
|
7211
7229
|
size: () => 1
|
|
7212
|
-
// Count-based
|
|
7213
7230
|
}
|
|
7214
7231
|
);
|
|
7215
7232
|
}
|
|
7216
7233
|
/**
|
|
7217
|
-
* Create
|
|
7234
|
+
* Create readable stream for audio chunks (output only)
|
|
7218
7235
|
*/
|
|
7219
7236
|
createAudioStream() {
|
|
7220
|
-
|
|
7221
|
-
|
|
7222
|
-
|
|
7237
|
+
if (this.skipAudio) {
|
|
7238
|
+
return null;
|
|
7239
|
+
}
|
|
7240
|
+
return new ReadableStream(
|
|
7223
7241
|
{
|
|
7224
|
-
start: (
|
|
7225
|
-
this.audioController =
|
|
7242
|
+
start: (ctrl) => {
|
|
7243
|
+
this.audioController = ctrl;
|
|
7226
7244
|
},
|
|
7227
|
-
|
|
7245
|
+
cancel: () => {
|
|
7246
|
+
this.audioController = void 0;
|
|
7247
|
+
}
|
|
7248
|
+
},
|
|
7249
|
+
{
|
|
7250
|
+
highWaterMark: this.demuxHighWaterMark,
|
|
7251
|
+
size: () => 1
|
|
7252
|
+
}
|
|
7253
|
+
);
|
|
7254
|
+
}
|
|
7255
|
+
/**
|
|
7256
|
+
* Create writable stream for input data (single source)
|
|
7257
|
+
* This is the only stream that should receive the input data
|
|
7258
|
+
*/
|
|
7259
|
+
createInputStream() {
|
|
7260
|
+
return new WritableStream(
|
|
7261
|
+
{
|
|
7262
|
+
write: (chunk) => {
|
|
7228
7263
|
const chunkData = new Uint8Array(chunk);
|
|
7229
7264
|
this.appendBuffer(chunkData);
|
|
7230
7265
|
this.mp4boxFile.flush();
|
|
7231
7266
|
},
|
|
7232
|
-
|
|
7267
|
+
close: async () => {
|
|
7233
7268
|
this.mp4boxFile.flush();
|
|
7269
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
7270
|
+
this.videoController?.close();
|
|
7271
|
+
this.audioController?.close();
|
|
7234
7272
|
}
|
|
7235
7273
|
},
|
|
7236
|
-
// Queuing strategy: use configuration
|
|
7237
7274
|
{
|
|
7238
|
-
highWaterMark: this.demuxHighWaterMark
|
|
7239
|
-
size: () => 1
|
|
7275
|
+
highWaterMark: this.demuxHighWaterMark
|
|
7240
7276
|
}
|
|
7241
7277
|
);
|
|
7242
7278
|
}
|