» AviSynth is a powerful video FrameServer for Win32.

AviSynth Links:
»Learn to script
»Discussion fora
»Project page
»External filters

» You can add pages to this website immediately. No login required.
Edit this document

» AboutAviSynth




For YUY2 and RGB material:

function CheckTopFirst(clip v1) {
v2 = v1.subtitle(v1.GetParity()?"TF":"BF")
v3 = v2.GetParity()?v2.ComplementParity():v2
t0 = v3.ComplementParity()
t1 = t0.separatefields()
t2 = compare(t1.trim(1,0),t1)
b1 = v3.separatefields()
b2 = compare(b1.trim(1,0),b1)
return stackvertical(t2,b2)



Then preview a few frames. It will use Compare to evaluate the two possibilities and vertically stack the results. This shows 2 useful pieces of info. First the preview of either the top or bottom half of the screen will probably be jerky, so choose the other one.

But just as reliable is the "Avg Mean Abs Dev" value that is displayed for each. Choose either the top (TopFirst?=1) or bottom (TopFirst?=0) clip that has the LOWEST value for Avg Mean Abs Dev.

For YV12 material (requires AviSynth 2.52)

function CheckTopFirst(clip v1){
global top_hits=1
global bot_hits=1
global uk_hits=1
global text = ""
global text2 = ""
global text3 = ""
v1 = assumeframebased(v1)
global tff=assumetff(v1).separatefields().bob()
global bff=assumebff(v1).separatefields().bob()
istff = tff.subtitle("Is frame TFF: TRUE").frameevaluate("top_hits=top_hits+1.0")
isnottff = tff.subtitle("Is frame TFF: FALSE").frameevaluate("bot_hits=bot_hits+1.0")
isunknown = tff.subtitle("Is frame TFF: Unknown").frameevaluate("uk_hits=uk_hits+1.0")
outclip = conditionalfilter(tff,istff, isnottff, "yDifferenceFromPrevious(tff)+ydifferenceToNext(tff)","<","yDifferenceFromPrevious(bff)+yDifferenceToNext(bff)",false)
outclip = conditionalfilter(tff,outclip, isunknown, "abs((yDifferenceFromPrevious(tff)+ydifferenceToNext(tff))-(yDifferenceFromPrevious(bff)+yDifferenceToNext(bff)))",">","0.5",false)
outclip = frameevaluate(outclip,"text = "+chr(34)+"STATS: TFF = "+chr(34)+" + string(100.0*top_hits/(top_hits+bot_hits)) + " + chr(34) + "%"+chr(34))
outclip = frameevaluate(outclip,"text2 = "+chr(34)+"STATS: BFF = "+chr(34)+" + string(100.0*bot_hits/(top_hits+bot_hits)) + " + chr(34) + "%"+chr(34))
outclip = frameevaluate(outclip,"text3 = "+chr(34)+"Certainty = "+chr(34)+" + string(100-(100.0*uk_hits/(uk_hits+top_hits+bot_hits-2))) + " + chr(34) + "%"+chr(34))
outclip = scriptclip(outclip, "Subtitle(text,y=50)")
outclip = scriptclip(outclip, "Subtitle(text2,y=70)")
outclip = scriptclip(outclip, "Subtitle(text3,y=100)")
return outclip



Preview some frames - you will now see a percentage of how many frames look like TFF and how many look like BFF. TFF is the one being passed through, so if this is jerky, it is also an indication that your clip is BFF.

Back to ShareFunctions

SourceForge Logo


Edit this document | View document history
Document last modified Mon, 08 Mar 2004 04:21:18