christianselig,
@christianselig@mastodon.social avatar

Made some progress with 360° video, but small snag where the Vision Pro can't draw the video to canvas fast enough in WebKit (required as video can't be directly snapshotted to my knowledge… right?). Any ideas for optimization?

Code: https://gist.github.com/christianselig/66fade4ecfc909183dec554a0be595e3

Demo: https://christianselig.com/canvas-demo.html

astrsk,

@christianselig do you need to render the entire 360 at all times?

tienshiao,

@christianselig Guessing you’re trying to snapshot the video frame to render on the native side?

I wonder if WebCodecs’ VideoDecoder might work instead. Directly decode the video/frame instead of trying to blit the video to canvas at a certain frame rate. I assume you’d still need to send that frame over to the native side (which I guess is what essentially happens when you take a snapshot, which I guess you’re trying to do at the same interval?).

christianselig,
@christianselig@mastodon.social avatar

@tienshiao Capturing it native side once visible is really fast, but I’ve been unable to find any way to encode it into something portable to “send” over, do you think VideoDecoder could do that more efficiently than canvas’ toDataURL? That ones not too fast

jernoble, (edited )

@christianselig You seem to be using a ‘2d’ canvas context rather than a ‘3d’. This requires blitting the whole frame to another buffer, which is going to be very slow for a 4K video frame. Try using a WebGL backed canvas (canvas.getContext("webgl")) as that should be able to texture directly from the video frame without hitting main memory.

jernoble,

@christianselig You can also use video.requestVideoFrameCallback() rather than a 40hz interval to be notified when there's a new frame to be displayed. That should mean a 24fps video would only need to be painted at 24hz (about a 40% savings).

christianselig,
@christianselig@mastodon.social avatar

@jernoble setInterval takes time not frequency, 24 Hz/fps is 1 frame every 42 ms

jernoble,

@christianselig @jernoble my mistake 😔. Still, setVideoFrameCallback() allows the paint cycle to exactly match the video fps, without having to introspect the container.

christianselig,
@christianselig@mastodon.social avatar

@jernoble Yeah that's cleaner, neat API! Will implement

christianselig,
@christianselig@mastodon.social avatar

@jernoble Ooo, would that add a lot of complexity? Would I need to write shaders or anything, or would it be pretty straight forward?

nrab,
@nrab@hachyderm.io avatar

@christianselig why are you recreating the canvas and refinding the video inside the setInterval callback? Those both should be able to just do once at init. Not sure if that’s inflicting much overhead though

nrab,
@nrab@hachyderm.io avatar

@christianselig nevermind, somehow my brain just skipped over the if (!canvas) 🤦‍♂️ but still the context and the video element can just be initialized outside of setInterval

christianselig,
@christianselig@mastodon.social avatar

@nrab It's still only performed once so the result is the same

mark,

@christianselig Have you tried requestAnimationFrame vs. setInterval?

christianselig,
@christianselig@mastodon.social avatar

@mark requestAnimationFrame would be 60 fps so even harsher on performance for a 24 fps video

mark,

@christianselig Understood but I’m curious if the performance would be better with the animation timer and only capturing when a given FPS interval has passed?

christianselig,
@christianselig@mastodon.social avatar

@mark Unfortunately not :( Fair guess (I thought the same) but it doesn't seem linked to synchronizing frame rate or anything

erik,

@christianselig @mark there is requestVideoFrameCallback too

christianselig,
@christianselig@mastodon.social avatar

@erik @mark No speed up there unfortunately :(

erik,

@christianselig @mark At work we're doing 4k video playback through WebGL with good performance, but it needs a lot more infrastructure than what you have in your screenshot.

christianselig,
@christianselig@mastodon.social avatar

@erik @mark I know next to no WebGL, what would the most basic flow look like there? I still need the video element to exist in the HTML DOM, but could you draw/capture frames from the video element using WebGL faster?

jernoble,
jernoble,
jernoble,
christianselig,
@christianselig@mastodon.social avatar

@jernoble @erik @mark I need to finish reading your tweets before I start replying haha. Thanks Jer, will keep you posted with how this goes

christianselig,
@christianselig@mastodon.social avatar

@jernoble @erik @mark This is so so so cool

erik,

@christianselig @mark right, that's correct. Here is a demo that I funnily created as a bug report to begin with. Might or might not be educational for you: https://github.com/bes/chrome-video-texture-upload-slow/tree/gh-pages?tab=readme-ov-file WebGL can be a bit much, for sure ...

erik,

@christianselig @mark I'm sure my demo has a bunch of stuff you simply won't need (like the surface normals stuff, for example)

christianselig,
@christianselig@mastodon.social avatar

@erik @mark I am in awe of this code, wow

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • DreamBathrooms
  • mdbf
  • ngwrru68w68
  • magazineikmin
  • thenastyranch
  • rosin
  • khanakhh
  • osvaldo12
  • Youngstown
  • slotface
  • Durango
  • kavyap
  • InstantRegret
  • tacticalgear
  • anitta
  • ethstaker
  • provamag3
  • cisconetworking
  • tester
  • GTA5RPClips
  • cubers
  • everett
  • modclub
  • megavids
  • normalnudes
  • Leos
  • JUstTest
  • lostlight
  • All magazines