How do you combine multiple videos into one in texture or shader?

ygreq's icon

Hi guys,

How do you combine multiple videos into one in texture or shader like in the example below? So not within a videoplane or anything like that but before that so I can put an effect after it. Any clues?

Thank you,
ygreq

Max Patch
Copy patch and select New From Clipboard in Max.

ygreq's icon

Or better yet how to you multiply it as many times as you want? 10x10 for example?

Rob Ramirez's icon

if you want behavior similar to jit.glue, then using jit.glue with matrices prior to turning in to textures is the simplest route.

otherwise, you can roll up your sleeves with jit.gl.pix to accomplish this. "sample" and "norm" are the operators to look at. you will need to set the output texture dimensions to whatever you want using a dummy texture in the left most outlet.

here's a basic example that glues together to video inputs to a single texture:

Max Patch
Copy patch and select New From Clipboard in Max.

ygreq's icon

Thank you, Rob, but jit.glue is a terrible object. And jit.gl.pix is a bit like Chinese for me.

I was trying to create at least a 2x2 grid of 4 videos. I guess I will try to do it using jit.gl.node if there are no other possibilies. :(

Max Gardener's icon

Wow. Didn't realize you could do *that*, Rob. Thanks.

Max Gardener's icon

By the way - what's wrong with jit.glue? It's the obvious choice (unless you want to use usesrcdim / usedstdim and their friends srcdimstart, srcdimend, dstdimstart, and dstdimend to write to a named matrix, maybe)....

ygreq's icon

I am using jit.grab and doing fx with some shaders so I cann't combine those with jit.glue.
And jit.glue is hoggy when it comes to using multiple columns and rows. At least this is what I remember since I last used it intensively a few years ago.

Max Gardener's icon

...and, thanks to Rob's elegant example, here's a solution to the jit.gl.pix 4-in-1.

As ever, I am in awe of your skills, Rob. Thanks!

Max Patch
Copy patch and select New From Clipboard in Max.

Christopher Dobrian's icon

Or just this?

Max Patch
Copy patch and select New From Clipboard in Max.

Max Gardener's icon

sweeeeeeeet, Christopher! Add a few negative values to the scaling and it's kaleidoscope time!!!!

ygreq's icon

Thank you, guys, for your help!

Max, I will try that definitely. Christopher, that is what I was thinking of when I said I would need to add a jit.gl.node as there are many things that happen in the main render. Both solutions are great! And thanks again, Rob!

TConnors's icon

Just found this thread and have a question for those in the know.
If I wanted to construct a larger grid of videos (16x12 using 6 videos), than the jit.gl.pix option would be the best route in terms of performance over the other options offered...?

Rob Ramirez's icon

the important thing is to size your video files appropriately (no larger than necessary), and enable output_texture. either technique in this thread will work well for displaying them.

TConnors's icon

Thanks for that Rob.

Yes, I have resized my video appropriately. I have constructed this 'video fabric' using the jit.glue route but would say it is not functioning at a performance level that cuts the mustard—particularly when switching videos.

I think I will roll up my sleeves and give the jit.gl.pix a try. To date, everything I have constructed in jit.gen has outperformed all other options.

TConnors's icon

Update on the 'video fabric' efforts and additional question.

To construct a 10x10 grid of video's I ended up using 6 x (jit.movie @output_tecture 1 @ texture_name (name) @colormode uyvy) to 100 x (jit.gl.gridshape @texture (name) @transform_reset 2 @automatic 1 @drawto cat) to (jit.world cat @fps 60).

I have 40 videos that are randomly read into the jit.movie objects.
Up until this past weekend, I had no issues and am loving the results. The ultimate test, however, is if the installation can run all night.

Failed.

The issue is, after a few hours of running, I get an error message stating the movie file can not be found when the jit.movie attempts to read. I have to close the patch and reopen it to reconnect the file pathway. I'm working on a Mac Book Pro and have set the Energy Saver to 'Never' and have clicked the Prevent App Nap in Max. I added a counter during the last test to see how many read messages were successful before the error. 130 x 6.

I will test again this weekend and perhaps move the movie files to another location but other than that, I can't figure out what might be the issue. I'm stumped. Any thoughts?

Rob Ramirez's icon

sounds like maybe you're relying on the the current working directory path to load your movies. this will change to the location of the most recently loaded file, and so is not reliable if that location changes. you should either look into using absolute file paths for your movie files, or better yet use Projects.

TConnors's icon

Thanks for the reply Rob,

This weekend I tested a few methods and ended up with the same issue. I even placed the movies in the media folder where all the Max demo video are located. But no go. After a few hours of running the installation, I get the “can’t find movie file” error.
But before that error message, there is always a series of jit.gl.fbo_texture draw begin: GL Error: Invalid value
I thought that perhaps the jit.movie was losing the connection with @output_texture 1 so I set up a periodic bang message to the jit.movie.

The weird thing is, and this is what confuses me, if I am working on the patch; as in manually triggering buttons etc., this error issue does not occur. I've work a whole day on this patch with no problems. I might give PHIOL's jit.gl.polymovie a go to see of that might work better.

Regards,
Teresa

phiol's icon

try the jit.gl.multiple version of my jit.gl.polymovie.

you'll get better results if you save the jit.gl.multiple version as a seperate patch

I'm getting a solid 60 fps with 20X20 videos (400 instances)
and even a good 33 fps with 40X40 videos (1600 instances)

and my mbp is almost 3 years old
nvidia 750m

Max Patch
Copy patch and select New From Clipboard in Max.

of course you need to save it in a folder with all the other abstraction patchers.
and again the content (moviefiles) go in the media folder.

here it is , if anybody ever falls on this thread :-)

phiol

Rob Ramirez's icon

teresa, sounds like you might be running out of memory, are you running in 32 or 64 bit? def better to be in 64 if possible.

TConnors's icon

Hi Rob, Thanks for the reply. I'm running in 64 bit. I stopped doing anything in 32 bit some time ago.

Hi PHIOL, Thanks A BUNCH for that! I will give it a go.

My issue was not fps as I was (joyfully) getting a solid 60 fps for the whole during when the installation ran.
It's just the patch stopped finding the movies after a few hours.
I placed all movies in a Projects folder, then placed them all into the OS Movie folder with a direct search link, and then (going old school) into the Max program media folder. Same thing happened, after running for a few hours the jit.moive kicked out the error message that the movie could not be found, preceded by the (jit.gl.fbo_texture draw begin: GL Error: Invalid value) error.

I’ll spend the weekend looking at your patch, and thanks again for that.

Teresa

phiol's icon

Hi again Teresa ,

> I have 40 videos that are randomly read into the jit.movie objects.
>130 x 6

This is where I believe my patch will help you.
All videos are read only once(on startup), then (in my patch setup ) each video texture are called using noise to call @texture attribute. As you can see this occurs directly in the jit.gl.multiple object.

As common practice, you load everything on startup , then put it to sleep.
Then wake it up when needed. This is how thing are done in 3D gl gaming software.
If the camera does not see your geos , there are not processed. But still everything is loaded on startup and waiting for a go!

Here below (objects in blue),

I make it obvious how to change a single cell's texture

Max Patch
Copy patch and select New From Clipboard in Max.

good luck

TConnors's icon

Thanks for that Phiol,

Nice patch.
It’s very helpful.

Best,
Teresa