Quantcast Avisynth: Guide to Dealing with Interlaced Sources - digitalFAQ.com Forums [Archives]
  #1  
09-04-2004, 03:48 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
Added August 2nd, 2007: See this post for a more up-to-date sample script: http://www.kvcd.net/forum/viewtopic.php?p=127192#127192

OK, since I've been writing the same things a lot recently, I decided to write a small guide regarding interlaced sources. It's also easy to keep the information up-to-date as recommended scripts and plugins tend to change over time. If anyone has any suggestions, corrections or questions, please post them in this thread so it will be easier for me to notice them. Note that I assume you know how to use Avisynth, load plugins etc. so I'm not answering questions related to those areas in here. Read http://www.avisynth.org/YourFirstScript if you don't know that stuff.

This guide applies to both PAL and NTSC. It's meant for keeping the material interlaced, so it's mostly for DVD encodes.

The only additional plugin you need is KernelDeint. You should have version 1.5 or above since those versions include the function KernelBob which is used in the script. The plugin can be downloaded at http://www.avisynth.org/warpenterprises or at http://forum.doom9.org/showthread.php?s=&threadid=81322 . Download it and extract to your Avisynth 2.5 plugins folder. The default it is C:\Program Files\Avisynth 2.5\plugins. The rest of the plugins depend on what filters you use.

Step one. Determining the field order

Create a script with the following lines in it:

Code:
MPEG2Source("path\clip.d2v") or AVISource("path\clip.avi")
AssumeTFF()
SeparateFields()
Open it in VirtualDub. Advance in the script frame-by-frame. Is the motion smooth? If it is, you have top field first video. If the motion jerks back and forth, you have bottom field first video. You'll need this information later.

Step two. The script

I'll only give a very basic script here. You can add all the filters you normally use and they can be used just as with any progressive source. The only thing is that they need to be placed between the KernelBob and SeparateFields lines.

Code:
MPEG2Source("path\clip.d2v") or AVISource("path\clip.avi")
KernelBob(order=x,sharp=true,threshold=7)
AssumeFrameBased()
#
#
#Place all the cropping, filtering, resizing, adding borders here!
#
#
ConverttoYUY2() # if you use CCE, if not, remove the line!
AssumeBFF()
SeparateFields()
SelectEvery(4,1,2) # SelectEvery(4,0,3) for bottom field first video
Weave()
You'll have to replace the order=x parameter with order=1 if you have top field first video or order=0 if you have bottom field first. Also see that the SelectEvery line is the right one for your field order.

That's it! Now you just have to encode the material correctly, i.e. encode as interlaced and with a correct field order set.

--------------------------------------

And upon request, two ways to convert pure interlaced 29.97fps (NTSC) stream to a 25fps (PAL) one. If your source material isn't pure interlaced video, you should either enable Force FILM in DVD2AVI or do an inverse telecine by using Telecide and Decimate, both in the Decomb package.

Don't forget to do the framerate conversion for the audio as well!

First method

This method will result in a 25fps progressive video, so you can encode as progressive and save some bits. The smoothness will take a slight hit, but there is no way for a perfect conversion without expensive professional programs and dedicated hardware.

Download MVTools here : http://jourdan.madism.org/~manao/MVTools-v0.9.3.zip

First, determine the field order as explained earlier in this post.

Then use this script to encode:

Code:
MPEG2Source("path\clip.d2v") or AVISource("path\clip.avi")
KernelBob(order=x,sharp=true,threshold=7)
AssumeFrameBased()
MVConvert60ito24p()

#
#
# Crop,resize,filter and add borders normally
#
#

AssumeFPS(25.000)

function mvconvert60ito24p(clip x, int "mode") 
{ 

mode = default(mode,2) 
mbl=0.1 

vectorsforward = x.mvanalyse(isb = false) 
vectorsbackward = x.mvanalyse(isb = true) 

y = x.mvinterpolate(vectorsbackward, vectorsforward, nb = 4, bl = 0.5 - mbl, el = 0.5 + mbl, wf = "hat") 

interleave(y,x) 
mode0=selectevery(5,2) 
mode1=overlay(selectevery(5,3),selectevery(5,2),opacity=0.5) 
mode2=overlay(overlay(selectevery(5,1),selectevery(5,3),opacity=0.5),selectevery(5,2),opacity=0.3) 
mode3=overlay(overlay(selectevery(5,0),selectevery(5,3),opacity=0.5),overlay(selectevery(5,1),selectevery(5,2),opacity=0.5),opacity=0.5) 

(mode==0) ? mode0 : (mode==1) ? mode1 : (mode==2) ? mode2 : mode3 

}
Remember to replace order=x by order=1 for top field first video or order=0 for bottom field first.



