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
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 8th April 2004, 12:29   #1  |  Link
actionman133
Movie buff & shine
 
Join Date: Jan 2004
Location: Logan, the only hole above ground.
Posts: 257
automated detection for interlacing?

im trying to make some automated code for determining whether a clip is compressed interlaced or progressive, but i havent been able to find any IsInterlaced function or the like. IsPlanar seems to return True on interlaced clips and False on progressive, but that may be coincidental.

i want to know so that the clip will be sampled correctly when it is converted from YV12 to YUY2, automatically. if IsPlanar the right way to go i can simply do:

ConvertToYUY2 (IsPlanar)

is IsPlanar the way to go or is there a proper function for testing whether the clip is interlaced? by the way, these clips are loaded by MPEG2Source.
__________________
I'm a boxer who can Bob () & Weave (). I like to Overlay () punches and Blur () his vision to ShowFiveVersions (). My KO punch will always Pulldown ().TimeStretch () and all he will hear is Tone ().
actionman133 is offline   Reply With Quote
Old 8th April 2004, 13:55   #2  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
The Decomb filter package has an IsCombed() function. But it is usable only within the Avisynth ConditionalFilter(). That may serve your needs.
Guest is offline   Reply With Quote
Old 10th April 2004, 09:11   #3  |  Link
LigH
German doom9/Gleitz SuMo
 
LigH's Avatar
 
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,782
YV12 is always "planar"; this is not related to "interlaced".

"Planar" video formats (like YV12) store all the component parts of each pixel (respective subsampling averages) together independently, e.g. first all Y pixel components, then all V (2 pixel)² components, and finally all U (2 pixel)² components.

In contrast, "packed" video formats (like YUY2, UYVY, or RGB[A]) store pixel by pixel with all components (e.g. Y for the first pixel, U for both first, Y for the second, V for both first - then the next 2 pixels follow).
LigH is offline   Reply With Quote
Old 10th April 2004, 14:17   #4  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
with YV12 source:

converttoyuy2(interlaced=true)

that should do you

comb detection is one of the big conundrums of video. a human can tell by looking at a frame if there's interlacing, but a computer cannot tell this as easily (ie. at a reasonable speed).
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 10th April 2004, 23:26   #5  |  Link
LigH
German doom9/Gleitz SuMo
 
LigH's Avatar
 
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,782
Quote:
Originally posted by Mug Funky
with YV12 source:

converttoyuy2(interlaced=true)
Oh, well - there are two different questions, and everyone shall not try to answer both of them in the same line:

1) Is the video stream interlaced?

That means: Was the encoder once set up to encode video frames as separate fields?

This question shall be answered by the function "IsInterlaced()". If the MPEG2 stream has its flags set according to the meaning "interlaced MPEG encoding", I hope that the function "MPEG2Source()" will set this video clip attribute accordingly. But even progressive content is often encoded with interlaced flags...

If the video was encoded as interlaced (the usuall rippers, or the DVD2AVI preview, or the Bitrate Viewer, will report this stream bitflag), one shall use 'MPEG2Source("*.d2v", iPP=true)' and 'ConvertToYUY2(interlaced=true)', for progressive encoding both shall be false - else miscoloring may be the result.

See examples 1 | 2 | 3 for accidently progressive processing of an interlaced video stream in YV12

2) Is the video content interlaced?

That means: Are there two different fields in the same frame, recorded at two different timestamps, visible by two weaved pairs of alternating lines?

This is the fact which the filter "IsCombed()" tries to detect.

Last edited by LigH; 10th April 2004 at 23:43.
LigH is offline   Reply With Quote
Old 11th April 2004, 14:56   #6  |  Link
actionman133
Movie buff & shine
 
Join Date: Jan 2004
Location: Logan, the only hole above ground.
Posts: 257
LigH has gotten the concept right: if the video is encoded in an interlaced format, even if the image APPEARS to be progressive.

and the simple 'ConvertToYUY2 (Interlaced = True)' is not right because I want this code to be in an importable script where any given source can be interlaced or progressive... therefore it needs to detect which method it was encoded with and convert accordingly.

LigH, you mentioned using an IsInterlaced() function... it doesn't work, saying that there is no such fuction. I'm running version 2.54 at the moment. Does 2.55 have it?
__________________
I'm a boxer who can Bob () & Weave (). I like to Overlay () punches and Blur () his vision to ShowFiveVersions (). My KO punch will always Pulldown ().TimeStretch () and all he will hear is Tone ().
actionman133 is offline   Reply With Quote
Old 11th April 2004, 21:26   #7  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
Quote:
IsInterlaced() function
AFAIK there is no such function. dvd2avi/mpeg2dec3 could be modified to return a flag for this ...
Wilbert is offline   Reply With Quote
Old 11th April 2004, 21:50   #8  |  Link
LigH
German doom9/Gleitz SuMo
 
