Quantcast Avisynth: Interlace Detection (Automatic) - digitalFAQ.com Forums [Archives]
  #1  
05-30-2006, 06:00 PM
incredible incredible is offline
Free Member
 
Join Date: May 2003
Location: Germany
Posts: 3,189
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to incredible
Quote:
Originally Posted by Boulder
Nope,

AssumeBFF().SeparateFields().SelectEvery(4,1,2).We ave() simply changes the field order to TFF. If you used SelectEvery(4,0,3), the field order would remain BFF. I chose TFF since many encoders seem to expect that by default.
Did you tested that in such a way? As you "switch" the fieldorder from the "input" and not from specific "BFF" to "TFF".
Avisynth assumes per default BFF even 95% of all inputs are TFF.
Example: My capture card defenitely outputs TFF but Avsiynth reports BFF.
Now ... If I just do switch the fieldorder like above avs reports TFF ok, but the final display on TV will be messed up ?
Reply With Quote
Someday, 12:01 PM
admin's Avatar
Site Staff / Ad Manager
 
Join Date: Dec 2002
Posts: 42
Thanks: ∞
Thanked 42 Times in 42 Posts
  #2  
05-31-2006, 01:23 AM
Boulder Boulder is offline
Free Member
 
Join Date: Sep 2002
Location: Lahti, Finland
Posts: 1,652
Thanks: 0
Thanked 0 Times in 0 Posts
Just try it on interlaced sources

I just did on a DV clip (DV is always BFF as you probably know) and it does work. The field order is truly TFF after the script.
Reply With Quote
  #3  
05-31-2006, 07:52 AM
incredible incredible is offline
Free Member
 
Join Date: May 2003
Location: Germany
Posts: 3,189
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to incredible
Yep, on BFF DV Sources this works as you switch the fieldorder and therefore finally when encoding to mpeg2 i.E. using a TFF flag in the encoder is no problem or better said its a must.

But as said, (just imho) if you use a common DVD source or a capture mostly these do come as TFF and the "fieldorder switch" above (imho) forces the user to check the "encode as BFF" in the encoder

Quote:
AssumeBFF().SeparateFields().SelectEvery(4,1,2).We ave() simply changes the field order to TFF
As this expects as source a BFF one it should be better explained as ...
Quote:
AssumeXXX().SeparateFields().SelectEvery(4,1,2).We ave() simply changes the field order of the source
can you confirm that?

Reply With Quote
  #4  
05-31-2006, 07:57 AM
Boulder Boulder is offline
Free Member
 
Join Date: Sep 2002
Location: Lahti, Finland
Posts: 1,652
Thanks: 0
Thanked 0 Times in 0 Posts
That is naturally true. For any interlaced DVD stuff, AssumeTFF().SeparateFields().SelectEvery(4,0,3).We ave() is the way to go. In any case, you need to know the original field order - and know what you are doing

Let's just say that I didn't want to confuse Blubear any more
Reply With Quote
  #5  
05-31-2006, 08:00 AM
incredible incredible is offline
Free Member
 
Join Date: May 2003
Location: Germany
Posts: 3,189
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to incredible
Today Momonster gave me a new update of a script I requested for the new coming version of PARanoia:
Code:
Function Interlacing2Reader(clip clp, float "mthresh", int "end", int "start", int "every", int "inf", string "file") 
{
###### PREPARATION ######
begin = default(start,0)
out = default(inf,1)
global stop = default(end,5000)
global deci = default(every,17)
global mthresh = default(mthresh,3.0)

global source = clp.trim(begin,stop)
global cltff = source.AssumeTFF().bob()
global clbff = source.AssumeBFF().bob()
global matched = source.tfm(mode=0,pp=2, MI=74,clip2=cltff.selecteven())

output = default(file,"C:\interlacing.log")

###### VAR.. ######
global interlaced = 0
global progressive = 0
global fieldshifted = 0
global tffcount = 0
global bffcount = 0
global real_interlaced = 0

###### Conditional Function Chain, evaluated from bottom to top (!) ######
c99=	out==0 ? scriptclip(source, "source") : ( out==1 ? 
	\	scriptclip(source,     "Subtitle(currentframe_s+string(current_frame),size=12)."+
			\	"Subtitle(interlaced_s+string(interlaced),size=12,y=10)."+
			\	"Subtitle(progressive_s+string(progressive),size=12,y=20)."+
			\	"Subtitle(fieldshifted_s+string(fieldshifted),size=12,y=30)."+
			\	"Subtitle(real_interlaced_s+string(real_interlaced),size=12,y=40)."+
			\	"Subtitle(bffcount_s+string(bffcount),size=12,y=50)."+
			\	"Subtitle(tffcount_s+string(tffcount),size=12,y=60)") : 
	\	WriteFileIf(source, output, "current_frame>stop-deci", """ "interlaced:" """, "interlaced", """ ",  progressive:" """, "progressive",
			\	""" ",  fieldshifted:" """, "fieldshifted", """ ",  real_interlaced:" """ , "real_interlaced", """ ",  BFF:" """, 
			\	"bffcount", """ ",  TFF:" """, "tffcount", append=false, flush=true) )

c4=FrameEvaluate(c99, "	global interlaced = count==2 || count==3 ? interlaced+1 : interlaced
			global progressive = count==0 ? progressive+1 : progressive
			global fieldshifted = count==1 ? fieldshifted+1 : fieldshifted
			global tffcount = count!=20 && (tffc+tffb)*1.25<bffc+bffb ? tffcount+1 : tffcount
			global bffcount = count!=20 && (bffc+bffb)*1.25<tffc+tffb ? bffcount+1 : bffcount
			global real_interlaced = count==2 && tffc*0.7<tffb && tffc*1.33>tffb ||
			\		count==3 && bffc*0.7<bffb && bffc*1.33>bffb ? real_interlaced+1 : real_interlaced")

c3=FrameEvaluate(c4, "	global count = (tffc>tffb && tffc>bffc && tffc>bffb ? tffc : (tffb>bffc && tffb>bffb ? tffb : 
			\		(bffc>bffb ? bffc : bffb))) > mthresh ? (abs(LumaDifference(matched,cltff.selectodd())-tffc)<0.0001 ? 
			\		(tffc+tffb<bffc+bffb ? 2 : 3) : (LumaDifference(source,matched)<0.0002 ? 0 : 1)): 20")

c2=FrameEvaluate(c3, "	global tffc = LumaDifference(cltff.selecteven(), cltff.selectodd())
			global tffb = LumaDifference(cltff.selectodd().duplicateframe(0), cltff.selecteven())
			global bffc = LumaDifference(clbff.selecteven(), clbff.selectodd())
			global bffb = LumaDifference(clbff.selectodd().duplicateframe(0), clbff.selecteven())")      

return(c2.selectevery(deci,0)) 
}
I just got this update this morning so I wasn't able to test.

It should detect if a source IS interlaced or Progressive and if its interlaced then also if that interlaced source is real-interlaced, fieldshifted and of course if its TFF or BFF.


"mthresh" = motionthreshod
"start" & "end" = the trimmed rage of the source in frames
"every" = SelectEvery... you should leave it at default (17) cause of pattern reasons
"inf" = 1 = Output stats to screen, 2= Output stats to file
"file" = if inf = 2 then here the Path+Name of the stats file to be written to
Reply With Quote
  #6  
05-31-2006, 08:13 AM
Dialhot Dialhot is offline
Free Member
 
Join Date: May 2003
Posts: 10,463
Thanks: 0
Thanked 0 Times in 0 Posts
If it can do the coffee, I prefer it with two sugars. Thanks.
Reply With Quote
  #7  
05-31-2006, 08:14 AM
Boulder Boulder is offline
Free Member
 
Join Date: Sep 2002
Location: Lahti, Finland
Posts: 1,652
Thanks: 0
Thanked 0 Times in 0 Posts
I wonder if that's similar to the algorithm that MeGUI uses? In any case, looks like a killer function for newbies to use
Reply With Quote
  #8  
05-31-2006, 10:51 AM
incredible incredible is offline
Free Member
 
Join Date: May 2003
Location: Germany
Posts: 3,189
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to incredible
Berrinam uses a diff. approach: A combination of the two scripts shown in this page: http://www.avisynth.org/mediawiki/wi...lace_detection

But if you feed his Tool (where those routines are also implementated in MeGUI) http://forum.doom9.org/showthread.ph...642#post758642 with a simply fieldshifted source the tool claims about that the source is hybrid which actually isn't the case as NO deinterlacing but phasecorrection would be needed .. Momonsters tool is capable of detecting such a phaseshifted state

Momonsters one is different. And as he already gave so much efforts into my request I dont think its a good behaviour asking him if he could add a NTSC Pulldown detection also.
Reply With Quote
  #9  
05-31-2006, 11:03 AM
kwag kwag is offline
Free Member
 
Join Date: Apr 2002
Location: Puerto Rico, USA
Posts: 13,537
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by incredible
Momonsters tool is capable of detecting such a phaseshifted state
Reply With Quote
  #10  
05-31-2006, 11:17 AM
Dialhot Dialhot is offline
Free Member
 
Join Date: May 2003
Posts: 10,463
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by incredible
http://www.avisynth.org/mediawiki/wiki
I didn't knew there was a avisynth wiki

BTW, Inc, an idea on how to use momonsters' function ? I tried to understand the code but...
Reply With Quote
  #11  
05-31-2006, 11:37 AM
incredible incredible is offline
Free Member
 
Join Date: May 2003
Location: Germany
Posts: 3,189
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to incredible
I added (as you already recognised) the parameter usage below the script code. What do you dont understand?
Reply With Quote
  #12  
05-31-2006, 11:53 AM
Dialhot Dialhot is offline
Free Member
 
Join Date: May 2003
Posts: 10,463
Thanks: 0
Thanked 0 Times in 0 Posts
In which way this function is supposed to be called (that's the part you answered) and its result used. It's not so evident when you read it.
Reply With Quote
  #13  
05-31-2006, 04:30 PM
incredible incredible is offline
Free Member
 
Join Date: May 2003
Location: Germany
Posts: 3,189
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to incredible
I did fix some things in the function as Momonster took my approach of the subtitle info displaying which I applied to his first version but he forgot to copy the string globals and so it resulted incomplete.

A significant speed improvement I archieved by changing at the end
return(c2.selectevery(deci,0)) to
return(c2.selectrangeevery(deci,1))
it should result in the same as no offset is applied and the pattern should be kept.

Also I did apply an amount-factor to set the amount of frames of the "whole" movie range which will be scanned.

The whole detection routine is done by "Momonster" @ the German doom9/Gleitz board, ... just to avoid confusings

Code:
# The "TIVTC.dll" from Triticals "TIVTC" Package to be found at http://www.avisynth.org/warpenterprises/
# has to be installed in the Avisynth 2.5 plugins dir.


Function Interlacing2Reader(clip clp, float "mthresh", int "end", int "start", int "every", int "amount", int "inf", string "file", bool "lowprec", int "FontSize")
{
###### PREPARATION ######
begin   = default(start, 0)
out     = default(inf, 1)
amount  = default(amount, 10)
output  = default(file,"X:\YourPathToThe\interlacing.log")
lowprec = default(lowprec, false)

global stop      = default(end, 0)
global deci      = default(every, 17)
global mthresh   = default(mthresh, 3.0)
global FontSize  = default(FontSize, 16) 

global multi     = (begin==0 && stop==0) ? int(framecount(clp)/(amount*1000))+1 : 1

global source    = (lowprec==false) ? clp.trim(begin,stop) : clp.trim(begin,stop).pointresize(width(clp)/2,height(clp)) 
global cltff     = source.AssumeTFF().bob()
global clbff     = source.AssumeBFF().bob()
global matched   = source.tfm(mode=0,pp=2, MI=74,clip2=cltff.selecteven())


###### VAR.. ######
global interlaced        = 0
global progressive       = 0
global fieldshifted      = 0
global tffcount          = 0
global bffcount          = 0
global real_interlaced   = 0
global currentframe_s    = "CurrFrame: "
global interlaced_s      = "interlaced: "
global progressive_s     = "progressive: "
global fieldshifted_s    = "fieldshifted: "
global real_interlaced_s = "real_interlaced: "
global bffcount_s        = "bff: "
global tffcount_s        = "tff : "

###### Conditional Function Chain, evaluated from bottom to top (!) ######
c99=   out==0 ? scriptclip(source, "source") : ( out==1 ?
   \   scriptclip(source,     "Subtitle(currentframe_s+string(current_frame),size= FontSize )."+
         \   "Subtitle(interlaced_s+string(interlaced),size=FontSize,y= FontSize )."+
         \   "Subtitle(progressive_s+string(progressive),size=FontSize,y= FontSize*2 )."+
         \   "Subtitle(fieldshifted_s+string(fieldshifted),size=FontSize,y= FontSize*3 )."+
         \   "Subtitle(real_interlaced_s+string(real_interlaced),size=FontSize,y= FontSize*4 )."+
         \   "Subtitle(tffcount_s+string(tffcount),size=FontSize,y= FontSize*5 )."+
         \   "Subtitle(bffcount_s+string(bffcount),size=FontSize,y= FontSize*6 )") :
   \   WriteFileIf(source, output, "current_frame>stop-deci", """ "interlaced:" """, "interlaced", """ ",  progressive:" """, "progressive",
         \   """ ",  fieldshifted:" """, "fieldshifted", """ ",  real_interlaced:" """ , "real_interlaced", """ ",  BFF:" """,
         \   "bffcount", """ ",  TFF:" """, "tffcount", append=false, flush=true) )

c4=FrameEvaluate(c99, "   global interlaced = count==2 || count==3 ? interlaced+1 : interlaced
         global progressive = count==0 ? progressive+1 : progressive
         global fieldshifted = count==1 ? fieldshifted+1 : fieldshifted
         global tffcount = count!=20 && (tffc+tffb)*1.25<bffc+bffb ? tffcount+1 : tffcount
         global bffcount = count!=20 && (bffc+bffb)*1.25<tffc+tffb ? bffcount+1 : bffcount
         global real_interlaced = count==2 && tffc*0.7<tffb && tffc*1.33>tffb ||
         \      count==3 && bffc*0.7<bffb && bffc*1.33>bffb ? real_interlaced+1 : real_interlaced")

c3=FrameEvaluate(c4, "   global count = (tffc>tffb && tffc>bffc && tffc>bffb ? tffc : (tffb>bffc && tffb>bffb ? tffb :
         \      (bffc>bffb ? bffc : bffb))) > mthresh ? (abs(LumaDifference(matched,cltff.selectodd())-tffc)<0.0001 ?
         \      (tffc+tffb<bffc+bffb ? 2 : 3) : (LumaDifference(source,matched)<0.0002 ? 0 : 1)): 20")

c2=FrameEvaluate(c3, "   global tffc = LumaDifference(cltff.selecteven(), cltff.selectodd())
         global tffb = LumaDifference(cltff.selectodd().duplicateframe(0), cltff.selecteven())
         global bffc = LumaDifference(clbff.selecteven(), clbff.selectodd())
         global bffb = LumaDifference(clbff.selectodd().duplicateframe(0), clbff.selecteven())")     


#return(c2.selectevery(deci*multi,0))
return(c2.selectrangeevery(deci*multi,1))
}
How does it work:
Code:
xxxSource("X:\MyPathToMySource.xx")
Interlacing2Reader()
.... already brings you the needed information on the screen

I added some options:
Code:
Interlacing2Reader(lowprec=true)
... here I added a LowPrecision option, means the source will be reduced by 2 in its width for faster (but also less accurate) detection speed.

Code:
Interlacing2Reader(FontSize=18)
... maybe you wont ever needed it but if you need glasses, by this you can in-/decrease the fontsize. The space between the rows will be adaptive.

Code:
Interlacing2Reader(amount=10)
... this only works if no "start" neither "end" position has been set as If you will scan a whole movie this amount-factor affects the whole movie %age beeing scanned (like we know from predictioning).


... and here for shure Momonsters parameters:

Code:
Interlacing2Reader(mthresh=3.0)
... affects the threshold for the detection

Code:
Interlacing2Reader(inf=x)
... x = 1 lets the routine display the info on the screen
... x = 2 lets the routine output the stats to a file where the path will be set by the string "file" parameter in the functions arguments.
... x = 0 no info

Code:
Interlacing2Reader(every=17)
... dont set this different to 17 as its a specific "odd" value based on a specific common source pattern.



How to interprete the results:
At the very top you can see the "current frame number" of the clip which is beeing processed.
If "interlacing" is detected, then here you can see how many of the moving frames are detected as interlaced.
Same for "progressive" as this shows if a progressive frame is detected.
Now ... "fieldshifted" means it could be a simple Phaseshift which can be easely restored to archive the real progressive contend of the source, or it means that the source could be Pulldowned. In this case just try to ivtc the source and see if an ivtc was needed.
Real interlaced speaks for itself
And last but not least ... if fieldbased thenhere you can see if its a TFF or a BFF stream.

All Values are outputtet as numbers so you can see on the size of each outputtet numbercount what the source could be made of.
Reply With Quote
  #14  
05-31-2006, 05:24 PM
Dialhot Dialhot is offline
Free Member
 
Join Date: May 2003
Posts: 10,463
Thanks: 0
Thanked 0 Times in 0 Posts
What a pain in the ass to find where the carriadge returns have to be

If someone can upload the avsi file somewhere on the net, I'll be glad. I must be too tired because I do not manage to find the correct indentation

(note for people trying to use the function dit given by Inc : you will have an evaluate error, and that's normal).
Reply With Quote
  #15  
06-01-2006, 05:53 AM
incredible incredible is offline
Free Member
 
Join Date: May 2003
Location: Germany
Posts: 3,189
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to incredible
Quote:
What a pain in the ass to find where the carriadge returns have to be
What? I just tried selecting the whole code in the post above, copied it and pasted it into a texteditor - no problem and the CRs are correctly copied as well.
Quote:
note for people trying to use the function dit given by Inc : you will have an evaluate error, and that's normal
Cant follow you!?
Reply With Quote
  #16  
06-01-2006, 06:02 AM
Dialhot Dialhot is offline
Free Member
 
Join Date: May 2003
Posts: 10,463
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by incredible
What? I just tried selecting the whole code in the post above, copied it and pasted it into a texteditor - no problem and the CRs are correctly copied as well.
That's barely impossible as I verified by editing directly the source of your message (that I can do as a moderator) and the CR are badly placed also there ! For instance the line starting with "c99=" shoudl have a CR after the
"\" isn't it ? But it is actually put after the "out==1 ?" Whatever the texteditor I use

Quote:
Cant follow you!?
Due to the bad CR, avisynth pops a strange error telling "Evaluate : == and != operators must be comparable (line 162)". Funny .

Can you upload the function Inc ? Else I will put manually the CR when my eyes will be correctly opened
Reply With Quote
  #17  
06-01-2006, 07:32 AM
incredible incredible is offline
Free Member
 
Join Date: May 2003
Location: Germany
Posts: 3,189
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to incredible
a "\" in an avisynth script means NO CR.
Thats why avisynth will interpret ..
Code:
c99=   out==0 ? scriptclip(source, "source") : ( out==1 ?
   \   scriptclip(source, .......
as
Code:
c99=   out==0 ? scriptclip(source, "source") : ( out==1 ? scriptclip(source, .....
This is just a cosmetic script appeareance option so codes wot exceed in their line width's especially in forums or whatever texteditor.

So as you get the "Evaluate : == and != operators must be comparable (line 162)" thats not the fault of wrong CRs but something else which I cant duplicate now in my office, so Ill have to check that this night. Yesterday it worked without problems

Heres the downloadlink of an avsi textfile:
Interlacing2reader.avsi
Reply With Quote
  #18  
06-01-2006, 08:33 AM
Dialhot Dialhot is offline
Free Member
 
Join Date: May 2003
Posts: 10,463
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by incredible
This is just a cosmetic script appeareance option so codes wot exceed in their line width's especially in forums or whatever texteditor.
I know that but there is your error : a \ followed by a CR is interpreted as "no CR", but a \ followed by a space is considered as "no space".
And then :
Code:
c99=   out==0 ? scriptclip(source, "source") : ( out==1 ? <CR>
   \   scriptclip(source, .......
is not interpreted as
Code:
c99=   out==0 ? scriptclip(source, "source") : ( out==1 ? scriptclip(source, .....
as you wrote, but as :
Code:
c99=   out==0 ? scriptclip(source, "source") : ( out==1 ? <CR>
    scriptclip(source, .......
And there are places where a CR completly disturb Avysinth (in the middle of a Scriptclip function for instance).

Quote:
Heres the downloadlink of an avsi textfile:
Interlacing2reader.avsi
This one works like a charm
You see... all was a matter of CR badly placed Thanks a lot
Reply With Quote
  #19  
06-01-2006, 08:44 AM
incredible incredible is offline
Free Member
 
Join Date: May 2003
Location: Germany
Posts: 3,189
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to incredible
Avisynth is in this case diff. then C++ etc.

Code:
c = dfsdffksjhjshjfhsjhkfshkjfshkfskdf : \
      sdsdsdsdsdsdsdsdsdssd
or
Code:
c = dfsdffksjhjshjfhsjhkfshkjfshkfskdf : 
\     sdsdsdsdsdsdsdsdsdssd
....

in my cases IS interpreted as
Code:
c = dfsdffksjhjshjfhsjhkfshkjfshkfskdf :      sdsdsdsdsdsdsdsdsdssd
as "\" in avisynth simply means "ignore last <cr>"

Its not like in C++ where \\ also would mean a remark. I never understood why this was not taken over to avisynth in the same logic/manner but using a "#" instead


Edit:
Quote:
This one works like a charm
You see... all was a matter of CR badly placed Wink Thanks a lot bowdown
Really strange, so its a browser or php or whatever problem
I never had any problems when copying such "\" including scripts at doom9 out of a code marked section within a post.
Reply With Quote
  #20  
06-01-2006, 08:57 AM
Dialhot Dialhot is offline
Free Member
 
Join Date: May 2003
Posts: 10,463
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by incredible
Avisynth is in this case diff. then C++ etc.
You are right, I just read that in the doc : "Continue on next or from previous line: \"

Quote:
Really strange, so its a browser or php or whatever problem
I never had any problems when copying such "\" including scripts at doom9 out of a code marked section within a post.
There a only some avisynth commands that suffer from a CR in the middle of a line (scripclip or fremaevaluate I think). I don't see where in your initial post we face to this situation, but if you have for instance :
Code:
aaaa <CR>
\ bbbb <CR>
cccc
this is interpreted by avisynth as :
Code:
aaaa bbbb<CR>
cccc
that can be problematic.

The problem happened to some people with the MA script (that also use scriptclip; and where you can find "\" in the middle of the line also for the cosmetic reason you mentionned). That is why I immediatly knew that my evaluate problem was due to that.

But that's a solved one now . Thanks again.
Reply With Quote
Reply




Similar Threads
Thread Thread Starter Forum Replies Last Post
Avisynth: Which interlace filter? towerblocks Avisynth Scripting 1 11-30-2004 08:44 AM
Avisynth: Scene Change Detection? Prodater64 Avisynth Scripting 1 02-29-2004 09:05 PM
Avisynth: Automatic loading of AVS 2.0x plugins in AVS 2.5 vmesquita Avisynth Scripting 1 10-10-2003 01:16 PM
Avisynth: FixOversharp+Film scratch detection? morsa Avisynth Scripting 2 08-08-2003 03:27 AM
KVCD: Interlace or de-interlace (progressive) encoding? Adder Video Encoding and Conversion 4 02-01-2003 05:01 AM

Thread Tools



 
All times are GMT -5. The time now is 03:10 PM  —  vBulletin © Jelsoft Enterprises Ltd