Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function frame2time(clip c, int f)
- {
- rawtime = f/c.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
- }
- function prepareline(clip c, string s, int b, int e)
- {
- result = RT_StrReplace(s, "0:00:00.00", frame2time(c, b))
- result = RT_StrReplace(result, "0:00:01.00", frame2time(c, e))
- return result
- }
- ffmpegSource2("C:\Users\Seedmanc\Desktop\guiminer\avisynth\imas_question_pause.mkv")
- #Settings:
- filename = "c:\Users\Seedmanc\Desktop\guiminer\avisynth\subhelp\subtitle.ass"
- stringtemplate = "Dialogue: 0,0:00:00.00,0:00:01.00,Style,Actor,0000,0000,0000,,"
- overwrite = true # Overwrites output file instead of appending to it. Useful while testing.
- debug = true # Controls visual indication and writebuffer flushing. Without them script runs at ~600 fps.
- shift = 0 # Shift of subtitle line placement in milliseconds, relative to time of detection. Both starting and ending times are affected
- mult = 1.0 # Multiplier of subtitle line duration relative to detected textbox on-screen duration. You'll likely want to increase it.
- lowthr = 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
- highthr = 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
- minlength = 1000 # Minimum duration of legit textbox appearance in milliseconds, used to filter out accidental false positives on flash-screens.
- # Textbox will flash green if the detection was accepted or red if it was discarded.
- tbX = 238
- tbY = 584
- tbW = 842
- tbH = 92
- writefilestart(filename, "chr(13)", append=!(overwrite))
- shift = round(shift/1000.0*framerate)
- minlength = round(minlength/1000.0*framerate)
- startframe = 0
- startshow = 0
- endframe = 0
- delta = 0
- textbox = crop(tbx, tby, tbw, tbh).coloryuv(autogain=true, autowhite=true)
- detected = false
- accepted = true
- begin = """ detected = true \
- startframe = current_frame """
- end = """ detected = false \
- endframe = current_frame \
- startshow = startframe """
- reject = """ accepted = false \
- overlay(blankclip(width=tbw, height=tbh, color=$FF0000), x=tbx, y=tby) """
- checkdif = """ eval("delta=endframe-startframe
- (delta>minlength)? \
- eval(write): \
- eval(reject)
- ") """
- write = """ writefile(filename, "prepareline(last, stringtemplate, startframe+shift, startframe+round(delta*mult)+shift)", append=true, flush=debug) \
- overlay(blankclip(width=tbw, height=tbh, color=$00FF00), x=tbx, y=tby) \
- accepted = true """
- ind = (debug)?""" overlay(blankclip(width=tbw, height=tbh, color=$00FF00), x=tbx, y=tby, opacity=0.25, mode="add") """ :""
- scriptclip("""
- status=accepted?"Accepted":"REJECTED"
- last=(debug)?rt_subtitle(frame2time(startshow)+" > "+frame2time(endframe)+chr(13)+status):last
- tal=textbox.rt_averageluma
- (tal>lowthr && tal<highthr)? \
- eval(ind+"(detected==false)? \
- eval(begin):last \
- ") \
- :(detected==true)? \
- eval(end+checkdif):nop
- last
- """)
- # assumefps(600) # Set Debug to false to get ~600 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