Skip to content
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

feat(*): remove canvas dependency #50

Merged
merged 3 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/mini-framefusion-example/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default defineConfig({
'path',
'fs',
'@pixi/node',
'canvas',
'framefusion',
'child_process',
'rimraf',
Expand Down
2 changes: 1 addition & 1 deletion framefusion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ImageData } from 'canvas';
import type { ImageData } from './src/types';
import { BeamcoderExtractor } from './src/backends/beamcoder.js';

export type Frame = {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lumen5/framefusion",
"version": "0.0.26",
"version": "1.0.0",
"type": "module",
"scripts": {
"docs": "typedoc framefusion.ts",
Expand All @@ -20,7 +20,6 @@
},
"dependencies": {
"@antoinemopa/beamcoder": "^0.7.4",
"canvas": "^2.9.1",
"fs-extra": "^11.1.1",
"tmp": "^0.2.1"
},
Expand All @@ -36,6 +35,7 @@
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"@vitest/ui": "^0.29.8",
"canvas": "^2.9.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need canvas to run tests, I just moved it to devDeps

"eslint": "^8.38.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.27.5",
Expand Down
4 changes: 2 additions & 2 deletions src/BaseExtractor.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { ImageData } from 'canvas';

import type {
ExtractorArgs,
Frame,
Extractor
} from '../framefusion';
import type { ImageData } from './types';


export class BaseExtractor implements Extractor {
static async create(args: ExtractorArgs): Promise<Extractor> {
Expand Down
15 changes: 7 additions & 8 deletions src/backends/beamcoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import type {
Frame
} from '@antoinemopa/beamcoder';
import beamcoder from '@antoinemopa/beamcoder';
import type { ImageData } from 'canvas';
import { createImageData } from 'canvas';
import type { ImageData } from '../types';
import { BaseExtractor } from '../BaseExtractor';
import type { Extractor, ExtractorArgs, InterpolateMode } from '../../framefusion';
import { DownloadVideoURL } from '../DownloadVideoURL';
Expand Down Expand Up @@ -256,12 +255,12 @@ export class BeamcoderExtractor extends BaseExtractor implements Extractor {
return null;
}
const rawData = this._resizeFrameData(frame);
const image = createImageData(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will create this function in luminary instead

rawData,
frame.width,
frame.height
) as ImageData;
return image;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was nice to have ImageData type, but since it comes with complex build requirements, I think it makes sense to remove 😿


return {
data: rawData,
width: frame.width,
height: frame.height,
};
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type ImageData = {
data: Uint8ClampedArray;
width: number;
height: number;
};
5 changes: 3 additions & 2 deletions test/framefusion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
beforeAll
} from 'vitest';
import { toMatchImageSnapshot } from 'jest-image-snapshot';
import { createCanvas } from 'canvas';
import { createCanvas, createImageData } from 'canvas';
import httpServer from 'http-server';
import { BeamcoderExtractor } from '../src/backends/beamcoder';

Expand Down Expand Up @@ -389,9 +389,10 @@ describe('FrameFusion', () => {
if (!imageData) {
continue;
}
const canvasImageData = createImageData(imageData.data, imageData.width, imageData.height);
const canvas = createCanvas(imageData.width, imageData.height);
const ctx = canvas.getContext('2d');
ctx.putImageData(imageData, 0, 0);
ctx.putImageData(canvasImageData, 0, 0);
expect(canvas.toBuffer('image/png')).toMatchImageSnapshot();
}

Expand Down
Loading