Getting rid of window padding without distorting aspect ratio of video

Christien Ayers's icon

I've read through quite a few threads about this on this forum, but I haven't found (or realized I've found) a solution to this particular issue I'm having. I'm including a screenshot as opposed to a patch because my patch includes a bunch of abstractions.

I've got a jit.movie object outputting a texture into a jit.gl.pix object, which scales and positions the video into jit.world. Currently, the texture is at the correct aspect ratio but I can't position the texture itself in any of the space colored red. I know this is partly because the @preserve_aspect attribute is turned on for the jit.world object, but of course, once I turned that off, the texture is distorted. Is there a way to have the texture coming out of my jit.gl.pix object stretch to fit the window without altering the aspect ratio of the texture itself (which, again, is being fed into the jit.gl.pix object)?

Wil's icon

connect jit.gl.pix to jit.gl.layer or videoplane @transform_reset 2

should work

Christien Ayers's icon

Hi Wil, just tried it out but it doesn't look like that works either. The texture still can only be positioned within that black square space (though the black color goes away).

Wil's icon

I can't quite see what is happening

You want everything to be red ?

Or keep black and red?

or only black

//

Your jit.world is red

the pix needs to stretch to fit the world

tranform_reset 2 combined with preserve_aspect 1 should work

//

can you resize the video to fill the entire black square? then resize and reposition the entire black square?

//

need to see some sort of patch

Christien Ayers's icon

Here you go, the main patch and necessary scripts/gen externals are attached below. Load in a video larger than 1000x1000 to reproduce the issue. I know that the pix output needs to be stretched, which I can do your way or by disabling adapt attribute and setting the dimensions of pix to the size of the window. The issue is that the aspect ratio of the video gets distorted (see new screenshot).

I'm sure I'm missing something but I can't seem to get my head around it.

Max Patch
Copy patch and select New From Clipboard in Max.
vrand-pos-scale.js
js
pos-scale-pix.genjit
genjit

Christien Ayers's icon

Also, the jit.world is only red for debugging purposes—it helps me see what the boundaries of the render context are

Wil's icon

I set up your patch.

Updated using videoplane (simple rule of thumb don't connect video processing directly to world)

I see that depending on the original video ratio, your container (code) is adapting to the video size

below I attach a you tube link that discusses aspect ratio in using pix objects - then later some codebox

I don't know enough about codbox to help further

Max Patch
Copy patch and select New From Clipboard in Max.
Untitled.mp4
Untitled2.mp4

aspect ratio around 5'

Wil's icon

here is an update position and scale in videoplane

but doing it this way kind of nullifies all that codebox stuff - you might have a bigger purpose!

Max Patch
Copy patch and select New From Clipboard in Max.
Screen Recording 2025-05-06 at 11.14.06 AM.mp4
Christien Ayers's icon

Hey, thanks for doing all of that—totally appreciate it. In your second video it looks like the aspect ratio of your video is still being distorted even after connecting jit.gl.pix to a jit.gl.videoplane object, and I reproduced those same results in my patch.

I think you may be onto something re:codebox... my @gen subpatch might be interacting with the dimensions of the video in such a way that produces the issue. I'll definitely give that video a watch!

And yeah, halfway through working on this patch, I realized I could probably just send the Javascript data as position and scale data straight to jit.gl.videoplane instead of jit.gl.pix, but I'm too stubborn after having written the code to give up on jit.gl.pix just yet. Seems cleaner to have it all happening in pix if I can. The Javascript code is based off of some V8 codebox code that Rob Ramirez helped me out with a few days ago—lets me generate position and scale values for these videos such that they don't overlap on screen, which I don't think you can do without using loops.

Rob Ramirez's icon

i don't know offhand the correct formula to use, but I do know that you will need to use both the aspect ratio of the input box, and the aspect ratio of the output box (aka the window size) in order to calculate this all. If you're going the jit.gl.pix route, you'll likely want to turn off adapt in the pix and explicitly set the dims to match that of your window.

Christien Ayers's icon

Yeah I fortunately ended up kinda figuring that out earlier today. Thanks to Wil, I realized it was something to do with how things were being processed in my gen codebox, and so I fudged with some numbers until I got something that worked. Turns out, I just had to multiply the norm.x value by the aspect ratio of the window (and then account for that when changing the position). Yay!

Appreciate you adding your comment though, because the above calculation only works properly if the input texture/video is a square. It looks like the final calculation is:

(norm.x * window aspect ratio) / input aspect ratio

At least it looks right lol. Thanks for all y'all helping me out!