View difference between Paste ID: Cvkechkt and 98ptVUE0
SHOW: | | - or go back to the newest paste.
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")
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 f)
12+
function prepareline(clip c, string s, int b, int e)
13
	{
14-
		result	= RT_StrReplace(s,"0:00:00.00",frame2time(c,f))
14+
		result	= RT_StrReplace(s, "0:00:00.00", frame2time(c, b))
15-
		result	= RT_StrReplace(result,"0:00:01.00",frame2time(c,f+round(c.framerate)))
15+
		result	= RT_StrReplace(result, "0:00:01.00", frame2time(c, e))
16
17
		return result
18
	}	
19
20-
directshowsource("test_hibiki.mkv")
20+
ffmpegSource2("C:\Users\Seedmanc\Desktop\guiminer\avisynth\imas_question_pause.mkv")
21
22-
#Variables:
22+
#Settings:
23-
filename 	   = "subtitle.ass" 
23+
filename	= "c:\Users\Seedmanc\Desktop\guiminer\avisynth\subhelp\subtitle.ass" 
24-
stringtemplate = "Dialogue: 0,0:00:00.00,0:00:01.00,DefaultStyle,,0000,0000,0000,,"
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-
#Coordinates of the textbox for 720p
26+
debug       	=   true    # Controls visual indication and writebuffer flushing. Without them script runs at ~600 fps. 
27-
tbX 	 = 198 
27+
shift		= 0	# Shift of subtitle line placement in milliseconds, relative to time of detection. Both starting and ending times are affected
28-
tbY 	 = 584
28+
mult		= 1.0	# Multiplier of subtitle line duration relative to detected textbox on-screen duration. You'll likely want to increase it.
29-
tbW 	 = 880
29+
lowthr		= 185	# Detection lower threshold, separates textbox from darker background. 
30-
tbH 	 = 92
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-
#Starting with a new line just to be sure.    
32+
highthr		= 225	# Detection higher threshold, separates textbox from brighter flash-screens
33-
writefilestart(filename,"chr(13)",append=true)    
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	 = crop(tbx,tby,tbw,tbh).coloryuv(autogain=true,autowhite=true ).levels(8,1,255-8,0,255,coring=false)
35+
# Textbox will flash green if the detection was accepted or red if it was discarded.
36-
detected = false
36+
37
tbX	= 238 
38-
temp=""" detected=true          \
38+
tbY	= 584
39-
    writefile(filename,"prepareline(last,stringtemplate,current_frame)",append=true) last"""
39+
tbW	= 842
40-
t="overlay(blankclip(width=tbw,height=tbh,color=$00FF00),x=tbx,y=tby,opacity=0.3 ) "   
40+
tbH	= 92
41-
#^ indicates detection by placing green bar over the textbox when it occurs
41+
writefilestart(filename, "chr(13)", append=!(overwrite))  
42
shift		= round(shift/1000.0*framerate) 
43
minlength	= round(minlength/1000.0*framerate) 
44-
 tal=textbox.rt_averageluma 
44+
startframe	= 0
45-
 (tal<235 && tal>190)?           \
45+
startshow	= 0
46-
    eval(t+"(detected==false)?   \
46+
endframe	= 0
47-
        eval(temp):last          \           
47+
delta		= 0
48-
    "):                          \
48+
textbox		= crop(tbx, tby, tbw, tbh).coloryuv(autogain=true, autowhite=true)
49-
    eval( "detected=false last")
49+
detected	= false
50-
""")
50+
accepted	= true
51
begin		= """ detected = true	\
52-
assumefps(270)    # You can make the script scan your video faster by raising the framerate here, if you're running it via player. It works at ~330 fps for me.
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).