Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
27th September 2002, 14:06 | #1 | Link |
Registered User
Join Date: Oct 2001
Location: Gainesville FL USA
Posts: 2,092
|
Useful function for checking TopFirst
When is a clip "TopFirst"?
Interlaced video clips have 2 different fields in each frame and you are never quite sure which one was intended to be displayed first and which second when displaying interlaced or when deinterlacing. But some of my filters (GreedyHMA, TomsMoComp) make you specify that when invoking them. So I just wrote a quickie Avisynth function that makes it easy to know if the clip is stored "TopFirst". The following function will do it fairly reliably: later edit: see updated version on page 2 of this thread. Code:
function CheckTopFirst(clip v1){ t0=v1.ComplementParity t1=t0.separatefields t2=compare(t1.trim(1,0),t1) b1=v1.separatefields b2=compare(b1.trim(1,0),b1) return stackvertical(t2,b2)} v=AVISource("C:\whatever\bikes.avi") CheckTopFirst(v) 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. Picture attached. In this example the Avg Mean Abs Dev is 6.143 for the top and 7.549 for the bottom, so the clip is TopFirst. - Tom Last edited by trbarry; 12th December 2002 at 14:48. |
27th September 2002, 17:39 | #6 | Link | |
Moderator
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
|
Quote:
The documentation on www.avisynth.org is a little bit behind schedule It would be nice if more people can copy-paste stuff from the project page to www.avisynth.org. |
|
27th September 2002, 19:42 | #7 | Link |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
@Wilbert
GetParity is just Avisynths internal state flag - it always assumes a clip is bottom field first (It must have been so on Ben's capture set up ) Toms function is attempting to actually work it out regards Simon
__________________
http://www.geocities.com/siwalters_uk/fnews.html |
28th September 2002, 13:38 | #8 | Link |
Registered User
Join Date: Apr 2002
Posts: 272
|
yes, that's right!
would there be a way, then, for the avisource command to run tom's function automatically and set its internal state flag to whatever has the lowest avg mean dev? i.e. so that parity is set correctly first time without user intervention? any filters that require parity input parameters could instead, as default behaviour, then just use whatever the internal state flag is set to |
28th September 2002, 15:39 | #9 | Link | |
Registered User
Join Date: Oct 2001
Location: Gainesville FL USA
Posts: 2,092
|
Quote:
1) It has some performance impact since it is doing a couple compares on every frame, so we wouldn't want to do it where not needed. This would suggest maybe an optional AutoSetParity filter. 2) Parity is kept by clip, not by frame. It is possible with some clips (or concatenated clips) that it changes in the middle. I'm not quite sure what the ramifications are here. - Tom |
|
28th September 2002, 20:00 | #10 | Link | |
Registered User
Join Date: Sep 2002
Posts: 88
|
Re: Useful function for checking TopFirst
Thanks,Tom!
It's a very usuful function. But,I have questions. Quote:
I tested some MPEG2 sources captured by MPEG-2 capture board and using MPEG2DEC.dll(by dividee). By using your function,the value of bottom field is lower in Avg Mean Abs Dev than top. Does that result mean BottomFirst? But,I think my sources should be TopFirst. For example,when I use TMPGEnc and DVD2AVI,they always judge my MPEG2 videos as TopFirst. Why did these differeneces happened? Or,does Avisynth always assume a clip is bottom field first? Any idea? My AVS is like this: LoadPlugin("mpeg2dec.dll") v=Mpeg2Source("D:\test.d2v") function CheckTopFirst(clip v1){ t0=v1.ComplementParity t1=t0.separatefields t2=compare(t1.trim(1,0),t1) b1=v1.separatefields b2=compare(b1.trim(1,0),b1) return stackvertical(t2,b2)} CheckTopFirst(v) |
|
28th September 2002, 20:25 | #11 | Link |
Registered User
Join Date: Oct 2001
Location: Gainesville FL USA
Posts: 2,092
|
niiyan -
Yes, the one (top or bottom) with the lower abs dev is probaly the correct answer to be first. But as a sanity check it should probably also be less jerky in preview, and I think also will probably have a HIGHER avg PSNR value. I can't explain the differences with Tmpg. But be careful you don't do it on a trailer, preview, lead-in, etc. Make sure to look at the body of the movie, probably in multiple places if there is any doubt. I think (like siwalters said above) Avisynth just assumes Bottom First unless you issue a ComplementParity statement. But I don't know if Avisynth passes this to Tmpg or anywhere else. - Tom |
29th September 2002, 17:42 | #13 | Link |
Registered User
Join Date: Sep 2002
Posts: 88
|
@trbarry
I tested again your function by using a movie,of course the body of a movie and in several scenes. The movie was captured by a MPEG2 capturing board from TV. So,the result is almost the same as yesterday. 1.About Avg Mean Abs Dev,the most of the bottom clip is lower than the top one. 2.But,in the some scene,the top value is sometimes lower. 3.When Avg Mean Abs Dev is lower in the bottom field,avg PSNR value is higher in the bottom. Sorry,it's difficult for me to judge if it's jerky or less jerky. In this result,do you think the movie is BottomFirst? By the way,Wilbert's Getparity script says TopFirst. |
29th September 2002, 17:55 | #14 | Link |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
@niiyan
Are you sure you get Topfirst from Wilberts script or do you have any other items in the script? Could you post the exact script used? regards Simon
__________________
http://www.geocities.com/siwalters_uk/fnews.html |
29th September 2002, 18:54 | #15 | Link |
Registered User
Join Date: Sep 2002
Posts: 88
|
@siwalters
My avs is like this: LoadPlugin("mpeg2dec.dll") Mpeg2Source("D:\test.d2v") subtitle(last.GetParity() ? "TopFirst":"BottomFirst", font="MS UI Gothic") Mm...,my script is a little bit different from Wilbert one. But is this the same thing? -niiyan |
29th September 2002, 22:23 | #16 | Link |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
@niiyan
Mpeg2Source may be able to query the MPEG file TFF(Top Field First) flag and return its state. OR it may just change the Parity flag regardless? Unfortunately, Mpeg2Source doesn't seem to work on my system so I can't do any tests with it (But maybe someone else could check) @niiyan again Could you save an avi from your script and then use Wilbert's script on that avi and see what you get? regards Simon
__________________
http://www.geocities.com/siwalters_uk/fnews.html |
30th September 2002, 18:06 | #18 | Link |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
Phew - I was getting worried
If anyones got the time (and the system that Mpeg2Source works on) maybe they could post some results with an MPEG-2 TFF=true and TFF =false to see if its being picked up correctly regards Simon
__________________
http://www.geocities.com/siwalters_uk/fnews.html |
30th September 2002, 22:39 | #20 | Link |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
@Warp - thanks
I've updated a few filter descriptions in the Wiki to let others know. regards Simon
__________________
http://www.geocities.com/siwalters_uk/fnews.html |
Thread Tools | Search this Thread |
Display Modes | |
|
|