Fix incorrect video depth being written in ISOBMFF for video tracks with an alpha channel (fixes #450)

This commit is contained in:
Vanilagy
2026-07-30 17:45:33 +02:00
parent c3df2a24e5
commit d5362e20ad
3 changed files with 19 additions and 10 deletions
+8 -8
View File
@@ -25,7 +25,7 @@
chunked: true,
chunkSize: 2**20
});
const outputFormat = new Mediabunny.Mp4OutputFormat();
const outputFormat = new Mediabunny.MovOutputFormat();
const p = document.createElement('p');
p.textContent = 'Capturing...';
@@ -129,11 +129,11 @@
},
*/
video: {
codec: 'avc',
bitrate: new Mediabunny.Quality({
quality: Infinity,
}),
forceTranscode: true,
//codec: 'avc',
//bitrate: new Mediabunny.Quality({
// quality: Infinity,
//}),
//forceTranscode: true,
//process: (sample) => {
// sample.draw(ctx, 0, 0, 1280, 720);
// return new Mediabunny.VideoSample(canvas, { timestamp: sample.timestamp, duration: sample.duration });
@@ -157,7 +157,7 @@
}
},
trim: {
end: 20,
end: 0.5,
//start: -2,
//end: 10,
//start: 300.14984567374756 - 100,
@@ -197,7 +197,7 @@
document.body.append(video);
video.play();
//download(new Blob([target.buffer]), 'converted' + outputFormat.fileExtension);
download(new Blob([target.buffer]), 'converted' + outputFormat.fileExtension);
function download(blob, filename) {
const url = URL.createObjectURL(blob);
+6 -2
View File
@@ -718,8 +718,12 @@ export const videoSampleDescription = (
u32(0x00480000), // Vertical resolution
u32(0), // Reserved
u16(1), // Frame count
Array(32).fill(0), // Compressor name
u16(0x0018), // Depth
// Compressor name
ascii('Mediabunny'),
Array(32 - 'Mediabunny'.length).fill(0),
u16(trackData.info.hasAlphaChannel ? 32 : 24), // Depth
i16(0xffff), // Pre-defined
], [
VIDEO_CODEC_TO_CONFIGURATION_BOX[trackData.track.source._codec]?.(trackData) ?? null,
+5
View File
@@ -108,6 +108,7 @@ export type IsobmffTrackData = {
* https://stackoverflow.com/questions/24884827
*/
requiresAnnexBTransformation: boolean;
hasAlphaChannel: boolean;
};
} | {
track: OutputAudioTrack;
@@ -413,6 +414,9 @@ export class IsobmffMuxer extends Muxer {
den: displayAspectHeight * decoderConfig.codedWidth,
});
// Kicks for ProRes 4444.
const hasAlphaChannel = decoderConfig.codec === 'ap4h' || decoderConfig.codec === 'ap4x';
const newTrackData: IsobmffVideoTrackData = {
muxer: this,
track,
@@ -423,6 +427,7 @@ export class IsobmffMuxer extends Muxer {
pixelAspectRatio,
decoderConfig: decoderConfig,
requiresAnnexBTransformation,
hasAlphaChannel,
},
timescale,
samples: [],