diff --git a/src/ProcessorPipeline.ts b/src/ProcessorPipeline.ts index e8d2ddd..62fd046 100644 --- a/src/ProcessorPipeline.ts +++ b/src/ProcessorPipeline.ts @@ -46,8 +46,8 @@ export default class ProcessorPipeline implements TrackProcessor { this.sourceSettings = this.source.getSettings(); this.sourceDummy = opts.element; if (this.sourceDummy instanceof HTMLVideoElement) { - this.sourceDummy.height = this.sourceSettings.height!; - this.sourceDummy.width = this.sourceSettings.width!; + this.sourceDummy.height = this.sourceSettings.height ?? 300; + this.sourceDummy.width = this.sourceSettings.width ?? 300; } if (!(this.sourceDummy instanceof HTMLVideoElement)) { throw TypeError('Currently only video transformers are supported'); diff --git a/src/index.ts b/src/index.ts index 5bc23c5..b7a7ea8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,8 @@ import ProcessorPipeline from './ProcessorPipeline'; import BackgroundTransformer, { SegmenterBaseOptions } from './transformers/BackgroundTransformer'; import DummyTransformer from './transformers/DummyTransformer'; +export * from './transformers/types'; + export const BackgroundBlur = ( blurRadius: number = 10, segmenterOptions?: SegmenterBaseOptions, diff --git a/src/transformers/BackgroundTransformer.ts b/src/transformers/BackgroundTransformer.ts index bec2648..b81a75d 100644 --- a/src/transformers/BackgroundTransformer.ts +++ b/src/transformers/BackgroundTransformer.ts @@ -118,10 +118,10 @@ export default class BackgroundProcessor extends VideoTransformer { this.ctx.globalCompositeOperation = 'copy'; const bitmap = await maskToBitmap( this.segmentationResults.categoryMask, - this.inputVideo.videoWidth, - this.inputVideo.videoHeight, + this.segmentationResults.categoryMask.width, + this.segmentationResults.categoryMask.height, ); - this.ctx.drawImage(bitmap, 0, 0); + this.ctx.drawImage(bitmap, 0, 0, this.canvas.width, this.canvas.height); this.ctx.filter = 'none'; this.ctx.globalCompositeOperation = 'source-in'; if (this.backgroundImage) { @@ -162,19 +162,19 @@ export default class BackgroundProcessor extends VideoTransformer { const bitmap = await maskToBitmap( this.segmentationResults.categoryMask, - this.inputVideo.videoWidth, - this.inputVideo.videoHeight, + this.segmentationResults.categoryMask.width, + this.segmentationResults.categoryMask.height, ); this.ctx.filter = 'blur(3px)'; this.ctx.globalCompositeOperation = 'copy'; - this.ctx.drawImage(bitmap, 0, 0); + this.ctx.drawImage(bitmap, 0, 0, this.canvas.width, this.canvas.height); this.ctx.filter = 'none'; this.ctx.globalCompositeOperation = 'source-out'; this.ctx.drawImage(frame, 0, 0, this.canvas.width, this.canvas.height); this.ctx.globalCompositeOperation = 'destination-over'; this.ctx.filter = `blur(${this.blurRadius}px)`; - this.ctx.drawImage(frame, 0, 0); + this.ctx.drawImage(frame, 0, 0, this.canvas.width, this.canvas.height); this.ctx.restore(); } }