Advertisement
Seedmanc

im@s2 subtitle generator

Aug 19th, 2013
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function frame2time(clip c, int f)
  2.     {
  3.         rawtime = f/c.framerate  
  4.         hours   = rawtime/3600.0
  5.         minutes = frac(hours)*60.0
  6.         seconds = frac(minutes)*60.0  
  7.         time    = string(floor(hours), "%1.0f")+":"+string(floor(minutes), "%02.0f")+":"+string(seconds, "%05.2f")
  8.        
  9.         return time
  10.     }
  11.  
  12. function prepareline(clip c, string s, int b, int e)
  13.     {
  14.         result  = RT_StrReplace(s, "0:00:00.00", frame2time(c, b))
  15.         result  = RT_StrReplace(result, "0:00:01.00", frame2time(c, e))
  16.  
  17.         return result
  18.     }  
  19.  
  20. ffmpegSource2("C:\Users\Seedmanc\Desktop\guiminer\avisynth\imas_question_pause.mkv")
  21.  
  22. #Settings:
  23. filename    = "c:\Users\Seedmanc\Desktop\guiminer\avisynth\subhelp\subtitle.ass"
  24. stringtemplate  = "Dialogue: 0,0:00:00.00,0:00:01.00,Style,Actor,0000,0000,0000,,"
  25. overwrite   = true  # Overwrites output file instead of appending to it. Useful while testing.
  26. debug           =   true    # Controls visual indication and writebuffer flushing. Without them script runs at ~600 fps.
  27. shift       = 0 # Shift of subtitle line placement in milliseconds, relative to time of detection. Both starting and ending times are affected
  28. mult        = 1.0   # Multiplier of subtitle line duration relative to detected textbox on-screen duration. You'll likely want to increase it.
  29. lowthr      = 185   # Detection lower threshold, separates textbox from darker background.
  30. # Raising will delay detection until textbox fully appears, but might fail to catch textboxes with lots of text.
  31. # Lower values might result in false positives on brighter backgrounds
  32. highthr     = 225   # Detection higher threshold, separates textbox from brighter flash-screens
  33. # Lower values ensure no false positives, but might delay detecting past the appearance of first few words on brighter backgrounds
  34. minlength   = 1000  # Minimum duration of legit textbox appearance in milliseconds, used to filter out accidental false positives on flash-screens.
  35. # Textbox will flash green if the detection was accepted or red if it was discarded.
  36.  
  37. tbX = 238
  38. tbY = 584
  39. tbW = 842
  40. tbH = 92
  41. writefilestart(filename, "chr(13)", append=!(overwrite))  
  42. shift       = round(shift/1000.0*framerate)
  43. minlength   = round(minlength/1000.0*framerate)
  44. startframe  = 0
  45. startshow   = 0
  46. endframe    = 0
  47. delta       = 0
  48. textbox     = crop(tbx, tby, tbw, tbh).coloryuv(autogain=true, autowhite=true)
  49. detected    = false
  50. accepted    = true
  51. begin       = """ detected = true   \
  52.     startframe  = current_frame """
  53. end     = """ detected = false  \
  54.     endframe    = current_frame         \
  55.     startshow   = startframe    """
  56. reject      = """ accepted = false  \
  57.    overlay(blankclip(width=tbw, height=tbh, color=$FF0000), x=tbx, y=tby) """
  58. checkdif    = """ eval("delta=endframe-startframe
  59.     (delta>minlength)?          \
  60.         eval(write):            \
  61.         eval(reject)
  62.     ") """  
  63. write       = """ writefile(filename, "prepareline(last, stringtemplate, startframe+shift, startframe+round(delta*mult)+shift)", append=true, flush=debug)                  \
  64.     overlay(blankclip(width=tbw, height=tbh, color=$00FF00), x=tbx, y=tby)  \
  65.     accepted    = true """
  66. ind     = (debug)?"""  overlay(blankclip(width=tbw, height=tbh, color=$00FF00), x=tbx, y=tby, opacity=0.25, mode="add") """ :""
  67. scriptclip("""
  68.    status=accepted?"Accepted":"REJECTED"
  69.    last=(debug)?rt_subtitle(frame2time(startshow)+" > "+frame2time(endframe)+chr(13)+status):last  
  70.    tal=textbox.rt_averageluma
  71.     (tal>lowthr && tal<highthr)?    \
  72.         eval(ind+"(detected==false)?    \
  73.             eval(begin):last        \          
  74.         ")              \
  75.     :(detected==true)?          \  
  76.        eval(end+checkdif):nop    
  77.    last    
  78. """)
  79.  
  80.  # 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