Second method

See Scharfis_brain's method as well, it's later in this thread.

This method will result in a 25fps interlaced video. There may be artifacts and blended fields, but motion should be smooth.

Once again, determine the field order.

Then use this script, encode as interlaced with the correct field order set:

Code:
MPEG2Source("path\clip.d2v") or AVISource("path\clip.avi")
KernelBob(order=x,sharp=true,threshold=7)
AssumeFrameBased()
ConverttoYUY2()
ConvertFPS(50)

#
#
# Crop,resize,filter and add borders normally
#
#

AssumeBFF()
SeparateFields()
SelectEvery(4,1,2) # SelectEvery(4,0,3) for bottom field first
Weave()
Replace order=x by order=1 for top field first video and order=0 for bottom field first. Don't forget to choose the correct SelectEvery parameters for your source.
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  
09-04-2004, 06:59 AM
Prodater64 Prodater64 is offline
Free Member
 
Join Date: Mar 2003
Location: Palma de Mallorca - España
Posts: 2,925
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Boulder, I like your guide.
Can you post something about NTSC interlaced to PAL?
Reply With Quote
  #3  
09-04-2004, 07:31 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
You probably don't want to go that way

There are two ways to convert a pure interlaced 29.97fps stream into a 25fps one. One will result in a progressive video and the other in an interlaced one.

I'll post them both to the first thread. You'll have to remember that I've not tried either one of them myself so they may or may not work. Your Mileage May Vary, as they say
Reply With Quote
  #4  
09-04-2004, 08:08 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
The two methods for 29.97fps to 25fps conversion are now added to the first post. They can be extremely slow, especially the one including the function MVConvert60ito24p(). If it's too slow, it might be a good idea to put ConverttoYUY2() at the end of the script and save in HuffYUV in VirtualDubMod (using fast recompress) if you have the required huge amount of diskspace and then process the saved AVI file directly in TMPGEnc/CCE/FreeEnc.
Reply With Quote
  #5  
09-05-2004, 03:32 AM
muaddib muaddib is offline
Free Member
 
Join Date: Jun 2002
Location: São Paulo - Brasil
Posts: 879
Thanks: 0
Thanked 0 Times in 0 Posts
Great guide Boulder!
I never tried "KernelBob" before.
I'll make some tests with it.
Reply With Quote
  #6  
09-05-2004, 03:52 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
The good thing about KernelBob compared to a simple Bob() is that being a smart bob it keeps a lot more details and gives a slightly sharper image too
Reply With Quote
  #7  
09-05-2004, 02:22 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
Nice guide ...

Also do have a look at TMCbob() as it gots some more nice advantages. I dunno remeber now if in case of scaling or fitering. But you should have a look at it.
Reply With Quote
  #8  
10-09-2004, 10:09 PM
Prodater64 Prodater64 is offline
Free Member
 
Join Date: Mar 2003
Location: Palma de Mallorca - España
Posts: 2,925
Thanks: 0
Thanked 0 Times in 0 Posts
How about JDL functions?
Reply With Quote
  #9  
10-10-2004, 02:13 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
The functions are faster and nice *but* they produce a blurrier image. It's also not a "real" way to process interlaced material as they simply put top field on the top of the frame and bottom field to the lower part of the frame.

There is always unwanted interference in the part where the top field area ends and bottom field area begins, even with the flip=true parameter. Thus this approach cannot be recommended if you want good quality.

The latest way is by using TDeint() as the smart bobber, but it's way too slow to be useful.
Reply With Quote
  #10  
10-11-2004, 06:51 PM
Prodater64 Prodater64 is offline
Free Member
 
