Old 05-22-2020, 08:13 AM   #1
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
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
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
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: 7,417
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: 3,451
Default

Thank you very much Fabian!!
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
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: 3,451
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..
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

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: 3,451
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?
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

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: 3,451
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..
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

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: 3,451
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.
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

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: 7,571
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: 3,451
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) );
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

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: 7,571
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,362
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: 3,451
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!
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
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
Old 07-17-2020, 05:30 AM   #15
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 1,362
Default

Quote:
Originally Posted by FanClay View Post
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, this is not about cropping video in general but about doing it with the video processor in Reaper. If you want to know how to do it in Reaper, just ask in this forum and I'm sure someone will explain it even for a tech idiot.

Greetings
ELi
__________________
☆.。.:*・°☆.。.:*・°☆.。.:*・°☆REAPER//✿◔‿◔)°☆.。.:*・°☆.。.:*・°☆
Eliseat is offline   Reply With Quote
Old 07-25-2020, 08:01 PM   #16
Eisenspalter
Human being with feelings
 
Join Date: May 2017
Posts: 125
Default

Great. I was looking for that.
Many thanks
Eisenspalter is offline   Reply With Quote
Old 08-08-2022, 06:16 AM   #17
valankar
Human being with feelings
 
Join Date: Jan 2016
Location: Switzerland
Posts: 130
Default

Just a quick question, is there a way to move the resulting cropped image to a different part of the screen? I tried using a 'Track opacity/zoom/pan' after this, but it doesn't seem to do what I'd like.
valankar is offline   Reply With Quote
Old 02-15-2023, 12:01 PM   #18
jak352
Human being with feelings
 
Join Date: Apr 2017
Location: Scotland, UK
Posts: 56
Default

Quote:
Originally Posted by valankar View Post
Just a quick question, is there a way to move the resulting cropped image to a different part of the screen? I tried using a 'Track opacity/zoom/pan' after this, but it doesn't seem to do what I'd like.
Here's a version based on the above with simple pan and zoom controls to do this. I've not checked it very carefully but seems to work:

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
//@param9:x_pan 'x pan' 0 -1 1 0 0.01
//@param10:y_pan 'y pan' 0 -1 1 0 0.01
//@param11:zoom 'zoom' 1 0 2 1 0.01

back = back == 0 ? -5000 : 1;
gfx_blit(back);
input_info(0, w, h);
gfx_blit(0, 1, 
-x_pan*w + (w_size*w)/2, -y_pan*h + (h_size*h)/2, 
zoom*(w - (w_size*w)), zoom*(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 jak352; 02-15-2023 at 01:26 PM.
jak352 is offline   Reply With Quote
Old 02-16-2023, 07:13 AM   #19
valankar
Human being with feelings
 
Join Date: Jan 2016
Location: Switzerland
Posts: 130
Default

Quote:
Originally Posted by jak352 View Post
Here's a version based on the above with simple pan and zoom controls to do this. I've not checked it very carefully but seems to work:
Awesome, it works great!

Perhaps unrelated, but is there a standard way in video to do something like transparent background? For example, I can record on my webcam with background removal. However when I overlay this webcam video, the background is black.

If I use something like Bandicam that records the webcam overlayed on the video, that black background is transparent. Is there a way to do that when overlaying images in Reaper? I figure it is something simple that I just can't figure out heh.
valankar is offline   Reply With Quote
Old 02-16-2023, 07:54 AM   #20
papagirafe
Human being with feelings
 
papagirafe's Avatar
 
Join Date: Aug 2020
Location: Brasil
Posts: 679
Default

Quote:
Originally Posted by valankar View Post
Awesome, it works great!

Perhaps unrelated, but is there a standard way in video to do something like transparent background? For example, I can record on my webcam with background removal. However when I overlay this webcam video, the background is black.

If I use something like Bandicam that records the webcam overlayed on the video, that black background is transparent. Is there a way to do that when overlaying images in Reaper? I figure it is something simple that I just can't figure out heh.
I succeeded with transparent video under very specific settings. Please open a new thread on this because it's going to trigger a lot interest I am sure... :-)
papagirafe is offline   Reply With Quote
Old 10-02-2023, 09:13 AM   #21
cporro
Human being with feelings
 
cporro's Avatar
 
Join Date: Jul 2010
Location: San Francisco, CA
Posts: 250
Default

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

[code]
//Overlay w/crop
much thanks for this. it's exactly what i needed. crop with controls for top bottom left and right and is an overlay for below video. along with a zoom and x/y offset i can control everything i need to for cropped video. much yay.
cporro 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 10:22 PM.


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