-
-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Layer masking (AKA Clip) a video using canvas? #221
Comments
Hi. I think what youre asking for is «masking». Not sure if canvas can do that |
Yes it can, see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clip |
I created a PR #222 that adds a new (optional) callback so users can use it to modify the generated image (Fabric.Image) before being rendered; so stuff like masking like this ticket is about can be done using the fabric API with this bit of code: await editly({
outPath: './output.mp4',
clips: [{
duration: 4, layers: [
{ type: 'video', path: './assets/lofoten.mp4', cutFrom: 0, cutTo: 4 },
{
type: 'video',
path: './assets/hiking.mp4',
cutFrom: 0, cutTo: 4,
resizeMode: 'cover',
originX: 'center', originY: 'center',
left: 0.5, top: 0.5, width: 0.5, height: 0.5,
fabricImagePostProcessing: async ({image, progress, canvas})=> {
const circleArgs = {
radius: Math.min(image.width, image.height) * 0.4,
originX: 'center',
originY: 'center',
stroke: 'white',
strokeWidth: 22,
};
image.setOptions({
clipPath: new fabric.Circle(circleArgs)
});
canvas.add(new fabric.Circle({
...circleArgs,
left: image.getCenterPoint().x,
top: image.getCenterPoint().y
}));
}
}
]}
]
}); Example result: alpha.mp4 |
@mifi Any intention to merge this or a similar API in the near future? Thanks. |
I want to create a circle using canvas and clip a video so only it uses the canvas element as alpha channel, how can I do that with editly?
The equivalent in Photoshop (and similarly on other software) looks a like this:
![image](https://cdn.statically.io/img/user-images.githubusercontent.com/907138/213594251-44d0a2e2-a7ed-4db6-a20a-e2e0a01b3e45.png)
Thank you very much for this library.
The text was updated successfully, but these errors were encountered: