View Single Post
Old 05-14-2019, 07:31 AM   #1
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 15,721
Default Video cut detection processor (and ReaScript to add markers)

I posted this in another thread but it really belongs here:

version that detects hue changes more than anything:
Code:
//cut detector (color-change detection)
//@param pixchgcnt "pixel change count" 40 1 99 50 1
//@param distchg   "color change thresh" 50 0 100 50 1
//@gmem=cutdetect

input=0;
colorspace='YV12';
input_info(input,project_w,project_h);
gfx_blit(input);

is_chg=0;
lf ? (
  code = "
    (sqr(su-u) + sqr(sv-v)) > thr ? (c1 += 1);
  ";  
  c1 = 0;
  thr = distchg * 41 / 100;
  cntreq=pixchgcnt * (project_w*project_h*.25*.01);
  gfx_evalrect(0,0,project_w,project_h,code,1|2,lf);
  
  is_chg = (c1 > cntreq);
  gfx_img_free(lf);
);
lf = gfx_img_hold(input);

is_chg && gmem[0] == 0 ? (
  last_project_time==0 || 
    project_time > last_project_time + 1.0 || 
    project_time < last_project_time-1.0 ? 
  (    
    gmem[0] = project_time;
    last_project_time = project_time;
    last_project_time == 0.0 ? last_project_time = 0.00000001;    
  );
);
version that detects luminance changes
Code:
//cut detector (luminance-change)
//@param pixchgcnt "pixel change count" 40 1 99 50 1
//@param distchg   "color change thresh" 50 0 100 50 1
//@gmem=cutdetect

input=0;
colorspace='YV12';
input_info(input,project_w,project_h);
gfx_blit(input);

is_chg=0;
lf ? (
  code = "
    sqr(sy1-y1)+sqr(sy2-y2)+sqr(sy3-y3)+sqr(sy4-y4) > thr ? (c1 += 1);
  ";  
  c1 = 0;
  thr = distchg * 41 / 100;
  cntreq=pixchgcnt * (project_w*project_h*.25*.01);
  gfx_evalrect(0,0,project_w,project_h,code,1|2,lf);
  
  is_chg = (c1 > cntreq);
  gfx_img_free(lf);
);
lf = gfx_img_hold(input);

is_chg && gmem[0] == 0 ? (
  last_project_time==0 || 
    project_time > last_project_time + 1.0 || 
    project_time < last_project_time-1.0 ? 
  (    
    gmem[0] = project_time;
    last_project_time = project_time;
    last_project_time == 0.0 ? last_project_time = 0.00000001;    
  );
);
(both of these will require threshold tweaks without any doubt)

And an EEL reascript which adds markers in response to it:

Code:
//@gmem=cutdetect

function run() (
  a = gmem[0];
  a != 0.0 ? (
    gmem[0] = 0.0;
    AddProjectMarker(0, 0, a, 0, "cut", -1);
  );
  defer("run();");
);

run();
Justin is offline   Reply With Quote