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(*): support transparent webm #56

Merged
merged 2 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 14 additions & 3 deletions src/backends/beamcoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,24 @@ const createDecoder = ({
streamIndex: number;
threadCount: number;
}): Decoder => {
return beamcoder.decoder({
demuxer: demuxer,
const commonParams = {
width: demuxer.streams[streamIndex].codecpar.width,
height: demuxer.streams[streamIndex].codecpar.height,
stream_index: streamIndex,
pix_fmt: demuxer.streams[streamIndex].codecpar.format,
thread_count: threadCount,
};

if (demuxer.streams[streamIndex].codecpar.name === 'vp8') {
return beamcoder.decoder({
...commonParams,
name: 'libvpx',
});
}

return beamcoder.decoder({
...commonParams,
demuxer: demuxer,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

codec info comes from demuxer. vp8 does not support alpha

stream_index: streamIndex,
});
};

Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions test/framefusion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,27 @@ describe('FrameFusion', () => {
await extractor.dispose();
});

it('can get frame from webm with alpha', async() => {
// Arrange
const extractor = await BeamcoderExtractor.create({
inputFileOrUrl: './test/samples/webm-with-alpha.webm',
threadCount: 8,
});

// Act and Assert
const imageData = await extractor.getImageDataAtTime(100);
const canvasImageData = createImageData(imageData.data, imageData.width, imageData.height);

const canvas = createCanvas(imageData.width, imageData.height);
const ctx = canvas.getContext('2d', { alpha: true });

ctx.putImageData(canvasImageData, 0, 0);
expect(canvas.toBuffer('image/png')).toMatchImageSnapshot();

// Cleanup
await extractor.dispose();
});

it('can get the same frame multiple times', async() => {
// When smaller increments are requested, the same frame can be returned multiple times. This happens when the
// caller plays the video at a lower playback rate than the source video.
Expand Down
Binary file added test/samples/webm-with-alpha.webm
Binary file not shown.
Loading