Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ffmpegSource2("C:\Users\Seedmanc\Desktop\guiminer\avisynth\imas_question_pause.mkv")
- #Settings:
- global filename = "c:\Users\Seedmanc\Desktop\guiminer\avisynth\subhelp\subtitle.ass"
- global stringtemplate = "Dialogue: 0,0:00:00.00,0:00:01.00,Style,Actor,0000,0000,0000,,"
- global shift = 0 # Shift of subtitle line placement in milliseconds, relative to time of detection. Both starting and ending times are affected
- global mult = 1.0 # Multiplier of subtitle line duration relative to detected on-screen duration. You'll likely want to increase it.
- global debug = true # Controls visual indication and writebuffer flushing. Without them script runs at ~600 fps.
- global overwrite = false # Overwrites output file instead of appending to it. Useful while testing.
- global TBlowthr = 185 # Detection lower threshold, separates textbox from darker background.
- # Raising will delay detection until textbox fully appears, but might fail to catch textboxes with lots of text.
- # Lower values might result in false positives on brighter backgrounds
- global TBhighthr = 225 # Detection higher threshold, separates textbox from brighter flash-screens
- # Lower values ensure no false positives, but might delay detecting past the appearance of first few words on brighter backgrounds
- global QBthr = 150 # Detection threshold for questionboxes, lower values - sooner happening and longer lasting detection at the cost of higher false positive chance (it's pretty low though).
- # Depends on the background, so having an idol in blue clothes on the left and another one in red on the right => more error chances.
- global minlength = 1000 # Minimum duration of legit detection in milliseconds, used to filter out accidental false positives.
- #/Settings.
- function analyze(int cur_frame)
- {
- mode = "add"
- textbox = "
- \ value = tarea.rt_averageluma(n=cur_frame )
- \ global analyzed = (tblowthr<value && value<tbhighthr)
- \ (analyzed && debug)?
- \ c.overlay(c.blankclip(width=tbw, height=tbh, color=$00FF00), x=tbx, y=tby, opacity=0.25, mode=mode)
- \ :c
- \ "
- qbox = "
- \ value = qarea.rt_averageluma(n=cur_frame)
- \ global analyzed = (value>qbthr)
- \ global yellow = (analyzed)?
- \ (yarea.RT_AverageLuma(n=cur_frame)>qbthr)
- \ :(yellow)
- \ mark = c.blankclip(width=qw, height=qh, color=$00FF00)
- \ (analyzed && debug)?
- \ c.overlay(mark, x=qxb, y=qyb, opacity=0.33, mode=mode).
- \ overlay(mark, x=qxr, y=qyr, opacity=0.33, mode=mode).
- \ overlay((yellow)?mark:c.crop(qxy, qyy, 4, 2), x=qxy, y=qyy, opacity=(yellow)?0.33:0, mode=mode)
- \ :c
- \ "
- return eval(rt_txtgetline("eval(textbox)"+chr(10)+"eval(qbox)",n ))
- }
- function detect(int cur_frame)
- {
- (analyzed)?
- \ (detected)?
- \ nop
- \ :eval("
- \ global detected = true
- \ global startframe = cur_frame
- \ global qbthr = qbthr-15
- \ ")
- \ :(detected)?
- \ eval("
- \ global detected = false
- \ global endframe = cur_frame
- \ global startshow = startframe
- \ global qbthr = qbthr+15
- \ validate()
- \ ")
- \ :eval("global n = (n>=nmax)?0:n+1")
- }
- function validate()
- {
- global delta = endframe-startframe
- global accepted = (delta>minlength)
- (accepted)?
- \ c.writefile(filename, "prepareline(stringtemplate, startframe+shift, startframe+round(delta*mult)+shift)", append=true, flush=debug)
- \ :nop
- }
- function prepareline(string s, int b, int e)
- {
- result = RT_StrReplace(s, "0:00:00.00", frame2time(b))
- result = RT_StrReplace(result, "0:00:01.00", frame2time(e))
- result = (n==1)?
- \ (RT_StrReplace(result, "Style", "QB_Blue")+chr(10)
- \ +(yellow?
- \ RT_StrReplace(result, "Style", "QB_Yellow")+chr(10)
- \ :"")
- \ +RT_StrReplace(result, "Style", "QB_Red")
- \ ).RT_StrReplace("Actor", "Q-Box")
- \ :result
- return result
- }
- function frame2time(int f)
- {
- rawtime = f/framerate
- hours = rawtime/3600.0
- minutes = frac(hours)*60.0
- seconds = frac(minutes)*60.0
- time = string(floor(hours), "%1.0f")+":"+string(floor(minutes), "%02.0f")+":"+string(seconds, "%05.2f")
- return time
- }
- # Textbox description
- global tbX = 238 global tbY = 584
- global tbW = 840 global tbH = 90
- global tarea = crop(tbx, tby, tbw, tbh).coloryuv(autogain=true)
- # Questionboxes description
- global qw = 308 global qh = 120
- global qxb = 200 global qyb = 322
- global qxr = 772 global qyr = qyb
- global qxy = 486 global qyy = 180
- bluebox = crop(qxb, qyb, qw, qh)
- bluemask = bluebox.maskhs(starthue=360-60, endhue=360-20, maxsat=76, minsat=5).converttoyv12.mt_inflate.mt_expand
- redbox = crop(qxr, qyr, qw, qh)
- redmask = redbox. maskhs(starthue=80, endhue=120, maxsat=76, minsat=5).converttoyv12.mt_inflate.mt_expand
- global qarea = mt_logic(bluemask, redmask, mode="min")
- yellowbox = crop(qxy, qyy, qw, qh)
- yellowmask = yellowbox.maskhs(starthue=130, endhue=160, maxsat=75, minsat=5).converttoyv12.mt_inflate.mt_expand
- global yarea = yellowmask
- global yellow = false
- # Common variables
- global n = 0 global nmax = 1
- global framerate = last.framerate
- global shift = round(shift/1000.0*framerate)
- global minlength = round(minlength/1000.0*framerate)
- global startframe = 0
- global startshow = 0
- global endframe = 0
- global analyzed = false
- global detected = false
- global accepted = true
- writefilestart(filename, "chr(13)", append=!(overwrite))
- global c = last
- # main()
- scriptclip("""
- analyze(current_frame)
- detect(current_frame)
- (debug)?
- \ rt_subtitle(frame2time(startshow)+" > "+frame2time(endframe)+chr(13)+(accepted?"Accepted":"REJECTED"))
- \ :last
- """)
- #assumefps(500) # Set Debug to false to get ~500 fps without visual indications (when you finished tuning the script and ready to process your videos).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement