Add xingHeader option to Mp3OutputFormat

This commit is contained in:
Vanilagy
2025-08-10 16:04:18 +02:00
parent 230f02fffc
commit 5608f519a7
3 changed files with 23 additions and 3 deletions
+7 -2
View File
@@ -50,7 +50,9 @@ export class Mp3Muxer extends Muxer {
const release = await this.mutex.acquire();
try {
if (!this.xingFrameData) {
const writeXingHeader = this.format._options.xingHeader !== false;
if (!this.xingFrameData && writeXingHeader) {
const view = toDataView(packet.data);
if (view.byteLength < 4) {
throw new Error('Invalid MP3 header in sample.');
@@ -97,11 +99,14 @@ export class Mp3Muxer extends Muxer {
this.validateAndNormalizeTimestamp(track, packet.timestamp, packet.type === 'key');
this.framePositions.push(this.writer.getPos());
this.writer.write(packet.data);
this.frameCount++;
await this.writer.flush();
if (writeXingHeader) {
this.framePositions.push(this.writer.getPos());
}
} finally {
release();
}