|
![]() |
|
Thread Tools | Display Modes |
![]() |
#1 |
Human being with feelings
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
|
![]()
I have made some code for showing a grid of videos while automatically allocating a column and row count (leaving black space where necessary). Here's the code to paste into the Video Processor plugin in an empty track with any number of video tracks below it:
Code:
// grid of videos - automatically draws any number of videos from tracks x=0; count_tracks = input_track_count(); cols = ceil(sqrt(count_tracks)); rows = ceil(count_tracks/cols); loop(cols*rows, gfx_blit(input_track(x), 1 /* preserve aspect */, (x%cols)*project_w/cols, ((x - (x%cols))/cols)*project_h/rows, // position project_w/cols,project_h/rows // output width and height ); x += 1; ); https://forum.cockos.com/showthread.php?t=233798 COVID-19 is currently inspiring lots of people to make videos like this. |
![]() |
![]() |
![]() |
#2 |
Human being with feelings
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
|
![]()
There's a video demo of this in action here:
Last edited by jak352; 04-05-2020 at 03:11 PM. Reason: square brackets instead of paranthesis required |
![]() |
![]() |
![]() |
#3 |
Human being with feelings
Join Date: Mar 2018
Location: Cologne
Posts: 1,362
|
![]()
Jak352, this is amazing!
![]() If you don't mind, I would put your video plugin into the video presets thread that I've started a while ago. (https://forum.cockos.com/showthread.php?p=2265562) Many thanks ![]()
__________________
☆.。.:*・°☆.。.:*・°☆.。.:*・°☆REAPER//✿◔‿◔)°☆.。.:*・°☆.。.:*・°☆
|
![]() |
![]() |
![]() |
#4 |
Human being with feelings
Join Date: Mar 2018
Location: Cologne
Posts: 1,362
|
![]()
Would it be possible to create different patterns? I mean to combine four video instances to a bigger one while the others stay small all around. Is there a way to handle that like tables in HTML with rows and cols?
Greetings Eli
__________________
☆.。.:*・°☆.。.:*・°☆.。.:*・°☆REAPER//✿◔‿◔)°☆.。.:*・°☆.。.:*・°☆
Last edited by Eliseat; 04-07-2020 at 02:59 AM. |
![]() |
![]() |
![]() |
#5 |
Human being with feelings
Join Date: Feb 2009
Location: Reaper HAS send control via midi !!!
Posts: 3,888
|
![]()
Cool, thanks for sharing, can Reaper render this to a new video, for uploading to youtube*? Automatic adjustment of the grid is elegant.
* Oh you answered already in your video, File, Render, Time selection, output format MPEG-4, render 1 file. So just a normal rendering does it already. |
![]() |
![]() |
![]() |
#6 | |
Human being with feelings
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
|
![]() Quote:
My code doesn't allow for that as it stands but you could do it like this: 1. Put the videos you want small into tracks 1,2,3,4,5,8,9,12,13,14,15,16. Put a random image into tracks 6,7,10,11. 2. Make a track above all these and use my code and you'll get a 4x4 grid 3. Make a track above all that and put the video into that that you want big and add a new instance of Video Processor on it and choose the "Overlay: Image Overlay" preset and use the zoom knob in the preset to resize the big video. Last edited by jak352; 05-12-2020 at 01:15 PM. Reason: Typo |
|
![]() |
![]() |
![]() |
#7 | |
Human being with feelings
Join Date: Mar 2018
Location: Cologne
Posts: 1,362
|
![]() Quote:
![]() Many thanks ![]()
__________________
☆.。.:*・°☆.。.:*・°☆.。.:*・°☆REAPER//✿◔‿◔)°☆.。.:*・°☆.。.:*・°☆
|
|
![]() |
![]() |
![]() |
#8 |
Human being with feelings
Join Date: May 2012
Posts: 1,273
|
![]()
Good job i love it !
|
![]() |
![]() |
![]() |
#9 |
Human being with feelings
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
|
![]()
If you are doing recordings with large numbers of choir members you might want to use portriat mode recordings but still want a landscape export. Force REAPER to use landscape mode by going to File>Project Settings>Video and set "Preferred video size..." to 1920 by 1080 pixels. For a "virtual choir" grid of portrait videos put the video processor in the top track with the following code:
Code:
// grid of portrait videos - automatically draws any number of videos from tracks x=0; count_tracks = input_track_count(); aspect = project_w/project_h; rows = ceil(sqrt(count_tracks)/aspect); cols = ceil(count_tracks/rows); rows_alt = rows - 1; cols_alt = ceil(count_tracks/rows_alt); rows*(aspect^2)>cols_alt ? (cols = cols_alt;rows = rows_alt;); loop(cols*rows, gfx_blit(input_track(x), 1 /* preserve aspect */, (x%cols)*project_w/cols, ((x - (x%cols))/cols)*project_h/rows, // position project_w/cols,project_h/rows // output width and height ); x += 1; ); Last edited by jak352; 04-09-2020 at 04:57 AM. Reason: Improved row and column allocation and forcing landscape settings |
![]() |
![]() |
![]() |
#10 |
Human being with feelings
Join Date: Nov 2018
Posts: 61
|
![]()
Nice! Good to have another option.
Your new portrait has a line "aspect = project_w/project_h" What happens if we insert that into your old code? |
![]() |
![]() |
![]() |
#11 | |
Human being with feelings
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
|
![]() Quote:
If you want to have the aspect ratio of the videos squashed or stretched to fit you can change the 1 to 0 just before the /* preserve aspect */ comment. Here's the virtual choir version of the code in action: Last edited by jak352; 04-10-2020 at 04:08 AM. Reason: included youtube link to code in aciton |
|
![]() |
![]() |
![]() |
#12 | |
Human being with feelings
Join Date: Feb 2018
Posts: 41
|
![]() Quote:
It's really awesome. How would you do the next idea? I start with your code, with a group of small videos in a grid, but after a seconds, how could I zoom in one of them and then continue in a full screen mode? Or just how to zoom out a full screen video and finish in a small one that is a cell of a grid... I repeat: THANKS!! |
|
![]() |
![]() |
![]() |
#13 | |
Human being with feelings
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
|
![]() Quote:
|
|
![]() |
![]() |
![]() |
#14 | |
Human being with feelings
Join Date: Feb 2018
Posts: 41
|
![]() Quote:
![]() |
|
![]() |
![]() |
![]() |
#15 |
Human being with feelings
Join Date: Dec 2011
Posts: 43
|
![]()
This is absolutely fantastic! Thank you!
|
![]() |
![]() |
![]() |
#16 |
Human being with feelings
Join Date: Apr 2020
Posts: 5
|
![]()
Here's some modifications to the code that allow two things:
Code:
// Grid of videos with Subtitles room - automatically draws any number of videos from tracks //@param 2:ypos "y position" 1 0 600 150 1 height = project_h - ypos; // width = project_w * height / (ypos + height); width = project_w; gfx_set(0); gfx_fillrect(0,0,project_w,project_h); x=0; count_tracks = input_track_count(); cols = ceil(sqrt(count_tracks)); rows = ceil(count_tracks/cols); loop(cols*rows, xpos = 0; lastLineCount = (count_tracks-1) % cols + 1; lastLineOffset = (width - width/cols * lastLineCount) / 2 ; x >= (cols*rows - cols) // Is it the last line? ? xpos = (x%cols)*width/cols + lastLineOffset // x position last line : xpos = (x%cols)*width/cols // x position non-last line ; gfx_blit( input_track(x), 1, // preserve aspect xpos, // X position ((x - (x%cols))/cols)*(height)/rows, // y position width/cols,height/rows // output width and height ); x += 1; ); |
![]() |
![]() |
![]() |
#17 |
Human being with feelings
Join Date: Apr 2020
Posts: 5
|
![]()
A minor edit to allow black borders around each video, so it looks more Zoom style and neater. Also last line centered.
Code:
// Grid of videos - automatically draws any number of videos from tracks with grid //@param 3:border "Grid Borders" 1 0 20 10 1 gfx_set(0); gfx_fillrect(0,0,project_w,project_h); x=0; count_tracks = input_track_count(); cols = ceil(sqrt(count_tracks)); rows = ceil(count_tracks/cols); height = project_h - border; width = project_w - border; vHeight = height / cols - border; // Video height vWidth = width / cols - border; // Video Width loop(cols*rows, xpos = 0; row = ceil((x+1) / cols); // Column position col = x % cols; // Row position lastLineCount = (count_tracks-1) % cols + 1; // Number of videos in last row lastLineOffset = (width - width/cols * lastLineCount) / 2 ; x >= (cols*rows - cols) // Is it the last line? ? xpos = col*vwidth + lastLineOffset +border*col // x position last line : xpos = col*vwidth + border*col // x position non-last line ; gfx_blit( input_track(count_tracks - x - 1), 0, // don't preserve aspect (low distortion for horiz images) border + xpos, // X position border + vheight*(row-1) + border*(row-1) + ypos, // Y position vwidth,vheight // output width and height ); x += 1; ); |
![]() |
![]() |
![]() |
#18 |
Human being with feelings
Join Date: Dec 2011
Posts: 43
|
![]()
Thank you so much for these. Question where in the code would I enter a value to end the track count so that I could add a background to the video mix?
Also, do you have a paypal I can donate to? You have saved me so much time! |
![]() |
![]() |
![]() |
#19 |
Human being with feelings
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
|
![]()
Nice work @echan101, thanks! Here's an improved version preserving the aspect ratio for larger borders and using the top track (the one with the video processor in it) as a source for background image/video. Hey, if anyone wants to PayPal me at jonathan@kempstrings.com I won't object!
Code:
// Grid of videos - automatically draws any number of videos from tracks with grid //@param 3:border "Grid Borders" 1 0 100 50 1 gfx_set(0); gfx_fillrect(0,0,project_w,project_h); x=0; count_tracks = input_track_count(); cols = ceil(sqrt(count_tracks)); rows = ceil(count_tracks/cols); aspect = project_w/project_h; height = project_h - border; width = project_w - border*aspect; vHeight = height / cols - border; // Video height vWidth = width / cols - border*aspect; // Video Width gfx_blit(0); //Show current track image or video as background loop(count_tracks, xpos = 0; row = ceil((x+1) / cols); // Column position col = x % cols; // Row position lastLineCount = (count_tracks-1) % cols + 1; // Number of videos in last row lastLineOffset = (width - width/cols * lastLineCount) / 2 ; x >= (cols*rows - cols) // Is it the last line? ? xpos = col*vwidth + lastLineOffset +border*aspect*col // x position last line : xpos = col*vwidth + border*aspect*col // x position non-last line ; gfx_blit( input_track(count_tracks - x - 1), 0, // don't preserve aspect (low distortion for horiz images) border*aspect + xpos, // X position border + vheight*(row-1) + border*(row-1) + ypos, // Y position vwidth,vheight // output width and height ); x += 1; ); Last edited by jak352; 04-26-2020 at 04:42 AM. Reason: "Grid Borders" dial is smoother with 1 0 100 50 1 |
![]() |
![]() |
![]() |
#20 | |
Human being with feelings
Join Date: Dec 2011
Posts: 43
|
![]() Quote:
|
|
![]() |
![]() |
![]() |
#21 | ||
Human being with feelings
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
|
![]() Quote:
Quote:
The videos that make up the grid go in tracks 2, 3, 4 and so on as usual (and are loaded using gfx_blit(input_track(count_tracks - x - 1)...) in the code) with the last one loaded being from track 2 in the project. Actually, you can make the order swap by replacing input_track(count_tracks - x - 1) with input_track(x) which makes more sense to me as then track 2 gives the top left video in the grid. The long and the short of it is that I think maybe you haven't put a video or image into track 1 (which is the track with the video processor in it) and therefore it is showing track 2 as the background for that reason. Does this help? Last edited by jak352; 04-26-2020 at 01:10 PM. |
||
![]() |
![]() |
![]() |
#22 | |
Human being with feelings
Join Date: Dec 2011
Posts: 43
|
![]() Quote:
I got it working. It was as you suspected. I hadn't inserted a video on to the top track yet. Thanks again! |
|
![]() |
![]() |
![]() |
#23 |
Human being with feelings
Join Date: Apr 2010
Posts: 1,247
|
![]()
Jonathan or echan,
super work as I already mentioned. Is there a reason why the first video is being displayed twice (one after another) plus the big one (this one I understand)? Some muted tracks from above cause that, but do not get the reason why so.
__________________
W10 (64) Lenovo E540 - SSD; Lenovo B590; W7 (32), Compaq 610 (2.1Ghz core 2 duo, L2 cache, 2GB RAM); DPA 4018, Schoeps MK2, Schoeps MTSC 64, Neumann mk184, AEA Ribbon 88mk, AKG SolidTUBE; Focusrite Scarlett 18i20, recording merely live acoustic music. Last edited by urednik; 04-27-2020 at 05:42 AM. |
![]() |
![]() |
![]() |
#24 |
Human being with feelings
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
|
![]()
Sorry, I'm not sure as the first video isn't being displayed twice for me. Is the Video processor running in track 1 (recommended)? Is the background video in track 1 (recommended)? In which track is the video that appears twice?
|
![]() |
![]() |
![]() |
#25 |
Human being with feelings
Join Date: Apr 2010
Posts: 1,247
|
![]()
Ok, thanks, I had it on master FX ... Now it works, thanks!
Is there possible to order videos rather in other way? 1st track first in grid? (now it is last) BTW this was possible with your code https://www.youtube.com/watch?v=gOx5DkDkceU
__________________
W10 (64) Lenovo E540 - SSD; Lenovo B590; W7 (32), Compaq 610 (2.1Ghz core 2 duo, L2 cache, 2GB RAM); DPA 4018, Schoeps MK2, Schoeps MTSC 64, Neumann mk184, AEA Ribbon 88mk, AKG SolidTUBE; Focusrite Scarlett 18i20, recording merely live acoustic music. Last edited by urednik; 04-27-2020 at 02:56 PM. |
![]() |
![]() |
![]() |
#26 | |
Human being with feelings
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
|
![]() Quote:
|
|
![]() |
![]() |
![]() |
#27 |
Human being with feelings
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
|
![]()
Here's a helper I made for my wife who is assembling a grid of videos... Unfortunately some are portrait some are landscape, and all need to be panned and zoomed to match scale, and besides there are 15 and she wanted 3 rows of 5, so the auto choir video didn't work.
To make that job simpler, I created this grid framer, and it occurs to me it will also make these auto-generated choir videos look better. It just creates a set of frames, any number of rows or columns with a selectable frame size. She put it on top of all her other videos, and it meams the edges don't have to be pixel perfect. Also, I think these kinds of videos look better with frames. If you set width and height to 1, and left and top to zero it fills the whole window. But you can change its size and position, so you could put 2 rows of 2 on the left half, and 3 rows of 2 on the right. Hope it's useful to someone.... Cheers! Code:
//Moon Grid Frame // 'name' [defval minval maxval centval step] //@param 1:percent_y 'Top' 0.0 //@param 2:percent_x 'Left' 0.0 //@param 3:percent_h 'Height' 1 0 1 .5 0.01 //@param 4:percent_w 'Width' 1 0 1 .5 0.01 //@param 6:fine_y 'Top-fine' 0 -1 1 0 .01 //@param 7:fine_x 'Left-fine' 0 -1 1 0 .01 //@param 8:fine_h 'Height-fine' 0 -1 1 0 .01 //@param 9:fine_w 'Width-fine' 0 -1 1 0 .01 //@param11:rows 'Rows' 1 1 9 5 1 //@param12:cols 'Columns' 1 1 9 5 1 //@param13:border 'Border' 10 0 50 10 2 //@param15:R 'Red' 1 0 1 0.5 0.1 //@param16:G 'Green' 1 0 1 0.5 0.1 //@param17:B 'Blue' 1 0 1 0.5 0.1 input = 0; !project_wh_valid && input_info(input,w,h) ? ( project_w=w; project_h=h; ); fine = .05; dest_x = (percent_x + (fine * fine_x)) * project_w; dest_y = (percent_y + (fine * fine_y)) * project_h; dest_w = (percent_w + (fine * fine_w)) * project_w; dest_h = (percent_h + (fine * fine_h)) * project_h; input = 0; gfx_blit(input,1); gfx_set(R,G,B,1); //verticals offset_H = ((dest_w - border) / cols) + dest_x; col = 0; loop(cols + 1, left = col * offset_H; top = dest_y; width = border; height = dest_h; gfx_fillrect(left,top,width,height); col = col + 1; ); //horizontals offset_V = ((dest_h - border) / rows) + dest_y; row = 0; loop(rows + 1, left = dest_x; top = row * offset_V; width = dest_w; height = border; gfx_fillrect(left,top,width,height); row = row + 1; ); Last edited by woodslanding; 04-28-2020 at 10:17 PM. |
![]() |
![]() |
![]() |
#28 |
Human being with feelings
Join Date: Jul 2009
Posts: 7,140
|
![]()
I've got my own code going for this as well.
results from an evening of hacking https://youtu.be/ASNSDOfUJzU https://youtu.be/Dz6RxhMtkcY have to merge my changes into the portrait version still but I'm really happy with these results
__________________
REAPER Video Tutorials, Tips & Tricks and more at The REAPER Blog
|
![]() |
![]() |
![]() |
#29 |
Human being with feelings
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
|
![]()
Here's a version that allows for a larger video within the grid. With "Lead Video Width" set to 2 then the lead video (which can be chosen using "Lead Video Track" dial) will be twice as wide/tall and placed centrally. If it's set to 3 the lead video will be three times as tall/wide and so on. Everything else fits around it. You can also drag the y position of the whole thing using "Y Offset". Border size is set with "Grid Borders". Setting "Preserve Aspect" to 0 means videos/images will be stretched to fit the grid which is unecessary if everything is the same aspect aspect ratio but can be helpful to get rid of any black spaces.
Just place this code in the Video Processor in track 1. Put the videos you want in the grid in tracks 2 onwards. If you want a background image or background video (visible for non-zero Grid Borders values) then put that in track 1. Images count as if they are videos and image items can be resized to fill space (to ensure tracks don't hop around if you don't want them to for instance). The default size/shape of the export video is set by the video or image in track 1 (or track 2 if there's no background image/video in track 1). If you get low quality or output of the wrong size I recommend going to File>Project Settings>Video and setting the preserved video size to what you want (such as 1920 x 1080) and you might find it helps to tick "Always resize video sources..." and "Always resize video output...". It possible to use automation on the parameters if you want to get fancy. Enjoy! Code:
// Grid of videos - automatically draws any number of videos from tracks with grid //@param 1:boss "Lead Video Track" 2 2 10 6 1 //@param 2:Nbig "Lead Video Width" 2 1 9 5 1 //@param 3:yposratio "Y Offset" 0 0 1 0.5 0.01 //@param 4:border "Grid Borders" 5 0 100 50 1 //@param 5:presasp "Preserve Aspect" 1 0 1 0.5 1 boss = boss - 1; // boss is now relative to video processor track Ntracks = input_track_count(); // Number of video files boss>Ntracks ? boss = Ntracks; // If the lead video track set is greater than Ntracks use last gfx_set(0); gfx_fillrect(0,0,project_w,project_h); x=0; Ntracks > 0 // If there are video tracks then get nonzero number of grid locations ? count_tracks = Ntracks + Nbig^2 - 1 // Number of grid locations filled : //else no grid count_tracks = 0 ; cols = ceil(sqrt(count_tracks)); rows = ceil(count_tracks/cols); aspect = project_w/project_h; height = project_h - border; width = project_w - border*aspect; vHeight = height / cols - border; // Video height vWidth = width / cols - border*aspect; // Video Width top_left_rows = floor((cols - Nbig)/2); // Number of columns (and rows) before big central video gfx_blit(0); // Show current track image or video as background bosscount = 0; // Counter for taking into account grid positions for boss video loop(count_tracks, xpos = 0; ypos = yposratio*project_h; row = floor(x/cols); // Column position (starts at 0) col = x % cols; // Row position (starts at 0) lastLineCount = (count_tracks-1) % cols + 1; // Number of videos in last row lastLineOffset = (width - width/cols * lastLineCount) / 2 ; x >= (cols*rows - cols) // Is it the last line? ? xpos = col*vwidth + lastLineOffset +border*aspect*col // x position last line : xpos = col*vwidth + border*aspect*col // x position non-last line ; ((row>top_left_rows-1)&(col>top_left_rows-1)&(row<top_left_rows+Nbig)&(col<top_left_rows+Nbig)) ? // if the grid number corresponds to being part of the big video ( bosscount == 0 // if its the first of the big video then plot it ? ( gfx_blit( input_track(boss-1), presasp, // preserve aspect ratio border*aspect + xpos, // X position border + vheight*(row) + border*(row) + ypos, // Y position Nbig*vwidth+(Nbig-1)*aspect*border,Nbig*vheight+(Nbig-1)*border // output width and height ); ); bosscount = bosscount + 1; // increment counter ) : // else if the grid number is not part of the big video x-bosscount+1 < Ntracks // if this video number exists ? (vidnum = x-bosscount+1; vidnum < boss ? vidnum = vidnum-1; gfx_blit( input_track(vidnum), presasp, // preserve aspect ratio border*aspect + xpos, // X position border + vheight*(row) + border*(row) + ypos, // Y position vwidth,vheight // output width and height ); ); x += 1; ); Last edited by jak352; 05-04-2020 at 01:24 AM. Reason: preserve aspect ratio is now optional |
![]() |
![]() |
![]() |
#30 |
Human being with feelings
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
|
![]()
Here's revised code where you can choose to optimise for landscape or portrait source videos using a dial (assuming landscape output)! It can now allow you to specify a background colour too. As before it allows for a larger video within the grid. With "Lead Video Width" set to 2 then the lead video (which can be chosen using "Lead Video Track" dial) will be twice as wide/tall and placed centrally and so on. Any number of videos then fit around it. You can also drag the y position of the whole thing using "Y Offset". Border size is set with "Grid Borders". Setting "Preserve Aspect" to 0 means videos/images will be stretched to fit the grid which can be helpful to get rid of any black spaces.
Just place this code in the Video Processor in track 1. Put the videos you want in the grid in tracks 2 onwards. If you want a background image or background video (visible for non-zero Grid Borders values) then put an image or video in track 1 and set Background Color/Video to 1. Leave Background Color/Video on 0 if you want to specify a backround color using the RGB knobs instead. Images count as if they are videos and image items can be resized to fill space (to ensure tracks don't hop around if you don't want them to for instance). The default size/shape of the export video is set by the video or image in track 1 (or track 2 if there's no background image/video in track 1). If you get low quality or output of the wrong size I recommend going to File>Project Settings>Video and setting the preserved video size to what you want (such as 1920 x 1080) and you might find it helps to tick "Always resize video sources..." and "Always resize video output...". It possible to use automation on the parameters if you want to get fancy. Enjoy! Code:
// Grid of videos - automatically draws any number of videos from tracks with grid //@param 1:boss "Lead Video Track" 2 2 10 6 1 //@param 2:Nbig "Lead Video Width" 1 1 9 5 1 //@param 3:yposratio "Y Offset" 0 0 1 0.5 0.01 //@param 4:border "Grid Borders" 5 0 100 50 1 //@param 5:presasp "Preserve Aspect" 0 0 1 0.5 1 //@param 6:portrait "Landscape or Portrait" 0 0 1 0.5 1 //@param 7:background "Backdrop Color/Video" 0 0 1 0.5 1 //@param 8:R "Backdrop Red" 0 0 1 0.5 0.01 //@param 9:G "Backdrop Green" 0 0 1 0.5 0.01 //@param 10:B "Backdrop Blue" 0 0 1 0.5 0.01 boss = boss - 1; // boss is now relative to video processor track Ntracks = input_track_count(); // Number of video files boss>Ntracks ? boss = Ntracks; // If the lead video track set is greater than Ntracks use last gfx_set(0); gfx_fillrect(0,0,project_w,project_h); x=0; Ntracks > 0 // If there are video tracks then get nonzero number of grid locations ? count_tracks = Ntracks + Nbig^2 - 1 // Number of grid locations filled : //else no grid count_tracks = 0 ; aspect = project_w/project_h; portrait == 0 ?// if landscape source videos ( border_h = border; border_w = border*aspect; height = project_h - border_h; width = project_w - border_w; cols = ceil(sqrt(count_tracks)); rows = ceil(count_tracks/cols); vHeight = height / cols - border_h; // Video height including half border*aspect each side vWidth = width / cols - border_w; // Video Width including half border*aspect each side ) : // else we assume portrait source videos need to be fitted into landscape output ( border_h = border*aspect; border_w = border; height = project_h - border_h; width = project_w - border_w; rows = ceil((sqrt(count_tracks))/aspect); cols = ceil(count_tracks/rows); rows_alt = rows - 1; cols_alt = ceil(count_tracks/rows_alt); rows*(aspect^2)>cols_alt ? (cols = cols_alt;rows = rows_alt;); // if reducing rows by one is more efficient rows<Nbig ? (rows = Nbig; cols = ceil(count_tracks/rows);); // if number of rows is less than Nbig vWidth = width / cols - border_w; // Video Width vHeight = height / rows - border_h; // Video Height aspect < (vHeight/vWidth) // if fitting to width and not tall enough ? (xoffset = 0; vHeight = vWidth*aspect;) // Replace video Height : // else fitting to height and not wide enough (vWidth = vHeight / aspect; // Replace video Width xoffset = (project_w - (cols*vWidth + (cols+1)*border_w))/2;) ); Nbig>1 ? // if one of the videos is chosen to be big ( left_cols = floor((cols - Nbig)/2); // Number of columns before big central video top_rows = floor((rows - Nbig)/2); // Number of rows before big central video ) : ( left_cols = 0; top_rows = 0; ); background == 1 ? gfx_blit(0) // Show current track image or video as background : ( gfx_set(R,G,B,1); gfx_fillrect(0,0,project_w,project_h); // Show color as background ); bosscount = 0; // Counter for taking into account grid positions for boss video ypos = yposratio*project_h; loop(count_tracks, row = floor(x/cols); // Column position (starts at 0) col = x % cols; // Row position (starts at 0) lastLineCount = (count_tracks-1) % cols + 1; // Number of videos in last row //lastLineOffset = (width - width/cols * lastLineCount) / 2 ; lastLineOffset = (project_w - (lastLineCount*vWidth + (lastLineCount+1)*border_w))/2; ((x >= (cols*rows - cols))&(bosscount == Nbig^2)) // Is it the last line? ? xpos = col*vwidth + lastLineOffset + border_w*col // x position last line : xpos = col*vwidth + border_w*col + xoffset // x position non-last line ; ((row>top_rows-1)&(col>left_cols-1)&(row<top_rows+Nbig)&(col<left_cols+Nbig)) ? // if the grid number corresponds to being part of the big video ( bosscount == 0 // if its the first of the big video then plot it ? ( gfx_blit( input_track(boss-1), presasp, // preserve aspect ratio border_w + xpos, // X position border_h + vheight*(row) + border_h*(row) + ypos, // Y position Nbig*vwidth+(Nbig-1)*border_w,Nbig*vheight+(Nbig-1)*border_h // output width and height ); ); bosscount = bosscount + 1; // increment counter ) : // else if the grid number is not part of the big video x-bosscount+1 < Ntracks // if this video number exists ? (vidnum = x-bosscount+1; vidnum < boss ? vidnum = vidnum-1; gfx_blit( input_track(vidnum), presasp, // preserve aspect ratio border_w + xpos, // X position border_h + vheight*(row) + border_h*(row) + ypos, // Y position vwidth,vheight // output width and height ); ); x += 1; ); Last edited by jak352; 05-10-2020 at 04:08 AM. Reason: Now allows for background color. Default Lead Video Width is now set to 1 |
![]() |
![]() |
![]() |
#31 |
Human being with feelings
Join Date: Jul 2009
Posts: 7,140
|
![]()
I was having some serious issues writing new features into the portrait mode preset originally posted. Thanks for this new preset
__________________
REAPER Video Tutorials, Tips & Tricks and more at The REAPER Blog
|
![]() |
![]() |
![]() |
#32 |
Human being with feelings
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
|
![]() |
![]() |
![]() |
![]() |
#33 |
Human being with feelings
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
|
![]()
Here's more revised code. If you want a large gap in the grid to allow a big bit of background video/image to be revealled then make Lead Track equal to 1 and switch Backdrop Color/Video to 1 and increase Lead Video Width to taste. This will allow the video on Track 2 to display in the backround instead of being resized within the grid (as long as you leave Track 1 empty of video/images).
You can choose to optimise for landscape or portrait source videos using a dial (assuming landscape output)! It can now allow you to specify a background colour too. As before it allows for a larger video within the grid. With "Lead Video Width" set to 2 then the lead video (which can be chosen using "Lead Video Track" dial) will be twice as wide/tall and placed centrally and so on. Any number of videos then fit around it. You can also drag the y position of the whole thing using "Y Offset". Border size is set with "Grid Borders". Setting "Preserve Aspect" to 0 means videos/images will be stretched to fit the grid which can be helpful to get rid of any black spaces. Just place this code in the Video Processor in track 1. Put the videos you want in the grid in tracks 2 onwards. If you want a background image or background video (visible for non-zero Grid Borders values) while still preserving the video on track 2 within the grid then put an image or video in track 1 and set Background Color/Video to 1. Leave Background Color/Video on 0 if you want to specify a backround color using the RGB knobs instead. Images count as if they are videos and image items can be resized to fill space (to ensure tracks don't hop around if you don't want them to for instance). The default size/shape of the export video is set by the video or image in track 1 (or track 2 if there's no background image/video in track 1). If you get low quality or output of the wrong size I recommend going to File>Project Settings>Video and setting the preserved video size to what you want (such as 1920 x 1080) and you might find it helps to tick "Always resize video sources..." and "Always resize video output...". It is possible to use automation on the parameters if you want to get fancy. Enjoy! Code:
// Grid of videos - automatically draws any number of videos from tracks with grid //@param 1:boss "Lead Video Track" 2 1 11 6 1 //@param 2:Nbig "Lead Video Width" 1 1 9 5 1 //@param 3:yposratio "Y Offset" 0 0 1 0.5 0.01 //@param 4:border "Grid Borders" 5 0 100 50 1 //@param 5:presasp "Preserve Aspect" 0 0 1 0.5 1 //@param 6:portrait "Landscape or Portrait" 0 0 1 0.5 1 //@param 7:background "Backdrop Color/Video" 1 0 1 0.5 1 //@param 8:R "Backdrop Red" 0 0 1 0.5 0.01 //@param 9:G "Backdrop Green" 0 0 1 0.5 0.01 //@param 10:B "Backdrop Blue" 0 0 1 0.5 0.01 boss = boss - 1; // boss is now relative to video processor track Ntracks = input_track_count(); // Number of video files boss>Ntracks ? boss = Ntracks; // If the lead video track set is greater than Ntracks use last gfx_set(0); gfx_fillrect(0,0,project_w,project_h); x=0; Ntracks > 0 // If there are video tracks then get nonzero number of grid locations ? count_tracks = Ntracks + Nbig^2 - 1 // Number of grid locations filled : //else no grid count_tracks = 0 ; aspect = project_w/project_h; portrait == 0 ?// if landscape source videos ( xoffset = 0; border_h = border; border_w = border*aspect; height = project_h - border_h; width = project_w - border_w; cols = ceil(sqrt(count_tracks)); rows = ceil(count_tracks/cols); vHeight = height / cols - border_h; // Video height including half border*aspect each side vWidth = width / cols - border_w; // Video Width including half border*aspect each side ) : // else we assume portrait source videos need to be fitted into landscape output ( border_h = border*aspect; border_w = border; height = project_h - border_h; width = project_w - border_w; rows = ceil((sqrt(count_tracks))/aspect); cols = ceil(count_tracks/rows); rows_alt = rows - 1; cols_alt = ceil(count_tracks/rows_alt); rows*(aspect^2)>cols_alt ? (cols = cols_alt;rows = rows_alt;); // if reducing rows by one is more efficient rows<Nbig ? (rows = Nbig; cols = ceil(count_tracks/rows);); // if number of rows is less than Nbig vWidth = width / cols - border_w; // Video Width vHeight = height / rows - border_h; // Video Height aspect < (vHeight/vWidth) // if fitting to width andѿ not tall enough ? (xoffset = 0; vHeight = vWidth*aspect;) // Replace video Height : // else fitting to height and not wide enough (vWidth = vHeight / aspect; // Replace video Width xoffset = (project_w - (cols*vWidth + (cols+1)*border_w))/2;) ); Nbig>1 ? // if one of the videos is chosen to be big ( left_cols = floor((cols - Nbig)/2); // Number of columns before big central video top_rows = floor((rows - Nbig)/2); // Number of rows before big central video ) : ( left_cols = 0; top_rows = 0; ); background == 1 ? gfx_blit(0) // Show current track image or video as background : ( gfx_set(R,G,B,1); gfx_fillrect(0,0,project_w,project_h); // Show color as background ); bosscount = 0; // Counter for taking into account grid positions for boss video ypos = yposratio*project_h; loop(count_tracks, row = floor(x/cols); // Column position (starts at 0) col = x % cols; // Row position (starts at 0) lastLineCount = (count_tracks-1) % cols + 1; // Number of videos in last row //lastLineOffset = (width - width/cols * lastLineCount) / 2 ; lastLineOffset = (project_w - (lastLineCount*vWidth + (lastLineCount+1)*border_w))/2; ((x >= (cols*rows - cols))&(bosscount == Nbig^2)) // Is it the last line? ? xpos = col*vwidth + lastLineOffset + border_w*col // x position last line : xpos = col*vwidth + border_w*col + xoffset // x position non-last line ; ((row>top_rows-1)&(col>left_cols-1)&(row<top_rows+Nbig)&(col<left_cols+Nbig)) ? // if the grid number corresponds to being part of the big video ( ((bosscount == 0)&(boss>0)) // if its the first of the big video then plot it ? ( gfx_blit( input_track(boss-1), presasp, // preserve aspect ratio border_w + xpos, // X position border_h + vheight*(row) + border_h*(row) + ypos, // Y position Nbig*vwidth+(Nbig-1)*border_w,Nbig*vheight+(Nbig-1)*border_h // output width and height ); ); bosscount = bosscount + 1; // increment counter ) : // else if the grid number is not part of the big video x-bosscount+1 < Ntracks // if this video number exists ? (vidnum = x-bosscount+1; vidnum < boss ? vidnum = vidnum-1; gfx_blit( input_track(vidnum), presasp, // preserve aspect ratio border_w + xpos, // X position border_h + vheight*(row) + border_h*(row) + ypos, // Y position vwidth,vheight // output width and height ); ); x += 1; ); Last edited by jak352; 05-10-2020 at 01:30 PM. Reason: corrected missing xoffset = 0; for landscape videos |
![]() |
![]() |
![]() |
#34 |
Human being with feelings
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
|
![]()
Here's more revised code. If you want a large gap in the grid to allow a big bit of background video/image to be revealled then make "Expand Lead Track" to 1 and leave "Lead to Front on 0" and increase "Lead Video Width" to taste. This will allow the video on the Lead Track number of your choice to display in the backround instead of being resized within the grid (as long as you leave Track 1 empty of video/images).
You can choose to optimise for landscape or portrait source videos using a dial (assuming landscape output). It can now allow you to specify a background colour too (if Expand Background Video is 0). As before it allows for a larger video within the grid. With "Lead Video Width" set to 2 then the lead video (which can be chosen using "Lead Video Track" dial) will be twice as wide/tall and placed centrally and so on. Any number of videos then fit around it. You can also drag the y position of the whole thing using "Y Offset". Border size is set with "Grid Borders". Setting "Preserve Aspect" to 0 means videos/images will be stretched to fit the grid which can be helpful to get rid of any black spaces. Just place this code in the Video Processor in track 1. Put the videos you want in the grid in tracks 2 onwards. If you want a background image or background video (visible for non-zero Grid Borders values when Expand Lead Track is 0) while still preserving the video on track 2 within the grid then put an image or video in track 1 and set Background Color/Video to 1. Leave Background Color/Video on 0 if you want to specify a backround color using the RGB knobs instead. Images count as if they are videos and image items can be resized to fill space (to ensure tracks don't hop around if you don't want them to for instance). The default size/shape of the export video is set by the video or image in track 1 (or track 2 if there's no background image/video in track 1). If you get low quality or output of the wrong size I recommend going to File>Project Settings>Video and setting the preserved video size to what you want (such as 1920 x 1080) and you might find it helps to tick "Always resize video sources..." and "Always resize video output...". It is possible to use automation on the parameters if you want to get fancy. Enjoy! Code:
// Grid of videos - automatically draws any number of videos from tracks with grid //@param 1:boss "Lead Video Track" 2 2 10 6 1 //@param 2:Nbig "Lead Video Width" 1 1 9 5 1 //@param 3:yposratio "Y Offset" 0 0 1 0.5 0.01 //@param 4:border "Grid Borders" 5 0 100 50 1 //@param 5:presasp "Preserve Aspect" 0 0 1 0.5 1 //@param 6:portrait "Landscape or Portrait" 0 0 1 0.5 1 //@param 7:background "Backdrop Color/Video" 1 0 1 0.5 1 //@param 8:R "Backdrop Red" 0 0 1 0.5 0.01 //@param 9:G "Backdrop Green" 0 0 1 0.5 0.01 //@param 10:B "Backdrop Blue" 0 0 1 0.5 0.01 //@param 11:bossexpand "Expand Lead Track" 0 0 1 0.5 1 //@param 12:bossfront "Lead to Front" 0 0 1 0.5 1 aspect = project_w/project_h; // aspect ratio of project boss = boss - 1; // boss is now relative to video processor track ypos = yposratio*project_h; ((boss>0)&(bossexpand==1)&(bossfront==1)) ? // if there is a lead track on front then plot it gfx_blit( input_track(boss-1), presasp, // preserve aspect ratio 0, // X position 0, // Y position project_w,project_h // output width and height ) : // if there isn't a lead track on front then do the rest of the code ( Ntracks = input_track_count(); // Number of video files boss>Ntracks ? boss = Ntracks; // If the lead video track set is greater than Ntracks use last gfx_set(0); gfx_fillrect(0,0,project_w,project_h); x=0; // Counter for looping through grid entries Ntracks > 0 // If there are video tracks then get nonzero number of grid locations ? count_tracks = Ntracks + Nbig^2 - 1 // Number of grid locations filled : //else no grid count_tracks = 0 ; portrait == 0 ?// if landscape source videos ( xoffset = 0; border_h = border; border_w = border*aspect; height = project_h - border_h; width = project_w - border_w; cols = ceil(sqrt(count_tracks)); rows = ceil(count_tracks/cols); vHeight = height / cols - border_h; // Video height including half border*aspect each side vWidth = width / cols - border_w; // Video Width including half border*aspect each side ) : // else we assume portrait source videos need to be fitted into landscape output ( border_h = border*aspect; border_w = border; height = project_h - border_h; width = project_w - border_w; rows = ceil((sqrt(count_tracks))/aspect); cols = ceil(count_tracks/rows); rows_alt = rows - 1; cols_alt = ceil(count_tracks/rows_alt); rows*(aspect^2)>cols_alt ? (cols = cols_alt;rows = rows_alt;); // if reducing rows by one is more efficient rows<Nbig ? (rows = Nbig; cols = ceil(count_tracks/rows);); // if number of rows is less than Nbig vWidth = width / cols - border_w; // Video Width vHeight = height / rows - border_h; // Video Height aspect < (vHeight/vWidth) // if fitting to width andѿ not tall enough ? (xoffset = 0; vHeight = vWidth*aspect;) // Replace video Height : // else fitting to height and not wide enough (vWidth = vHeight / aspect; // Replace video Width xoffset = (project_w - (cols*vWidth + (cols+1)*border_w))/2;) ); Nbig>1 ? // if one of the videos is chosen to be big ( left_cols = floor((cols - Nbig)/2); // Number of columns before big central video top_rows = floor((rows - Nbig)/2); // Number of rows before big central video ) : ( left_cols = 0; top_rows = 0; ); ((boss>0)&(bossexpand==1)&(bossfront==0)) ? // if there is a lead track at back then plot it gfx_blit( input_track(boss-1), presasp, // preserve aspect ratio 0, // X position 0, // Y position project_w,project_h // output width and height ) : ( background == 1 ? gfx_blit(0) // If background is 1 then show current track image or video as background : ( gfx_set(R,G,B,1); gfx_fillrect(0,0,project_w,project_h); // else show color as background ); ); bosscount = 0; // Counter for taking into account grid positions for boss video loop(count_tracks, row = floor(x/cols); // Column position (starts at 0) col = x % cols; // Row position (starts at 0) lastLineCount = (count_tracks-1) % cols + 1; // Number of videos in last row lastLineOffset = (project_w - (lastLineCount*vWidth + (lastLineCount+1)*border_w))/2; ((x >= (cols*rows - cols))&(bosscount == Nbig^2)) // Is it the last line? ? xpos = col*vWidth + lastLineOffset + border_w*col // x position last line : xpos = col*vWidth + border_w*col + xoffset // x position non-last line ; ((row>top_rows-1)&(col>left_cols-1)&(row<top_rows+Nbig)&(col<left_cols+Nbig)) ? // if the grid number corresponds to being part of the big video ( ((bosscount == 0)&(boss>0)&(bossexpand!=1)) // if its the first of the big video then plot it ? ( gfx_blit( input_track(boss-1), presasp, // preserve aspect ratio border_w + xpos, // X position border_h + vHeight*(row) + border_h*(row) + ypos, // Y position Nbig*vWidth+(Nbig-1)*border_w,Nbig*vHeight+(Nbig-1)*border_h // output width and height ); ); bosscount = bosscount + 1; // increment counter ) : // else if the grid number is not part of the big video x-bosscount+1 < Ntracks // if this video number exists ? (vidnum = x-bosscount+1; vidnum < boss ? vidnum = vidnum-1; gfx_blit( input_track(vidnum), presasp, // preserve aspect ratio border_w + xpos, // X position border_h + vHeight*(row) + border_h*(row) + ypos, // Y position vWidth,vHeight // output width and height ); ); x += 1; ); ); Last edited by jak352; 05-13-2020 at 10:37 AM. Reason: Changed description to make it clear you can change background track and made use of case consistent |
![]() |
![]() |
![]() |
#35 |
Human being with feelings
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
|
![]()
Here's a version that allows for the lead track to resize continuously. Set "Expand Lead Track" to 0 and the lead track fits in the grid. Set "Expand Lead Track" to 1" and the lead track fills the whole video window (behind the other videos if "Lead to Front" is set to 0). You can use automation to make "Expand Lead Track" zoom between 0 and 1 for a cool effect during playback. Leaving "Expand Lead Track" set to 0 makes more sense if making a grid from portrait source videos.
You can choose to optimise for landscape or portrait source videos using the dial (assuming landscape output). With "Lead Video Width" set to 2 then the lead video (which can be chosen using "Lead Video Track" dial) will be twice as wide/tall and placed centrally and so on. Any number of videos then fit around it. You can also drag the y position of the whole thing using "Y Offset". Border size is set with "Grid Borders". Setting "Preserve Aspect" to 1 means videos/images will be stretched to fit the grid which can be helpful to get rid of any black spaces. Just place this code in the Video Processor in track 1. Put the videos you want in the grid in tracks 2 onwards. If you want a background image or background video (visible for non-zero Grid Borders values when Expand Lead Track is less than 1) while still preserving the video on the lead track within the grid then put an image or video in track 1 and set Background Color/Video to 1. Leave Background Color/Video on 0 if you want to specify a backround color using the RGB knobs instead. Images count as if they are videos and image items can be resized to fill space (to ensure tracks don't hop around if you don't want them to for instance). The default size/shape of the export video is set by the video or image in track 1 or track 2 if there's no background image/video in track 1. If you get low quality or output of the wrong size I recommend going to File>Project Settings>Video and setting the preserved video size to what you want (such as 1920 x 1080) and you might find it helps to tick "Always resize video sources..." and "Always resize video output...". It is possible to use automation on any of the parameters if you want to get fancy. Enjoy! Code:
// Grid of videos - automatically draws any number of videos from tracks with grid //@param 1:boss "Lead Video Track" 2 2 10 6 1 //@param 2:Nbig "Lead Video Width" 1 1 9 5 1 //@param 3:yposratio "Y Offset" 0 0 1 0.5 0.01 //@param 4:border "Grid Borders" 5 0 100 50 1 //@param 5:presasp "Preserve Aspect" 1 0 1 0.5 1 //@param 6:portrait "Landscape or Portrait" 0 0 1 0.5 1 //@param 7:background "Backdrop Color/Video" 0 0 1 0.5 1 //@param 8:R "Backdrop Red" 0.1 0 1 0.5 0.01 //@param 9:G "Backdrop Green" 0.1 0 1 0.5 0.01 //@param 10:B "Backdrop Blue" 0.5 0 1 0.5 0.01 //@param 11:bossexpand "Expand Lead Track" 0 0 1 0.5 0.01 //@param 12:bossfront "Lead to Front" 0 0 1 0.5 1 aspect = project_w/project_h; // aspect ratio of project boss = boss - 1; // boss is now relative to video processor track ypos = yposratio*project_h; ((boss>0)&(bossexpand==1)&(bossfront==1)) ? // if there is a lead track fully expanded on front then plot it gfx_blit( input_track(boss-1), presasp, // preserve aspect ratio 0, // X position 0, // Y position project_w,project_h // output width and height ) : // if there isn't a lead track on front then do the rest of the code ( Ntracks = input_track_count(); // Number of video files boss>Ntracks ? boss = Ntracks; // If the lead video track set is greater than Ntracks use last gfx_set(0); gfx_fillrect(0,0,project_w,project_h); x=0; // Counter for looping through grid entries Ntracks > 0 // If there are video tracks then get nonzero number of grid locations ? count_tracks = Ntracks + Nbig^2 - 1 // Number of grid locations filled : //else no grid count_tracks = 0 ; portrait == 0 ?// if landscape source videos ( xoffset = 0; border_h = border; border_w = border*aspect; height = project_h - border_h; width = project_w - border_w; cols = ceil(sqrt(count_tracks)); rows = ceil(count_tracks/cols); vHeight = height / cols - border_h; // Video height including half border*aspect each side vWidth = width / cols - border_w; // Video Width including half border*aspect each side ) : // else we assume portrait source videos need to be fitted into landscape output ( border_h = border*aspect; border_w = border; height = project_h - border_h; width = project_w - border_w; rows = ceil((sqrt(count_tracks))/aspect); cols = ceil(count_tracks/rows); rows_alt = rows - 1; cols_alt = ceil(count_tracks/rows_alt); rows*(aspect^2)>cols_alt ? (cols = cols_alt;rows = rows_alt;); // if reducing rows by one is more efficient rows<Nbig ? (rows = Nbig; cols = ceil(count_tracks/rows);); // if number of rows is less than Nbig vWidth = width / cols - border_w; // Video Width vHeight = height / rows - border_h; // Video Height aspect < (vHeight/vWidth) // if fitting to width and not tall enough ? (xoffset = 0; vHeight = vWidth*aspect;) // Replace video Height : // else fitting to height and not wide enough (vWidth = vHeight / aspect; // Replace video Width xoffset = (project_w - (cols*vWidth + (cols+1)*border_w))/2;) ); Nbig>1 ? // if one of the videos is chosen to be big ( left_cols = floor((cols - Nbig)/2); // Number of columns before big central video top_rows = floor((rows - Nbig)/2); // Number of rows before big central video ) : ( left_cols = 0; top_rows = 0; ); background == 1 ? gfx_blit(0) // If background is 1 then show current track image or video as background : ( gfx_set(R,G,B,1); gfx_fillrect(0,0,project_w,project_h); // else show color as background ); // if the lead track is behind plot it first bossfront==0 ? ( xpos = left_cols*vWidth + border_w*left_cols + xoffset; //xpos for boss if in front gfx_blit( input_track(boss-1), presasp, // preserve aspect ratio (1-bossexpand)*(border_w + xpos), // X position (1-bossexpand)*(border_h + vHeight*(top_rows) + border_h*(top_rows) + ypos), // Y position (1-bossexpand)*(Nbig*vWidth+(Nbig-1)*border_w) + bossexpand*project_w, (1-bossexpand)*(Nbig*vHeight+(Nbig-1)*border_h) + bossexpand*project_h // output width and height ); ); bosscount = 0; // Counter for taking into account grid positions for boss video loop(count_tracks, row = floor(x/cols); // Column position (starts at 0) col = x % cols; // Row position (starts at 0) lastLineCount = (count_tracks-1) % cols + 1; // Number of videos in last row lastLineOffset = (project_w - (lastLineCount*vWidth + (lastLineCount+1)*border_w))/2; ((x >= (cols*rows - cols))&(bosscount == Nbig^2)) // Is it the last line? ? xpos = col*vWidth + lastLineOffset + border_w*col // x position last line : xpos = col*vWidth + border_w*col + xoffset // x position non-last line ; ((row>top_rows-1)&(col>left_cols-1)&(row<top_rows+Nbig)&(col<left_cols+Nbig)) ? // if the grid number corresponds to being part of the big video bosscount = bosscount + 1 // increment counter : // else if the grid number is not part of the big video x-bosscount+1 < Ntracks // if this video number exists ? (vidnum = x-bosscount+1; vidnum < boss ? vidnum = vidnum-1; gfx_blit( input_track(vidnum), presasp, // preserve aspect ratio border_w + xpos, // X position border_h + vHeight*(row) + border_h*(row) + ypos, // Y position vWidth,vHeight // output width and height ); ); x += 1; ); //End of main loop bossfront==1 //If the boss is in front of everything else plot it now ? ( xpos = left_cols*vWidth + border_w*left_cols + xoffset; //xpos for boss if in front gfx_blit( input_track(boss-1), presasp, // preserve aspect ratio (1-bossexpand)*(border_w + xpos), // X position (1-bossexpand)*(border_h + vHeight*(top_rows) + border_h*(top_rows) + ypos), // Y position (1-bossexpand)*(Nbig*vWidth+(Nbig-1)*border_w) + bossexpand*project_w, (1-bossexpand)*(Nbig*vHeight+(Nbig-1)*border_h) + bossexpand*project_h // output width and height ); ); ); Last edited by jak352; 05-13-2020 at 01:50 PM. |
![]() |
![]() |
![]() |
#36 |
Human being with feelings
Join Date: Mar 2018
Location: Cologne
Posts: 1,362
|
![]()
Would be great to see some of your versions in a video or gif example. Your stuff is a really nice addition to reaper video processor.
many thanks Eli ![]()
__________________
☆.。.:*・°☆.。.:*・°☆.。.:*・°☆REAPER//✿◔‿◔)°☆.。.:*・°☆.。.:*・°☆
|
![]() |
![]() |
![]() |
#37 |
Human being with feelings
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
|
![]() |
![]() |
![]() |
![]() |
#38 |
Human being with feelings
Join Date: Apr 2010
Posts: 1,247
|
![]()
Jonathan, a new video on its way with your code.
http://www.facebook.com/robi.petric/...2262859777788/ Made another one with professional superstar hornplayers as well few days ago. Thanks! youtu.be/DPazNSxDDbM
__________________
W10 (64) Lenovo E540 - SSD; Lenovo B590; W7 (32), Compaq 610 (2.1Ghz core 2 duo, L2 cache, 2GB RAM); DPA 4018, Schoeps MK2, Schoeps MTSC 64, Neumann mk184, AEA Ribbon 88mk, AKG SolidTUBE; Focusrite Scarlett 18i20, recording merely live acoustic music. Last edited by urednik; 05-16-2020 at 04:21 PM. |
![]() |
![]() |
![]() |
#39 | |
Human being with feelings
Join Date: Mar 2018
Location: Cologne
Posts: 1,362
|
![]() Quote:
__________________
☆.。.:*・°☆.。.:*・°☆.。.:*・°☆REAPER//✿◔‿◔)°☆.。.:*・°☆.。.:*・°☆
|
|
![]() |
![]() |
![]() |
#40 |
Human being with feelings
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
|
![]()
Lead track can resize continuously. Set "Expand Lead Track" to 0 and the lead track fits in the grid. Set "Expand Lead Track" to 1" and the lead track fills the whole video window (behind the other videos if "Lead to Front" is set to 0 and this is handy when you have "Lead Grid Size" greater than 1). You can use automation to make "Expand Lead Track" zoom between 0 and 1 for a cool effect during playback. Leaving "Expand Lead Track" set to 0 makes more sense if making a grid from portrait source videos.
You can choose to optimise for landscape or portrait source videos using the dial (and this code assumes landscape output). With "Lead Grid Size" set to 2 then the lead video (which can be chosen using "Lead Track Number" dial) will be twice as wide/tall and placed centrally and so on. Any number of videos then fit around it. You can also drag the y position of the whole thing using "Y Offset". Border size is set with "Grid Borders". Setting "Preserve Aspect" to 1 means videos/images will be stretched to fit the grid which can be helpful to get rid of any black spaces. Just place this code in the Video Processor in track 1. Put the videos you want in the grid in tracks 2 onwards. If you want a background image or background video (visible for non-zero Grid Borders values when Expand Lead Track is less than 1) while still preserving the video on the lead track within the grid then put an image or video in track 1 and set Background Color/Video to 1. Leave Background Color/Video on 0 if you want to specify a backround color using the RGB knobs instead. Images count as if they are videos and image items can be resized to fill space (to ensure tracks don't hop around if you don't want them to for instance). The default size/shape of the export video is set by the video or image in track 1 or track 2 if there's no background image/video in track 1. If you get low quality or output of the wrong size I recommend going to File>Project Settings>Video and setting the preserved video size to what you want (such as 1920 x 1080) and you might find it helps to tick "Always resize video sources..." and "Always resize video output...". It is possible to use automation on any of the parameters if you want to get fancy. Enjoy! Code:
// Grid of videos - automatically draws any number of videos from tracks with grid //@param 1:boss "Lead Track Number" 2 2 10 6 1 //@param 2:Nbig "Lead Grid Size" 1 1 9 5 1 //@param 3:bossexpand "Expand Lead Track" 0 0 1 0.5 0.01 //@param 4:bossfront "Lead to Front" 0 0 1 0.5 1 //@param 5:yposratio "Y Offset" 0 0 1 0.5 0.01 //@param 6:border "Grid Borders" 5 0 720 360 1 //@param 7:presasp "Preserve Aspect" 1 0 1 0.5 1 //@param 8:portrait "Landscape or Portrait" 0 0 1 0.5 1 //@param 9:background "Backdrop Color/Video" 0 0 1 0.5 1 //@param 10:R "Backdrop Red" 0.1 0 1 0.5 0.01 //@param 11:G "Backdrop Green" 0.1 0 1 0.5 0.01 //@param 12:B "Backdrop Blue" 0.5 0 1 0.5 0.01 aspect = project_w/project_h; // aspect ratio of project boss = boss - 1; // boss is now relative to video processor track ypos = yposratio*project_h; Ntracks = input_track_count(); // Number of video files boss>Ntracks ? boss = Ntracks; // If the lead video track set is greater than Ntracks use last ((boss>0)&(bossexpand==1)&(bossfront==1)) ? // if there is a lead track fully expanded on front then plot it gfx_blit( input_track(boss-1), presasp, // preserve aspect ratio 0, // X position 0, // Y position project_w,project_h // output width and height ) : // if there isn't a lead track on front then do the rest of the code ( gfx_set(0); gfx_fillrect(0,0,project_w,project_h); x=0; // Counter for looping through grid entries Ntracks > 0 // If there are video tracks then get nonzero number of grid locations ? count_tracks = Ntracks + Nbig^2 - 1 // Number of grid locations filled : //else no grid count_tracks = 0 ; portrait == 0 ?// if landscape source videos ( xoffset = 0; border_h = border; border_w = border*aspect; height = project_h - border_h; width = project_w - border_w; cols = ceil(sqrt(count_tracks)); rows = ceil(count_tracks/cols); vHeight = height / cols - border_h; // Video height including half border*aspect each side vWidth = width / cols - border_w; // Video Width including half border*aspect each side ) : // else we assume portrait source videos need to be fitted into landscape output ( border_h = border*aspect; border_w = border; height = project_h - border_h; width = project_w - border_w; rows = ceil((sqrt(count_tracks))/aspect); cols = ceil(count_tracks/rows); rows_alt = rows - 1; cols_alt = ceil(count_tracks/rows_alt); rows*(aspect^2)>cols_alt ? (cols = cols_alt;rows = rows_alt;); // if reducing rows by one is more efficient rows<Nbig ? (rows = Nbig; cols = ceil(count_tracks/rows);); // if number of rows is less than Nbig vWidth = width / cols - border_w; // Video Width vHeight = height / rows - border_h; // Video Height aspect < (vHeight/vWidth) // if fitting to width and not tall enough ? (xoffset = 0; vHeight = vWidth*aspect;) // Replace video Height : // else fitting to height and not wide enough (vWidth = vHeight / aspect; // Replace video Width xoffset = (project_w - (cols*vWidth + (cols+1)*border_w))/2;) ); Nbig>1 ? // if one of the videos is chosen to be big then put lead track in centre ( left_cols = floor((cols - Nbig)/2); // Number of columns before big central video top_rows = floor((rows - Nbig)/2); // Number of rows before big central video ) : // else all videos same size then lead tracks stays where it is ( top_rows = floor((boss-1)/cols); left_cols = (boss-1) % cols; ); background == 1 ? gfx_blit(0) // If background is 1 then show current track image or video as background : ( gfx_set(R,G,B,1); //Set color for background gfx_fillrect(0,0,project_w,project_h); // show color as background ); bossfront==0 // if the lead track is behind plot it first ? ( (boss-1 >= (cols*rows - cols)) // Is it the last line? ? ( lastLineCount = (count_tracks-1) % cols + 1; // Number of videos in last row lastLineOffset = (project_w - (lastLineCount*vWidth + (lastLineCount+1)*border_w))/2; xpos = left_cols*vWidth + lastLineOffset + border_w*left_cols; // x position last line ) : xpos = left_cols*vWidth + border_w*left_cols + xoffset; // x position non-last line gfx_blit( input_track(boss-1), presasp, // preserve aspect ratio (1-bossexpand)*(border_w + xpos), // X position (1-bossexpand)*(border_h + vHeight*(top_rows) + border_h*(top_rows) + ypos), // Y position (1-bossexpand)*(Nbig*vWidth+(Nbig-1)*border_w) + bossexpand*project_w, (1-bossexpand)*(Nbig*vHeight+(Nbig-1)*border_h) + bossexpand*project_h // output width and height ); ); bosscount = 0; // Counter for taking into account grid positions for boss video loop(count_tracks, //main loop for plotting grid row = floor(x/cols); // Column position (starts at 0) col = x % cols; // Row position (starts at 0) lastLineCount = (count_tracks-1) % cols + 1; // Number of videos in last row lastLineOffset = (project_w - (lastLineCount*vWidth + (lastLineCount+1)*border_w))/2; ((x >= (cols*rows - cols))&(bosscount > Nbig^2 - 2)) // Is it the last line and after any big video? ? xpos = col*vWidth + lastLineOffset + border_w*col // x position last line : xpos = col*vWidth + border_w*col + xoffset // x position non-last line ; ((row>top_rows-1)&(col>left_cols-1)&(row<top_rows+Nbig)&(col<left_cols+Nbig)) ? // if the grid number corresponds to being part of the big video bosscount = bosscount + 1 // increment counter : // else if the grid number is not part of the big video x-bosscount+1 < Ntracks // if this video number exists ? (vidnum = x-bosscount+1; vidnum < boss ? vidnum = vidnum-1; gfx_blit( input_track(vidnum), presasp, // preserve aspect ratio border_w + xpos, // X position border_h + vHeight*(row) + border_h*(row) + ypos, // Y position vWidth,vHeight // output width and height ); ); x += 1; ); //End of main loop bossfront==1 //If the boss is in front of everything else plot it now ? ( (boss-1 >= (cols*rows - cols)) // Is it the last line? ? ( lastLineCount = (count_tracks-1) % cols + 1; // Number of videos in last row lastLineOffset = (project_w - (lastLineCount*vWidth + (lastLineCount+1)*border_w))/2; xpos = left_cols*vWidth + lastLineOffset + border_w*left_cols; // x position last line ) : //else not the last line xpos = left_cols*vWidth + border_w*left_cols + xoffset; // x position non-last line gfx_blit( input_track(boss-1), presasp, // preserve aspect ratio (1-bossexpand)*(border_w + xpos), // X position (1-bossexpand)*(border_h + vHeight*(top_rows) + border_h*(top_rows) + ypos), // Y position (1-bossexpand)*(Nbig*vWidth+(Nbig-1)*border_w) + bossexpand*project_w, (1-bossexpand)*(Nbig*vHeight+(Nbig-1)*border_h) + bossexpand*project_h // output width and height ); ); ); |
![]() |
![]() |
![]() |
Thread Tools | |
Display Modes | |
|
|