Skip to content

Commit

Permalink
Adding fabricImagePostProcessing callback
Browse files Browse the repository at this point in the history
In videoFrameSource.js
  • Loading branch information
Ivanca committed Feb 4, 2023
1 parent 4f9f7c4 commit e56904a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ declare namespace Editly {

}

interface VideoPostProcessingFunctionArgs {
canvas: Fabric.Canvas;
image: Fabric.Image;
progress: number;
}

/**
* For video layers, if parent `clip.duration` is specified, the video will be slowed/sped-up to match `clip.duration`.
* If `cutFrom`/`cutTo` is set, the resulting segment (`cutTo`-`cutFrom`) will be slowed/sped-up to fit `clip.duration`.
Expand Down Expand Up @@ -372,6 +378,10 @@ declare namespace Editly {
*/
mixVolume?: number | string;

/**
* Post-processing function after calling rgbaToFabricImage but before adding it to StaticCanvas.
*/
fabricImagePostProcessing?: (data: VideoPostProcessingFunctionArgs) => Promise<void>;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion sources/videoFrameSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from './fabric.js';

export default async ({ width: canvasWidth, height: canvasHeight, channels, framerateStr, verbose, logTimes, ffmpegPath, ffprobePath, enableFfmpegLog, params }) => {
const { path, cutFrom, cutTo, resizeMode = 'contain-blur', speedFactor, inputWidth, inputHeight, width: requestedWidthRel, height: requestedHeightRel, left: leftRel = 0, top: topRel = 0, originX = 'left', originY = 'top' } = params;
const { path, cutFrom, cutTo, resizeMode = 'contain-blur', speedFactor, inputWidth, inputHeight, width: requestedWidthRel, height: requestedHeightRel, left: leftRel = 0, top: topRel = 0, originX = 'left', originY = 'top', fabricImagePostProcessing = null } = params;

const requestedWidth = requestedWidthRel ? Math.round(requestedWidthRel * canvasWidth) : canvasWidth;
const requestedHeight = requestedHeightRel ? Math.round(requestedHeightRel * canvasHeight) : canvasHeight;
Expand Down Expand Up @@ -227,6 +227,10 @@ export default async ({ width: canvasWidth, height: canvasHeight, channels, fram
canvas.add(blurredImg);
}

if (fabricImagePostProcessing) {
fabricImagePostProcessing({ image: img, progress, canvas });
}

canvas.add(img);
}

Expand Down

0 comments on commit e56904a

Please sign in to comment.