Join Date: Mar 2003
Location: Palma de Mallorca - España
Posts: 2,925
Thanks: 0
Thanked 0 Times in 0 Posts
I have The Matrix in PAL format and DVD2AVI info shows me that it is interlaced. But I can't see any combing effect. Also previewing with VirtualDubMode the diagnosis scripts with assumeTFF and assumeBFF, it plays smooth both scripts.
How must I understand that.
Is there a general rule for PAL material?
Reply With Quote
  #11  
10-12-2004, 12:16 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
The material is progressive. You must trust your eyes, DVD2AVI will only tell you how the stream is flagged and must not be trusted.
Reply With Quote
  #12  
10-12-2004, 05:02 PM
Leksa Leksa is offline
Free Member
 
Join Date: Apr 2003
Location: Finland
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
How about Bitrate Viewer? Can I trust the specs the program gives about a movie?
Reply With Quote
  #13  
10-13-2004, 12:45 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
Nope, it will probably report the same as DVD2AVI. The only thing you can trust is checking for the combing by your own eyes.

99% of all "Hollywood" movies are progressive. The 1% comes from incorrect transfer from NTSC to PAL. If you know that the original material is in fact progressive (FILM) and the PAL version has combing, you should go for the Restore24 method to restore the original progressive frames at 23.976fps and then speedup the video and audio to 25fps.
Reply With Quote
  #14  
10-13-2004, 03:36 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
If PAL Material is combed and its shure that the original source WAS shot on Film, then the following steps should be used in the following order of try outs:

1.
mpeg2source("CombedPALmovie.d2v")
doubleweave().selectodd()

A simple inverse of a "static" field shift will be performed, and if that not works...



2.
mpeg2source("CombedPALmovie.d2v")
Telecide(order=1,guide=2,post=0)

An inverse "dynamical" field shift will be performed, and if that not works...



3.
mpeg2source("CombedPALmovie.d2v")
Restore24(AA,BB)

Restore24: http://forum.gleitz.info/attachment....chmentid=68866

Trys to inverse a fieldblended decimation/conversion from 29.976 to direct 25fps



4.
And finnaly if you deal with StarTrek TNG Sources you can try Scharfis_Brain's "repairPAL_TNG_DVD()" Function. It can be found at doom9.org but as it has become that damn slow to search (that forum) you should search by yourself
Reply With Quote
  #15  
10-13-2004, 03:42 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
Ah, I forgot field/phase shifting..thanks for clearing that up!
Reply With Quote
  #16  
10-16-2004, 03:26 AM
scharfis_brain scharfis_brain is offline
Free Member
 
Join Date: Nov 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Better do the NTSC <-> PAL conversions this way:

Code:
function tmcbob(clip i)
{i.doubleweave().tomsmocomp(-1,5,0)}

xxxsource("video.xxx")
x=tmcbob()
y=x.trim(1,0)
x.mergeluma(y,0.5).mergechroma(y,0.5)
convertfps(50) #or 59.94
assumebff() #for BFF-Out or assumetff() for TFF-output
separatefields().selectevery(4,0,3).weave()
it is two downsides:
- much more motionblur
- requires footage shot with 1/60 (NTSC) 1/50 (PAL) second shutter, shorter shutter will result in ghosting.

advandages: heavily reduced annoying border scrolling!

(also, I tend to use mvconvertfps for that task, but it currently has some weird behaviours making it not really useful for genral purposes )
Reply With Quote
  #17  
10-22-2004, 01:42 AM
Prodater64 Prodater64 is offline
Free Member
 
Join Date: Mar 2003
Location: Palma de Mallorca - España
Posts: 2,925
Thanks: 0
Thanked 0 Times in 0 Posts
Hi:
1 - Where to put Kwag's MA script or Dialhot's V series scripts in following one. (Post complete sample script please).
Code:
MPEG2Source("path\clip.d2v") or AVISource("path\clip.avi") 
KernelBob(order=x,sharp=true,threshold=7) 
AssumeFrameBased() 
MVConvert60ito24p() 

# 
# 
# Crop,resize,filter and add borders normally 
# 
# 

AssumeFPS(25.000) 

