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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 27th September 2002, 14:06   #1  |  Link
trbarry
Registered User
 
trbarry's Avatar
 
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)}
Run the function with something like:

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.
trbarry is offline   Reply With Quote
Old 27th September 2002, 16:12   #2  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Hollola, Finland
Posts: 4,324
Thanks Tom, this is greatly appreciated!
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...
Boulder is online now   Reply With Quote
Old 27th September 2002, 16:33   #3  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,295
Less work:

clip=AviSource("C:\Temp\synchro_external.AVI")
clip.subtitle(String(clip.GetParity?"TopFirst":"BottomFirst"), font="MS UI Gothic")
Wilbert is offline   Reply With Quote
Old 27th September 2002, 17:27   #4  |  Link
wotef
Registered User
 
wotef's Avatar
 
Join Date: Apr 2002
Posts: 272
both are cool, thanks - but wilbert where did getparity come from?
i see nothing on avisynth.org nor through a search here
wotef is offline   Reply With Quote
Old 27th September 2002, 17:36   #5  |  Link
trbarry
Registered User
 
trbarry's Avatar
 
Join Date: Oct 2001
Location: Gainesville FL USA
Posts: 2,092
What does GetParity do? I thought Avisynth just assume a clip was bottom first unless you told it different.

- Tom
trbarry is offline   Reply With Quote
Old 27th September 2002, 17:39   #6  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,295
Quote:
both are cool, thanks - but wilbert where did getparity come from? I see nothing on avisynth.org nor through a search here
It's not there yet. You can find it on the project page, scroll down to clip-properties.

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.
Wilbert is offline   Reply With Quote
Old 27th September 2002, 19:42   #7  |  Link
Si
Simply me
 
Si's Avatar
 
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
Si is offline   Reply With Quote
Old 28th September 2002, 13:38   #8  |  Link
wotef
Registered User
 
wotef's Avatar
 
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
wotef is offline   Reply With Quote
Old 28th September 2002, 15:39   #9  |  Link
trbarry
Registered User
 
trbarry's Avatar
 
Join Date: Oct 2001
Location: Gainesville FL USA
Posts: 2,092
Quote:
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?
I've considered that for some time, and it wouldn't be hard to implement but for 2 issues:

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
trbarry is offline   Reply With Quote
Old 28th September 2002, 20:00   #10  |  Link
niiyan
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:
Originally posted by trbarry
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.
You mean,if the value for the Avg Mean Abs Dev is lower,that field is First?

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)
niiyan is offline   Reply With Quote
Old 28th September 2002, 20:25   #11  |  Link
trbarry
Registered User
 
trbarry's Avatar
 
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
trbarry is offline   Reply With Quote
Old 28th September 2002, 21:47   #12  |  Link
Marc FD
XviD fan
 
Marc FD's Avatar
 
Join Date: Jun 2002
Location: France
Posts: 907
i know i've inverted the parity value in MPEG2DecPP (finally i need to give this a name)
because it seemed to be always false.
Marc FD is offline   Reply With Quote
Old 29th September 2002, 17:42   #13  |  Link
niiyan
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.
niiyan is offline   Reply With Quote
Old 29th September 2002, 17:55   #14  |  Link
Si
Simply me
 
Si's Avatar
 
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
Si is offline   Reply With Quote
Old 29th September 2002, 18:54   #15  |  Link
niiyan
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
niiyan is offline   Reply With Quote
Old 29th September 2002, 22:23   #16  |  Link
Si
Simply me
 
Si's Avatar
 
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
Si is offline   Reply With Quote
Old 30th September 2002, 17:40   #17  |  Link
niiyan
Registered User
 
Join Date: Sep 2002
Posts: 88
@siwalters

I tested UnRecompressed avi and DivX codec avi.
Both are captured as MPEG2 and encoded by AviUtl or VirtualDub.
When I use those AVI files,Getparity script shows BottomFirst.

-niiyan
niiyan is offline   Reply With Quote
Old 30th September 2002, 18:06   #18  |  Link
Si
Simply me
 
Si's Avatar
 
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
Si is offline   Reply With Quote
Old 30th September 2002, 21:32   #19  |  Link
WarpEnterprises
C64
 
WarpEnterprises's Avatar
 
Join Date: Apr 2002
Location: Austria
Posts: 831
MPEG2SOURCE does it correctly - tested.
WarpEnterprises is offline   Reply With Quote
Old 30th September 2002, 22:39   #20  |  Link
Si
Simply me
 
Si's Avatar
 
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
Si is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 17:43.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2017, vBulletin Solutions Inc.