Old 05-22-2020, 08:13 AM   #1
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 2,081
Default Script to crop video sides?

Does something like that exist? A script that can put black on both sides of the video and can move the image (horizontal offset) in the new box in the middle.


big pic
amagalma is offline   Reply With Quote
Old 05-22-2020, 11:12 AM   #2
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 5,720
Default

I had the need for a crop tool:

Code:
// Crop tool by M Fabian
src=0;
//@param1:x_coord 'x coord' 0
//@param2:y_coord 'y coord' 0
//@param3:width 'width' 1 
//@param4:height 'height' 1 

input_info(src,w,h) ? ( project_w=w; project_h=h; ); // preserve input dimensions
gfx_dest = mybuf = gfx_img_resize(mybuf, project_w, project_h, 1);
gfx_blit(src, 0, 
  x_coord*project_w,  y_coord*project_h, 
  (width-x_coord)*project_w, (height-y_coord)*project_h,
  x_coord*project_w,  y_coord*project_h, 
  (width-x_coord)*project_w, (height-y_coord)*project_h);

gfx_dest = -1; // main framebuffer
gfx_blit(mybuf);
It doesn't move the image, but that's easy enough to add.
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian is offline   Reply With Quote
Old 05-22-2020, 12:41 PM   #3
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 2,081
Default

Thank you very much Fabian!!
amagalma is offline   Reply With Quote
Old 05-22-2020, 01:18 PM   #4
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 2,081
Default

I am trying to combine a simple code for moving the image with your code:
Code:
//@param1:xoffs 'X offset' 0 -1 1 0 0.01
//@param2:yoffs 'Y offset' 0 -1 1 0 0.01
//@param3:x_coord 'x coord' 0
//@param4:y_coord 'y coord' 0

input_info(0,w,h);
gfx_blit(-1);
x = xoffs*w;
y = yoffs*h;
gfx_blit(0,1, x,y);

width = 1 - x_coord;
height = 1 - y_coord;
mybuf = gfx_img_resize(-1, w, h, 1);
gfx_blit(0, 0,
  x_coord*w, y_coord*h,
  (width-x_coord)*w, (height-y_coord)*h,
  x_coord*w, y_coord*h,
  (width-x_coord)*w, (height-y_coord)*h);
gfx_blit(mybuf);
But something I am doing wrong.. I think I don't really understand the blitting, the buffers etc.. I must study a little this..

Last edited by amagalma; 05-22-2020 at 01:57 PM.
amagalma is offline   Reply With Quote
Old 05-23-2020, 09:09 AM   #5
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 2,081
Default

I have tried this too:
Code:
//@param1:x_pos 'Horiz Shift' 0 -1 1 0 0.01
//@param2:y_pos 'Vert Shift' 0 -1 1 0 0.01
//@param3:w_size 'Horizontal Curtains' 0 0 1 0.5 0.01
//@param4:h_size 'Vertical Curtains' 0 0 1 0.5 0.01
input_info(0, w, h);
gfx_blit(0, 1, 0, 0, w, h, -x_pos*w, y_pos*h, w, h );
w_size != 0 ? (
  w_size = w*w_size;
  gfx_fillrect(0,0,w_size,h);
  gfx_fillrect(w-w_size,0,w_size,h);
);
h_size != 0 ? (
  h_size = h*h_size;
  gfx_fillrect(0,0,w,h_size);
  gfx_fillrect(0,h-h_size,w,h_size);
);

But it either flickers or is very slow to react when changing values in realtime. Anyone got any idea why?

Last edited by amagalma; 05-24-2020 at 03:00 AM.
amagalma is offline   Reply With Quote
Old 05-23-2020, 03:56 PM   #6
briff
Human being with feelings
 
Join Date: Jul 2011
Posts: 12
Default

Quote:
Originally Posted by amagalma View Post
Does something like that exist? A script that can put black on both sides of the video and can move the image (horizontal offset) in the new box in the middle.
I extended the Image overlay preset, and it seems to work:

