Fix: Premultiply alpha for WebM VP9 export to prevent black halos
This commit is contained in:
1 parent
5e1be54798
commit
c759eda534
1 file changed
+22
@@ -1820,6 +1820,20 @@
|
||||
return getTopBottomCanvasTb;
|
||||
}
|
||||
|
||||
function preMultiplyAlpha(ctx, width, height) {
|
||||
const imgData = ctx.getImageData(0, 0, width, height);
|
||||
const d = imgData.data;
|
||||
for (let i = 0; i < d.length; i += 4) {
|
||||
const a = d[i + 3];
|
||||
if (a === 255) continue;
|
||||
if (a === 0) { d[i] = d[i+1] = d[i+2] = 0; continue; }
|
||||
d[i] = (d[i] * a + 127) >> 8;
|
||||
d[i + 1] = (d[i + 1] * a + 127) >> 8;
|
||||
d[i + 2] = (d[i + 2] * a + 127) >> 8;
|
||||
}
|
||||
ctx.putImageData(imgData, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hardware-Accelerated In-Browser Video Export Engine (WebCodecs + Muxer)
|
||||
* Supports: WebM VP9 Alpha & MP4 H.264 with robust codec probing & lossless audio
|
||||
@@ -2083,6 +2097,14 @@
|
||||
finalFrameCanvas = getTopBottomCanvas(renderCanvas);
|
||||
}
|
||||
|
||||
if (supportsAlpha && !isTopBottom) {
|
||||
preMultiplyAlpha(
|
||||
finalFrameCanvas.getContext('2d'),
|
||||
finalFrameCanvas.width,
|
||||
finalFrameCanvas.height
|
||||
);
|
||||
}
|
||||
|
||||
// Create VideoFrame for WebCodecs
|
||||
const timestampUs = Math.round((f / fps) * 1_000_000);
|
||||
const durationUs = Math.round((1 / fps) * 1_000_000);
|
||||
|
||||
Reference in new issue
Block a user