Advertisement
Seedmanc

im@s2 questionboxes detection

Apr 30th, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ffmpegsource2("C:\Users\Seedmanc\Desktop\[765subs] Ganaha Hibiki - Episode 10.mp4")  
  2. ConvertToYV12                   # just to make sure we are in right colorspace no matter what the source is                    
  3. # boxes sizes
  4. w=round(312*width/(1280*2)) *2          # this way we get independent from source resolution
  5. h=round(120*height/(720*2)) *2          # having boxes' coordinates relative instead of absolute
  6. # coordinates of left box
  7. xb=round(196*width/(1280*2)) *2         # also this ensures mod2 rule, since video in YV12 format
  8. yb=round(322*height/(720*2)) *2         # must have even dimensions          
  9. # coordinates of right box
  10. xr=round(770*width/(1280*2)) *2      
  11. yr=round(322*height/(720*2)) *2                              
  12. # we don't need third box, as it is not always present
  13. src1= crop(xb,yb,w,h).blur(1.58)        #source video area of left box
  14. bluemask=src1.maskhs(starthue=360-45,endhue=360-7,maxsat=70,minsat=5).converttoyv12.mt_inflate.mt_expand
  15. # ^ selection by color blue
  16. src2= crop(xr,yr,w,h).blur(1.58)        #source video area of right box
  17. redmask = src2. maskhs(starthue=60, endhue=120, maxsat=75, minsat=10 ) .converttoyv12. mt_inflate. mt_expand
  18. # ^ selection by color red
  19. comb=mt_logic(bluemask, redmask, mode="min")                
  20. # ^ combining masks by AND operator - so that detection happens only when both boxes are found
  21. scriptclip("""AverageLuma(comb )>245 ? \
  22. invert : \
  23. last""")
  24. __END__
  25. Here it simply switches to inverted colors when it detects question boxes appearing, just to show that it works.
  26. 245 is the threshold of detection, lower values will make it happen earlier and last longer (since those boxes slide in and out gradually) with the chance of false detection, higher values will do the opposite.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement