|
05-14-2019, 07:31 AM | #1 |
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 15,721
|
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; ); ); 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; ); ); 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(); |
05-14-2019, 07:44 AM | #2 |
Human being with feelings
Join Date: Sep 2018
Location: China
Posts: 565
|
Thanks, Justin!
|
05-14-2019, 07:40 PM | #3 |
Human being with feelings
Join Date: Sep 2018
Location: China
Posts: 565
|
@Justin
I wrote a lua script to creat the marker Code:
it=reaper.GetSelectedMediaItem(0, 0) start=reaper.GetMediaItemInfo_Value(it, "D_POSITION") length=reaper.GetMediaItemInfo_Value(it, "D_LENGTH") fr=reaper.SNM_GetIntConfigVar("projfrbase", -1) d=1/fr reaper.gmem_attach("cutdetect") reaper.gmem_write(0, 0.0) time=math.ceil(length/d) reaper.SetEditCurPos(start, 0, 0) for i=1, time do cur=reaper.GetCursorPosition() reaper.SetEditCurPos(cur+d, 0, 1) pos=reaper.gmem_read(0) if pos~=0 then reaper.AddProjectMarker2(0, 0, pos, 0, "cut:"..i, reaper.CountProjectMarkers(0), 16777471) reaper.gmem_write(0, 0.0) end end |
05-15-2019, 06:53 AM | #5 |
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 15,721
|
|
05-15-2019, 09:51 AM | #6 | |
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,623
|
Quote:
https://forum.cockos.com/showpost.ph...2&postcount=21
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish On vacation for the time being... |
|
05-15-2019, 11:30 AM | #7 |
Human being with feelings
Join Date: Sep 2018
Location: China
Posts: 565
|
Thanks Justin and mespotine. Yes running in defer doesn't block the GUI, but it runs as slowly as I play the whole video. Is there any way to get all those gmem[0]~=0 value without actually playing the video?
|
05-15-2019, 02:42 PM | #8 |
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 15,721
|
Nope, but you could crank up the project playrate to 4x to get it to run faster...
|
Thread Tools | |
Display Modes | |
|
|