LigH's Avatar
 
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,782
Sorry...

There are the following "clip attributes" related to this topic:

IsFieldBased() / IsFrameBased(); GetParity()

I'd say that "IsFieldBased" is most similar to "was it encoded with interlaced flag".
LigH is offline   Reply With Quote
Old 11th April 2004, 23:27   #9  |  Link
Richard Berg
developer wannabe
 
Richard Berg's Avatar
 
Join Date: Nov 2001
Location: Brooklyn, NY
Posts: 1,211
No, IsFieldBased() returns whether each frame is actually a half-height field, e.g. after a SeparateFields was performed.
Richard Berg is offline   Reply With Quote
Old 11th April 2004, 23:54   #10  |  Link
LigH
German doom9/Gleitz SuMo
 
LigH's Avatar
 
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,782
Wow.

So is there no hint from any clip attribute, if I shall use "ConvertToYUY2(interlaced=true)" or "ConvertToYUY2(interlaced=false)"? I'm afraid I'm getting slightly confused...
___

I just checked the following:
  • I created a small clip using AviSynth:
    Code:
    ColorBars(720,576)
    AssumeFPS(25)
    Trim(0,249)
  • I encoded it to progressive (frame based) MPEG2 video (p.m2v) on one hand, and to interlaced (field based) MPEG2 video (i.m2v) on the other.
  • I compared the information on the progressive and the interlaced video with AviSynth and MPEG2Dec3:
    Code:
    LoadPlugin("E:\Programme\Gordian Knot\mpeg2dec3.dll")
    p=MPEG2Source("p.d2v",iPP=false).Info()
    i=MPEG2Source("i.d2v",iPP=true).Info()
    Subtract(i,p).Levels(96,1.0,160,0,255)
    Guess the resulting image...
    Quote:
    Plain gray?
    Yes, you are right.
  • Now I tried the same with video converted to YUY2:
    Code:
    LoadPlugin("E:\Programme\Gordian Knot\mpeg2dec3.dll")
    p=MPEG2Source("p.d2v",iPP=false).ConvertToYUY2(interlaced=false).Info()
    i=MPEG2Source("i.d2v",iPP=true).ConvertToYUY2(interlaced=true).Info()
    Subtract(i,p).Levels(96,1.0,160,0,255)
    Now guess again the resulting image...
    Quote:
    Plain gray again?
    This time, you are wrong!
And now I sit there in my corner and wonder why AviSynth 2.5 provides enhanced support for interlaced video...
LigH is offline   Reply With Quote
Old 14th April 2004, 12:10   #11  |  Link
zettai
Fascinated Lurker
 
zettai's Avatar
 
Join Date: Feb 2002
Location: Durham, UK
Posts: 243
So does this mean that in Avisynth there is currently no way of telling if an mpeg2 source is encoded as interlaced except looking to see whether seeing interlacing=true in a colourspace conversion looks better?

If interlacing is just an mpeg2 flag then it could easily be set incorrectly...
zettai is offline   Reply With Quote
Old 14th April 2004, 12:38   #12  |  Link
LigH
German doom9/Gleitz SuMo
 
LigH's Avatar
 
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,782
Not really - there are several flags related to interlaced encoding of MPEG-2 video. bbMPEG has the most detailed Advanced options (practically, you may set up each bit flag in an MPEG header), and there are 3 settings: "Progressive Sequence", "Progressive Frame", and "Field Pictures". The difference seems to be "very slightly" at first, but I'm afraid that they are much more important...
LigH is offline   Reply With Quote
Old 14th April 2004, 13:17   #13  |  Link
zettai
Fascinated Lurker
 
zettai's Avatar
 
Join Date: Feb 2002
Location: Durham, UK
Posts: 243
Well either I am understanding this wrong but it seems that unless we can get the frame type from dvd2avi then we can have problems.

Here's a little test I did with some easily identifiable chroma areas on a hybrid NTSC source that (in dvd2avi) stores some frames as "progressive" and others as "interlaced" but is mostly NTSC in the Video Type.

Code:
function CheckUpsampling(clip a) {

b=converttoYUY2(a,interlaced=false).crop(270,180,-270,-180)
\.pointresize(360,480).subtitle("interlaced=false")

c=converttoYUY2(a,interlaced=true).crop(270,180,-270,-180)
\.pointresize(360,480).subtitle("interlaced=true")

stackhorizontal(b,c)
}

MPEG2Source("L:\BCBA_0619\suprgals2.d2v")
CheckUpsampling()
Frame 378

In this first one it suggests that we should use interlaced=false. Fine.

Frame 381

Uh-oh.. now we get an interlaced frame. It certainly looks to me that interlaced=true is the way to go.