Code:
//Overlay w/crop
//@param1:opacity 'opacity' 1
//@param2:zoom 'zoom' 0 -15 15 0
//@param3:xoffs 'X offset' 0 -1 1 0
//@param4:yoffs 'Y offset' 0 -1 1 0
//@param6:filter 'filter' 0 0 1 0.5 1
//@param7:use_srca 'alpha channel' 1 0 1 0.5 1
//@param9:cropL 'Crop left' 0 0 1
//@param10:cropR 'Crop right' 0 0 1
//@param11:cropT 'Crop top' 0 0 1
//@param12:cropB 'Crop bottom' 0 0 1

img1=input_track(0);
img2=0;
use_srca && img2 != img1 ? colorspace='RGBA';
input_info(img1,img1w,img1h) && project_wh_valid===0 ?  ( project_w = img1w; project_h = img1h; );

a = opacity < 0.01 ? 0 : opacity > 0.99 ? 1 : opacity;

img2 != img1 && input_info(img2,sw,sh) ? (
  gfx_blit(img1,0);
  a>0?(
    gfx_a=a;
    gfx_mode = (filter>0.5 ? 256 : 0)|(use_srca?0x10000:0);
    z = 10^(zoom/10);
    dw = (sw*z)|0;
    dh = (sh*z)|0;
    x = (project_w - dw + (project_w + dw)*xoffs)*.5;
    y = (project_h - dh + (project_h + dh)*yoffs)*.5;
    //gfx_img_resize(img2, dw*(1-cropL-cropR), dh*(1-cropT-cropB));
    gfx_blit(img2,0, 
      x+dw*cropL|0, 
      y+dh*cropT|0, 
      dw*(1-cropL-cropR),
      dh*(1-cropT-cropB), 
      sw*cropL, 
      sh*cropT, 
      sw*(1-cropL-cropR), 
      sh*(1-cropT-cropB));
    
    
  );
);
briff is offline   Reply With Quote
Old 05-24-2020, 01:05 AM   #7
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 2,081
Default

Quote:
Originally Posted by briff View Post
I extended the Image overlay preset, and it seems to work:

Code:
//Overlay w/crop
//@param1:opacity 'opacity' 1
//@param2:zoom 'zoom' 0 -15 15 0
//@param3:xoffs 'X offset' 0 -1 1 0
//@param4:yoffs 'Y offset' 0 -1 1 0
//@param6:filter 'filter' 0 0 1 0.5 1
//@param7:use_srca 'alpha channel' 1 0 1 0.5 1
//@param9:cropL 'Crop left' 0 0 1
//@param10:cropR 'Crop right' 0 0 1
//@param11:cropT 'Crop top' 0 0 1
//@param12:cropB 'Crop bottom' 0 0 1

img1=input_track(0);
img2=0;
use_srca && img2 != img1 ? colorspace='RGBA';
input_info(img1,img1w,img1h) && project_wh_valid===0 ?  ( project_w = img1w; project_h = img1h; );

a = opacity < 0.01 ? 0 : opacity > 0.99 ? 1 : opacity;

img2 != img1 && input_info(img2,sw,sh) ? (
  gfx_blit(img1,0);
  a>0?(
    gfx_a=a;
    gfx_mode = (filter>0.5 ? 256 : 0)|(use_srca?0x10000:0);
    z = 10^(zoom/10);
    dw = (sw*z)|0;
    dh = (sh*z)|0;
    x = (project_w - dw + (project_w + dw)*xoffs)*.5;
    y = (project_h - dh + (project_h + dh)*yoffs)*.5;
    //gfx_img_resize(img2, dw*(1-cropL-cropR), dh*(1-cropT-cropB));
    gfx_blit(img2,0, 
      x+dw*cropL|0, 
      y+dh*cropT|0, 
      dw*(1-cropL-cropR),
      dh*(1-cropT-cropB), 
      sw*cropL, 
      sh*cropT, 
      sw*(1-cropL-cropR), 
      sh*(1-cropT-cropB));
    
    
  );
);

Thanks! Although it does not move the image inside the black "curtains" on the sides.

