Add AppendOnlyStreamSource, adjust examples to use it

This commit is contained in:
Vanilagy
2026-04-21 14:58:33 +02:00
parent 2b3e5f45c6
commit 783cfa6fbe
17 changed files with 328 additions and 68 deletions
+8 -10
View File
@@ -176,7 +176,7 @@ export class IsobmffMuxer extends Muxer {
isCmaf: boolean;
private auxTarget = new BufferTarget();
private auxWriter = new Writer(this.auxTarget);
private auxWriter = new Writer(this.auxTarget, false);
private auxBoxWriter = new IsobmffBoxWriter(this.auxWriter);
private mdat: Box | null = null;
@@ -210,7 +210,11 @@ export class IsobmffMuxer extends Muxer {
const release = await this.mutex.acquire();
if (!this.isCmaf) {
this.writer = await this.output._getRootWriter();
this.writer = await this.output._getRootWriter(target => (
this.format._options.fastStart !== undefined
? this.format._options.fastStart === 'fragmented'
: target instanceof BufferTarget // Since if this is the case we'll use 'in-memory'
));
this.boxWriter = new IsobmffBoxWriter(this.writer);
// If the fastStart option isn't defined, enable in-memory fast start if the target is an ArrayBuffer, as
@@ -223,10 +227,6 @@ export class IsobmffMuxer extends Muxer {
this.isFragmented = true;
}
if (this.fastStart === 'in-memory' || this.isFragmented) {
this.writer?.ensureMonotonicity();
}
if (this.isCmaf) {
if (!this.output._hasInitTarget()) {
throw new Error(
@@ -237,7 +237,7 @@ export class IsobmffMuxer extends Muxer {
// Set up the init writer to which we'll write the init segment
const initTarget = await this.output._getInitTarget();
const initWriter = new Writer(initTarget);
const initWriter = new Writer(initTarget, true);
initWriter.start();
this.initWriter = initWriter;
@@ -1165,11 +1165,9 @@ export class IsobmffMuxer extends Muxer {
// Only now, init the main writer; this way the init writer is fully done before the main writer is
// even acquired
this.writer = await this.output._getRootWriter();
this.writer = await this.output._getRootWriter(true);
this.boxWriter = new IsobmffBoxWriter(this.writer);
this.writer.ensureMonotonicity();
const stypSize = this.boxWriter.measureBox(styp());
const sidxSize = this.boxWriter.measureBox(sidx(this, 0));
this.segmentHeaderSize = stypSize + sidxSize;