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 92784c2
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 40 deletions.
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"export": "next export"
},
"dependencies": {
"@types/dom-mediacapture-transform": "^0.1.5",
"codemirror": "^5.58.2",
"dat.gui": "^0.7.6",
"file-loader": "^6.2.0",
Expand Down
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 92784c2

Please sign in to comment.