The code could be reduced down to this:
Code:
//Crop/offset
//@param1:xoffs 'X offset' 0 -1 1 0
//@param2:yoffs 'Y offset' 0 -1 1 0
//@param4:cropL 'Crop left' 0 0 1
//@param5:cropR 'Crop right' 0 0 1
//@param7:cropT 'Crop top' 0 0 1
//@param8:cropB 'Crop bottom' 0 0 1

input_info(0,sw,sh);
gfx_blit(-1,0);
x = (project_w - sw + (project_w + sw)*xoffs)*.5;
y = (project_h - sh + (project_h + sh)*yoffs)*.5;
gfx_blit(0,0, 
  x+sw*cropL|0, 
  y+sh*cropT|0, 
  sw*(1-cropL-cropR),
  sh*(1-cropT-cropB), 
  sw*cropL, 
  sh*cropT, 
  sw*(1-cropL-cropR), 
  sh*(1-cropT-cropB));
I think if I study each one of these I may understand how they work, which one works better. has less CPU cost etc..

Last edited by amagalma; 05-24-2020 at 01:21 AM.
amagalma is offline   Reply With Quote
Old 05-24-2020, 02:47 AM   #8
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 2,081
Default

Quote:
Originally Posted by amagalma View Post
I have tried this too:
Code:
//@param1:x_pos 'Horiz Shift' 0 -1 1 0 0.01
//@param2:y_pos 'Vert Shift' 0 -1 1 0 0.01
//@param3:w_size 'Horizontal Curtains' 0 0 1 0.5 0.01
//@param4:h_size 'Vertical Curtains' 0 0 1 0.5 0.01
input_info(0, w, h);
gfx_blit(0, 1, 0, 0, w, h, -x_pos*w, y_pos*h, w, h );
w_size != 0 ? (
  w_size = w*w_size;
  gfx_fillrect(0,0,w_size,h);
  gfx_fillrect(w-w_size,0,w_size,h);
);
h_size != 0 ? (
  h_size = h*h_size;
  gfx_fillrect(0,0,w,h_size);
  gfx_fillrect(0,h-h_size,w,h_size);
);
But it either flickers or is very slow to react when changing values. Anyone got any idea why?

And yet another variation:
Code:
//@param1:x_pos 'Horiz Shift' 0 -1 1 0 0.01
//@param2:y_pos 'Vert Shift' 0 -1 1 0 0.01
//@param3:w_size 'Horizontal Curtains' 0 0 1 0.5 0.01
//@param4:h_size 'Vertical Curtains' 0 0 1 0.5 0.01
input_info(0, w, h);
blank = -5000;
gfx_blit(0, 1, 0, 0, w, h, -x_pos*w, y_pos*h, w, h );
w_size != 0 ? (
  gfx_blit(blank, 0, 0, 0, w*w_size/2, h);
  gfx_blit(blank, 0, w-w*w_size/2, 0);
);
h_size != 0 ? (
  gfx_blit(blank, 0, 0, 0, w, h*h_size/2);
  gfx_blit(blank, 0, 0, h-h*h_size/2);
);
Edit. Measured them and they are exactly the same CPU-wise. 128 instances take 0.06% of CPU usage.. There is not any flickering at all, but when changing values in realtime the changes are not applied immediately.

Last edited by amagalma; 05-24-2020 at 03:00 AM.
amagalma is offline   Reply With Quote
Old 05-31-2020, 10:28 AM   #9
EpicSounds
Human being with feelings
 
EpicSounds's Avatar
 
Join Date: Jul 2009
Posts: 5,865
Default

while this does crop the image, it's not passing through any image/video on tracks below.
__________________
REAPER Video Tutorials, Tips & Tricks and more at The REAPER Blog
EpicSounds is offline   Reply With Quote
Old 06-01-2020, 01:25 AM   #10
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 2,081
Default

You mean being able to see the images below instead of black? Because I wanted it this way: to have black "curtains".