function mvconvert60ito24p(clip x, int "mode") 
{ 

mode = default(mode,2) 
mbl=0.1 

vectorsforward = x.mvanalyse(isb = false) 
vectorsbackward = x.mvanalyse(isb = true) 

y = x.mvinterpolate(vectorsbackward, vectorsforward, nb = 4, bl = 0.5 - mbl, el = 0.5 + mbl, wf = "hat") 

interleave(y,x) 
mode0=selectevery(5,2) 
mode1=overlay(selectevery(5,3),selectevery(5,2),opacity=0.5) 
mode2=overlay(overlay(selectevery(5,1),selectevery(5,3),opacity=0.5),selectevery(5,2),opacity=0.3) 
mode3=overlay(overlay(selectevery(5,0),selectevery(5,3),opacity=0.5),overlay(selectevery(5,1),selectevery(5,2),opacity=0.5),opacity=0.5) 

(mode==0) ? mode0 : (mode==1) ? mode1 : (mode==2) ? mode2 : mode3 

}

2 - I read in avisynth.org web site that not all interlaced video is fieldbased. Is it true? What percentage of interlaced video is not fieldbased (or is framebased)?
Reply With Quote
  #18  
10-22-2004, 12:12 PM
Peter1234 Peter1234 is offline
Free Member
 
Join Date: Feb 2003
Posts: 237
Thanks: 0
Thanked 0 Times in 0 Posts
All interlaced video has two fields per frame. If the two fields are captured at different times, consecutively, then the video is standard interlaced. If both fields are captured at same time, then the video can be called progressive since it is possible to re-generate a progressive frame from the two fields. A DVD usually is progressive since both fields are captured from one film frame.
Reply With Quote
  #19  
10-23-2004, 04:41 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
You'll simply place all the processing in the portion between the conversion from 60i to 24p and AssumeFPS(25). After the MVConvert60ito24p() line the video is progressive and at 23.976fps.

Using MVConvert60ito24p() is dead slow so you might want to save an intermediate HuffYUV compressed file (remember to convert to YUY2 in the script if you do that) and then process this file as you normally would process any DVD. Another option is to use the version Kwag posted, it will produce a slightly softer video but looks good too.

Code:
MPEG2Source("path\clip.d2v") or AVISource("path\clip.avi") 
KernelBob(order=x,sharp=true,threshold=7) 
AssumeFrameBased() 
MVConvert60ito24p() 

# 
# 
# All the normal script items here
# 
# 

AssumeFPS(25.000) 

function mvconvert60ito24p(clip x, int "mode") 
{ 

mode = default(mode,2) 
mbl=0.1 

vectorsforward = x.mvanalyse(isb = false) 
vectorsbackward = x.mvanalyse(isb = true) 

y = x.mvinterpolate(vectorsbackward, vectorsforward, nb = 4, bl = 0.5 - mbl, el = 0.5 + mbl, wf = "hat") 

interleave(y,x) 
mode0=selectevery(5,2) 
mode1=overlay(selectevery(5,3),selectevery(5,2),opacity=0.5) 
mode2=overlay(overlay(selectevery(5,1),selectevery(5,3),opacity=0.5),selectevery(5,2),opacity=0.3) 
mode3=overlay(overlay(selectevery(5,0),selectevery(5,3),opacity=0.5),overlay(selectevery(5,1),selectevery(5,2),opacity=0.5),opacity=0.5) 

(mode==0) ? mode0 : (mode==1) ? mode1 : (mode==2) ? mode2 : mode3 

}
Reply With Quote
  #20  
10-23-2004, 05:18 AM
Prodater64 Prodater64 is offline
Free Member
 
Join Date: Mar 2003
Location: Palma de Mallorca - España
Posts: 2,925
Thanks: 0
Thanked 0 Times in 0 Posts
@Boulder

Please, an answer to my second previous question?
Reply With Quote
Reply




Similar Threads
Thread Thread Starter Forum Replies Last Post
KVCD: Interlaced/29.970 sources? gretagun Video Encoding and Conversion 13 01-08-2005 02:29 PM
Avisynth: Interlaced sources guide? [See pg2] J-Wo Avisynth Scripting 50 04-20-2004 07:41 AM
Avisynth: MA script for interlaced sources? Boulder Avisynth Scripting 52 04-03-2004 02:47 PM
DVD2SVCD: Script for Interlaced sources azel Video Encoding and Conversion 3 11-02-2003 11:29 AM
VirtualDub: Correcting Field Order and Swapping in interlaced sources ozjeff99 Video Encoding and Conversion 9 05-16-2003 02:21 AM

Thread Tools



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