mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 19:03:46 +02:00
Fix ISOBMFF muxer track alternate groups (fixes #454), fixed mutex race condition in Output
This commit is contained in:
+7
-7
@@ -47,7 +47,7 @@
|
|||||||
format = new Mediabunny.MkvOutputFormat();
|
format = new Mediabunny.MkvOutputFormat();
|
||||||
format = new Mediabunny.MovOutputFormat();
|
format = new Mediabunny.MovOutputFormat();
|
||||||
format = new Mediabunny.Mp4OutputFormat({ fastStart: 'reserve' });
|
format = new Mediabunny.Mp4OutputFormat({ fastStart: 'reserve' });
|
||||||
format = new Mediabunny.WebMOutputFormat();
|
format = new Mediabunny.Mp4OutputFormat();
|
||||||
let target = new Mediabunny.BufferTarget();
|
let target = new Mediabunny.BufferTarget();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -118,21 +118,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
let videoSource = new Mediabunny.CanvasSource(canvas, {
|
let videoSource = new Mediabunny.CanvasSource(canvas, {
|
||||||
codec: 'vp9',
|
codec: 'avc',
|
||||||
//fullCodecString: 'avc1.42001f',
|
//fullCodecString: 'avc1.42001f',
|
||||||
bitrate: 1e6,
|
bitrate: 1e6,
|
||||||
alpha: 'keep',
|
alpha: 'keep',
|
||||||
onEncoderConfig: console.log,
|
onEncoderConfig: console.log,
|
||||||
});
|
});
|
||||||
let audioSource = new Mediabunny.AudioBufferSource({
|
let audioSource = new Mediabunny.AudioBufferSource({
|
||||||
codec: 'opus',
|
codec: 'aac',
|
||||||
bitrate: 128e3,
|
bitrate: 128e3,
|
||||||
});
|
});
|
||||||
let subtitleSource = new Mediabunny.TextSubtitleSource('webvtt');
|
let subtitleSource = new Mediabunny.TextSubtitleSource('webvtt');
|
||||||
|
|
||||||
output.addVideoTrack(videoSource, { languageCode: 'eng', name: 'Mononoké', maximumPacketCount: 100 });
|
output.addVideoTrack(videoSource, { languageCode: 'eng', name: 'Mononoké', maximumPacketCount: 100 });
|
||||||
output.addAudioTrack(audioSource, { name: 'Yooo', maximumPacketCount: 1000 });
|
output.addAudioTrack(audioSource, { name: 'Yooo', maximumPacketCount: 1000 });
|
||||||
//output.addSubtitleTrack(subtitleSource);
|
output.addSubtitleTrack(subtitleSource);
|
||||||
|
|
||||||
output.start();
|
output.start();
|
||||||
|
|
||||||
@@ -191,8 +191,8 @@ Testing... <00:17.350>One... <00:18.125>Two...
|
|||||||
9. <b>justify (bottom, right)</b>.
|
9. <b>justify (bottom, right)</b>.
|
||||||
`;
|
`;
|
||||||
|
|
||||||
//subtitleSource.add(simpleWebvttFile);
|
subtitleSource.add(simpleWebvttFile);
|
||||||
//subtitleSource.close();
|
subtitleSource.close();
|
||||||
|
|
||||||
const p = document.createElement('p');
|
const p = document.createElement('p');
|
||||||
document.body.append(p);
|
document.body.append(p);
|
||||||
@@ -216,5 +216,5 @@ Testing... <00:17.350>One... <00:18.125>Two...
|
|||||||
await output.finalize();
|
await output.finalize();
|
||||||
|
|
||||||
console.log(target);
|
console.log(target);
|
||||||
//download(new Blob([target.buffer]), 'test' + format.fileExtension);
|
download(new Blob([target.buffer]), 'test' + format.fileExtension);
|
||||||
</script>
|
</script>
|
||||||
@@ -493,6 +493,17 @@ export const tkhd = (
|
|||||||
flags |= 0x1; // Track enabled
|
flags |= 0x1; // Track enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the alternate group based on the track type; this mirror's how FFmpeg does it. A more advanced version would
|
||||||
|
// determine the alternate groups based on the actual track pairability graph. Note that it appears important that
|
||||||
|
// video get assigned to group 0, see https://github.com/Vanilagy/mediabunny/issues/454.
|
||||||
|
const alternateGroup = trackData.type === 'video'
|
||||||
|
? 0
|
||||||
|
: trackData.type === 'audio'
|
||||||
|
? 1
|
||||||
|
: trackData.type === 'subtitle'
|
||||||
|
? 2
|
||||||
|
: assertNever(trackData);
|
||||||
|
|
||||||
return fullBox('tkhd', +needsU64, flags, [
|
return fullBox('tkhd', +needsU64, flags, [
|
||||||
u32OrU64(creationTime), // Creation time
|
u32OrU64(creationTime), // Creation time
|
||||||
u32OrU64(creationTime), // Modification time
|
u32OrU64(creationTime), // Modification time
|
||||||
@@ -501,7 +512,7 @@ export const tkhd = (
|
|||||||
u32OrU64(durationInGlobalTimescale), // Duration
|
u32OrU64(durationInGlobalTimescale), // Duration
|
||||||
Array(8).fill(0), // Reserved
|
Array(8).fill(0), // Reserved
|
||||||
u16(0), // Layer
|
u16(0), // Layer
|
||||||
u16(trackData.track.id), // Alternate group
|
u16(alternateGroup), // Alternate group
|
||||||
fixed_8_8(trackData.type === 'audio' ? 1 : 0), // Volume
|
fixed_8_8(trackData.type === 'audio' ? 1 : 0), // Volume
|
||||||
u16(0), // Reserved
|
u16(0), // Reserved
|
||||||
matrixToBytes(matrix), // Matrix
|
matrixToBytes(matrix), // Matrix
|
||||||
|
|||||||
+3
-2
@@ -830,7 +830,8 @@ export class Output<
|
|||||||
return this._startPromise = (async () => {
|
return this._startPromise = (async () => {
|
||||||
this.state = 'started';
|
this.state = 'started';
|
||||||
|
|
||||||
const release = await this._mutex.acquire();
|
// We want to call muxer.start immediately, so we avoid using an await here
|
||||||
|
const releasePromise = this._mutex.acquire();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this._muxer.start();
|
await this._muxer.start();
|
||||||
@@ -838,7 +839,7 @@ export class Output<
|
|||||||
const promises = this.tracks.map(track => track.source._start());
|
const promises = this.tracks.map(track => track.source._start());
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
} finally {
|
} finally {
|
||||||
release();
|
(await releasePromise)();
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user