This will let the behind image to pass through:
Code:
// Crop Image (let behind image through)
//@param1:x_pos 'Horiz Shift' 0 -1 1 0 0.01
//@param2:y_pos 'Vert Shift' 0 -1 1 0 0.01
//@param3:w_size 'Horizontal Curtains' 0 0 1 0.5 0.01
//@param4:h_size 'Vertical Curtains' 0 0 1 0.5 0.01
input_info(0, w, h);
other = 1;
gfx_blit(0, 1, 0, 0, w, h, -x_pos*w, y_pos*h, w, h );
w_size != 0 ? (
  w_amount = w*w_size/2;
  gfx_blit(other, 1, 0, 0,w_amount, h, 0, 0, w_amount, h );
  gfx_blit(other, 1, w-w_amount, 0, w_amount, h, w-w_amount, 0, w_amount, h);
);
h_size != 0 ? (
  h_amount = h*h_size/2;
  gfx_blit(other, 1, 0, 0, w, h_amount, 0, 0, w, h_amount);
  gfx_blit(other, 1, 0, h-h_amount, w, h_amount, 0, h-h_amount, w, h_amount);
);
EDIT:
Greatly optimized alternative:
Code:
// Crop Image (optional let behind image through)
//@param1:w_size 'Horizontal Crop' 0 0 1 0.5 0.01
//@param2:x_pos 'Fine tune x_pos' 0 -1 1 0 0.01
//@param4:h_size 'Vertical Crop' 0 0 1 0.5 0.01
//@param5:y_pos 'Fine tune y_pos' 0 -1 1 0 0.01
//@param7:back 'Let back image' 0 0 1 0.5 1

back = back == 0 ? -5000 : 1;
gfx_blit(back);
input_info(0, w, h);
gfx_blit(0, 1, 
(w_size*w)/2, (h_size*h)/2, 
w - (w_size*w), h - (h_size*h), 
(w_size*w)/2 - x_pos*(w_size*w)/2, (h_size*h)/2 - y_pos*(h_size*h)/2, 
w - (w_size*w), h - (h_size*h) );

Last edited by amagalma; 06-02-2020 at 07:50 AM.
amagalma is offline   Reply With Quote
Old 06-01-2020, 08:39 AM   #11
EpicSounds
Human being with feelings
 
EpicSounds's Avatar
 
Join Date: Jul 2009
Posts: 5,865
Default

thanks for that. I wasn't actually requesting it, just pointing it out. A lot of people buy my video tools class just for the ability to crop.
You've done this in a different way than mine so I'll hang on to it.

More people making video scripts is a very good thing for the community. Keep it up!
__________________
REAPER Video Tutorials, Tips & Tricks and more at The REAPER Blog
EpicSounds is offline   Reply With Quote
Old 06-01-2020, 10:03 AM   #12
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 1,235
Default

Amazing.

Many thanks
__________________
☆.。.:*・°☆.。.:*・°☆.。.:*・°☆REAPER//✿◔‿◔)°☆.。.:*・°☆.。.:*・°☆
Eliseat is offline   Reply With Quote
Old 06-02-2020, 07:56 AM   #13
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 2,081
Default

Quote:
Originally Posted by EpicSounds View Post
thanks for that. I wasn't actually requesting it, just pointing it out. A lot of people buy my video tools class just for the ability to crop.
You've done this in a different way than mine so I'll hang on to it.

More people making video scripts is a very good thing for the community. Keep it up!
I am experimenting with this (video processor) and post for two reasons: either because some may find it useful too, or because maybe some one pops-up and shouts "what the hell are you doing? you're doing it wrong!!" .. and hopefully corrects it!
amagalma is offline   Reply With Quote
Old 06-02-2020, 11:58 PM   #14
FanClay
Human being with feelings
 
Join Date: May 2020
Location: Tokyo, JP
Posts: 4
Default

I'm a tech idiot, so I just tried some simple and intuitive tools to edit videos. I found an ultimate review of video cropping software on google. If other newbies like me come across this thread, I hope this helps.
https://www.videoproc.com/video-edit...eo-cropper.htm
FanClay is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:14 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.