Skip to content

Commit

Permalink
feat(*): support transparent webm
Browse files Browse the repository at this point in the history
  • Loading branch information
stepancar committed Jul 14, 2024
1 parent 1469ba8 commit 5ee9d39
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
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,
stream_index: streamIndex,
});
};

Expand Down
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.only('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.

0 comments on commit 5ee9d39

Please sign in to comment.