Old 05-22-2020, 08:13 AM   #1
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 2,018
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 online now   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,697
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,018
Default

Thank you very much Fabian!!
amagalma is online now   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,018
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 online now   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,018
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; Yesterday at 03:00 AM.
amagalma is online now   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 Yesterday, 01:05 AM   #7
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 2,018
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; Yesterday at 01:21 AM.
amagalma is online now   Reply With Quote
Old Yesterday, 02:47 AM   #8
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 2,018
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; Yesterday at 03:00 AM.
amagalma is online now   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 12:51 AM.


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