Of course if you don't specify which to do then ConvertToYUY2 will just use interlaced=false.

So what can you do? Well, I'm not sure to be honest. It would be fine if all the frames had the same result but with a source like this (where I can't force film because it is a hybrid) I just don't know...

Selecting ipp=true in mpeg2source does noting as that is only for post processing deblock and dering.

In short, I'm lost

[EDIT: formatting change]

Last edited by zettai; 14th April 2004 at 13:21.
zettai is offline   Reply With Quote
Old 14th April 2004, 13:54   #14  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,653
how about a consturct like this:

scriptclip(x,"x.converttoyuy2(interlaced=iscombed(x,20))")

I don't know whether its syntax is correct, but I assum you can imagoine, what I mean
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.
scharfis_brain is offline   Reply With Quote
Old 14th April 2004, 14:32   #15  |  Link
zettai
Fascinated Lurker
 
zettai's Avatar
 
Join Date: Feb 2002
Location: Durham, UK
Posts: 243
Yeah, IsCombed does the trick pretty well.

Code:
function CheckUpsampling(clip a) {

b=converttoYUY2(a,interlaced=false)
\.crop(270,180,-270,-180).pointresize(360,480).subtitle("interlaced=false")
c=converttoYUY2(a,interlaced=true).crop(270,180,-270,-180)
\.pointresize(360,480).subtitle("interlaced=true")
d=conditionalfilter(a,b,c,"IsCombed","equals","false").subtitle("iscombed")
stackhorizontal(b,c,d)
}

MPEG2Source("L:\BCBA_0619\suprgals2.d2v")
CheckUpsampling()
gives this version of frame 378 and then this version of frame 381
zettai is offline   Reply With Quote
Old 14th April 2004, 15:02   #16  |  Link
zettai
Fascinated Lurker
 
zettai's Avatar
 
Join Date: Feb 2002
Location: Durham, UK
Posts: 243
The thing I'm not quite understanding is why dvd2avi and mpeg2dec can't tell us what kind of frame type we have and what sort of processing is required.

I mean, this dvd is obviously encoded so that a DVD player can play it back without upsampling the chroma incorrectly every few frames... and sure enough on this source some of the frames are labelled as Progressive and others are labelled as Interlaced but there seems to be no procedure for dvd2avi to communicate this information via mpeg2dec (unless I just haven't spotted it yet)

Surely there should be some sort of hint that you can enable to allow mpeg2dec to define whether a certain frame is or is not progressively encoded that can be picked up by avisynth filters such as ConvertToYUY2 when changing colourspace.

Of course, there is the chance that the frame type is labelled incorrectly but that's another issue that would probably need resolving with IsCombed. However, I don't see why we should have to use something like IsCombed when a properly encoded mpeg2 stream should be able to tell us automatically how to deal with the data.
zettai is offline   Reply With Quote
Old 15th April 2004, 13:28   #17  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
Upsampling issues are on my work list for DVD2AVIdg/MPEG2DEC3dg. Maybe you will get your wish.

http://neuron2.net/misc/Work_List.html
Guest is offline   Reply With Quote
Old 15th April 2004, 13:31   #18  |  Link
zettai
Fascinated Lurker
 
zettai's Avatar
 
Join Date: Feb 2002
Location: Durham, UK
Posts: 243
Thank you!

Good luck with the updates - I'm especially looking forward to this faster random frame access
zettai is offline   Reply With Quote
Old 15th April 2004, 13:56   #19  |  Link
SeeMoreDigital
Life's clearer in 4K UHD
 
SeeMoreDigital's Avatar
 
Join Date: Jun 2003
Location: Notts, UK
Posts: 12,227
This is a great idea. I mentioned something along these lines here: -

http://forum.doom9.org/showthread.php?s=&threadid=73880

I also provided a link to some Mpeg4 interlaced video content with the fields clearly identified.

Cheers

DEIT: spewling!
__________________
| I've been testing hardware media playback devices and software A/V encoders and decoders since 2001 | My Network Layout & A/V Gear |

Last edited by SeeMoreDigital; 15th April 2004 at 19:13.
SeeMoreDigital is offline   Reply With Quote
Old 15th April 2004, 18:11   #20  |  Link
LigH
German doom9/Gleitz SuMo
 
LigH's Avatar
 
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,782
But still, I even wonder how AviSynth stores frames internally in YV12 mode: YV12 video uses 4:2:0 chroma subsampling, therefore a chroma value represents the average of 4 pixels (2 besides and 2 above each other). If it stores them progressively, then one average represents the lines 1&2 and the next lines 3&4; if it stores them interlacedly, one average represents lines 1&3 and the next lines 2&4. But if no (clip / frame) attribute is available, then I wonder if AviSynth works this way at all!
LigH is offline   Reply With Quote
Reply


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 09:18.


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