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

How to display video frames with deck.gl ? #3199

Closed
jrabary opened this issue Jun 5, 2019 · 8 comments
Closed

How to display video frames with deck.gl ? #3199

jrabary opened this issue Jun 5, 2019 · 8 comments
Labels

Comments

@jrabary
Copy link

jrabary commented Jun 5, 2019

I'm new to deck.gl and wondering how to display video frames with it.
I would like to build an app like the ascii demo but instead draw the actual frames.
Is the BitmapLayer suitable for this task or do I need to write a custom layers ?
Any hints will be helpful.
Regards

@Pessimistress
Copy link
Collaborator

The BitmapLayer does not support video right now. I think this is a reasonable use case and we should consider supporting it. @xintongxia

I put together an example here: https://codepen.io/Pessimistress/pen/pmmbRj

@jrabary
Copy link
Author

jrabary commented Jun 6, 2019

@Pessimistress Thanks for the example. Is there something missing it the code ? The image in the canvas is not updated when the video is playing.

@Pessimistress
Copy link
Collaborator

Are you using Safari? WebGL1 does not have good support for non-power-of-two texture sizes (and the demo video demensions are not power of two). You will need to resize your source video.

@tsherif
Copy link
Contributor

tsherif commented Jun 6, 2019

To get an non-power-of-two texture to work in WebGL 1, just change the wrap mode to CLAMP_TO_EDGE (and turn off mipmaps, which was already done here), i.e. in the codepen example, change the texture construction to:

this.setState({
  bitmapTexture: new luma.Texture2D(gl, {
    width: 1,
    height: 1,
    parameters: {
      [gl.TEXTURE_MIN_FILTER]: gl.NEAREST,
      [gl.TEXTURE_MAG_FILTER]: gl.NEAREST,
      
      // THIS IS THE NEW PART
      [gl.TEXTURE_WRAP_S]: gl.CLAMP_TO_EDGE,
      [gl.TEXTURE_WRAP_T]: gl.CLAMP_TO_EDGE
    },
    mipmaps: false          
  })
});

@Pessimistress
Copy link
Collaborator

Thanks @tsherif ! Codepen is updated.

@jrabary
Copy link
Author

jrabary commented Jun 7, 2019

Thank you. It's working great!

@jrabary
Copy link
Author

jrabary commented Jun 7, 2019

@Pessimistress Just to understand what's going on. Does the fact that we set _animate = true forces deckGL to call layer.draw every timestep ?

@Pessimistress
Copy link
Collaborator

Pessimistress commented Jun 7, 2019

That is correct. If you want more control over this, you can manually trigger redraw:

let animation = null;

const videoBitmapLayer = new VideoBitmapLayer({...});
new DeckGL({...});

function animate() {
  videoBitmapLayer.setNeedsRedraw(true);
  animation = requestAnimationFrame(animate);
};

video.onplay = () => animate();
video.onpause = () => cancelAnimationFrame(animation);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants