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. |
8th April 2004, 12:29 | #1 | Link |
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 (). |
10th April 2004, 09:11 | #3 | Link |
German doom9/Gleitz SuMo
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). |
10th April 2004, 14:17 | #4 | Link |
interlace this!
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 |
10th April 2004, 23:26 | #5 | Link | |
German doom9/Gleitz SuMo
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,782
|
Quote:
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. |
|
11th April 2004, 14:56 | #6 | Link |
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 (). |
11th April 2004, 21:50 | #8 | Link |
German doom9/Gleitz SuMo
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". |
11th April 2004, 23:54 | #10 | Link | ||
German doom9/Gleitz SuMo
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:
|
||
14th April 2004, 12:10 | #11 | Link |
Fascinated Lurker
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... |
14th April 2004, 12:38 | #12 | Link |
German doom9/Gleitz SuMo
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...
|
14th April 2004, 13:17 | #13 | Link |
Fascinated Lurker
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() 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. |
14th April 2004, 13:54 | #14 | Link |
brainless
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. |
14th April 2004, 14:32 | #15 | Link |
Fascinated Lurker
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() |
14th April 2004, 15:02 | #16 | Link |
Fascinated Lurker
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. |
15th April 2004, 13:28 | #17 | Link |
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 |
15th April 2004, 13:56 | #19 | Link |
Life's clearer in 4K UHD
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. |
15th April 2004, 18:11 | #20 | Link |
German doom9/Gleitz SuMo
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!
|
|
|