Skip to content

Commit

Permalink
Use VideoFrame constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
beaufortfrancois committed Apr 18, 2023
1 parent 99123cf commit 2fba909
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions src/sample/videoUploadingWebCodecs/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,35 +61,11 @@ const init: SampleInit = async ({ canvas, pageState }) => {
minFilter: 'linear',
});

function getVideoFrameFromVideoElement(video) {
return new Promise((resolve) => {
const videoTrack = video.captureStream().getVideoTracks()[0];
const trackProcessor = new MediaStreamTrackProcessor({
track: videoTrack,
});
const transformer = new TransformStream({
transform(videoFrame) {
videoTrack.stop();
resolve(videoFrame);
},
flush(controller) {
controller.terminate();
},
});
const trackGenerator = new MediaStreamTrackGenerator({
kind: 'video',
});
trackProcessor.readable
.pipeThrough(transformer)
.pipeTo(trackGenerator.writable);
});
}

async function frame() {
// Sample is no longer the active page.
if (!pageState.active) return;

const videoFrame = await getVideoFrameFromVideoElement(video);
const videoFrame = new VideoFrame(video);

const uniformBindGroup = device.createBindGroup({
layout: pipeline.getBindGroupLayout(0),
Expand Down

0 comments on commit 2fba909

Please sign in to comment.