digitalFAQ.com Forums [Archives]

digitalFAQ.com Forums [Archives] (http://www.digitalfaq.com/archives/)
-   Avisynth Scripting (http://www.digitalfaq.com/archives/avisynth/)
-   -   Avisynth: Guide to dealing with interlaced sources (http://www.digitalfaq.com/archives/avisynth/11922-avisynth-guide-dealing.html)

Boulder 10-23-2004 08:17 AM

I think Peter explained it well. See also here : http://www.kvcd.net/forum/viewtopic....14621&start=16 , especially Scharfi's post about the patterns observed when the unknown clip has been bob-deinterlaced.

Boulder 10-25-2004 03:01 AM

Edited the first script a little : AssumeBFF() added to ensure a certain field order in the final video.

jorel 10-26-2004 06:48 AM

@ Boulder
thank you my friend....
i remeber when you was helping me in lots of pms to understand how it works round 1 or 2 years ago .
thanks again(past,present and future) ! :D

Prodater64 11-13-2004 12:34 PM

@Boulder: Could you explain me how frames are managed in ntsc -> pal both methods.
I mean, you have 29.97 interlaced, in one of the scripts you use assumefps(25), it is no drop frames, but movie time changed, isn't it?
The other one uses convertfps(50). What does it mean? 29.97 to 50 fps. If convertfps works without inserting frames, I don't understand how do its work.
How we must to manage audio in both scripts?
It would be possible convert from 29.97 interlaced to 25 fps droping frames (less frames, same movie time) with a good result?

incredible 11-13-2004 02:44 PM

Assume FPS() is used IF you just pitch up from 23.976 to 25.000 (as that MVconvert60ito24p() does pre-convert to 23.976 out of 29.97 real interlaced )

Convertfps() is used IF you perform a fieldblended conversion out of real NTSC 29.97 interlaced video to 25.000.
The 29.97 will be bobbed to the fieldrate (=twice the framerate) and a convertFPS(50) will fieldblend convert to full PAL fieldrate, finally that resulted 50fps PAL stream will be reinterlaced to its PAL framerate 25.000

Prodater64 11-13-2004 03:12 PM

How about this 2 questions?

Quote:

Originally Posted by Prodater64

1 - How we must to manage audio in both scripts (is playing time changed)?

2 - It would be possible convert from 29.97 interlaced to 25 fps droping frames (less frames, same movie time) with a good result?


incredible 11-13-2004 09:25 PM

1. The audio sync is kept as assumefps(25,true) (I see that should be added!!) in both scripts do force the 23.976 resulted stream to finally end up in PAL 25.000.

2. In a direct way: NO. As it would bekome noticable jerky.
But if you do a fieldblended conversion from 29.97 to 25 in the known bobbed way then it works but the result is still interlaced.


http://home.arcor.de/scharfis_brain/...esInterlacing/
Its in german but THE best bible related to interlaced sources/scripting!
An online translator could make it understandable for you.

Surfinette 11-16-2004 06:24 AM

Hi everyone and thanks to Boulder for starting this post.

I just started to work on my own personal videos (captured with a PAL DV camcorder) hence I'm new to the subject of interlaced video. After hours of reading (through this forum notably), I discovered that this is tricky and most confusing for dumb newbies as myself (I'm trying hard to learn though). I therefore still have questions for the experts here.

OK, after editing my video, I end-up with an avi file in PAL format, interlaced BFF, which I want to turn into KVCD to be viewed on PAL TV

Here are my questions:

1) Is it right to assume that I do not need to deinterlace the video, since I will not watch it on a computer, but on TV only?

2) Or is there any reasons why I should still deinterlace it?

3) I'm not sure to understand the purpose of Boulder's sript:

Quote:

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()
If I understand correctly, you deinterlace the video first, before applying your usual script (crop, filter, resize...) then interlace the video again. Why deinterlace-interlace and not simply applying the usual script?
Are there cases where you don't need to go through all this deinterlace-interlace process while encoding to KVCD (if you do not apply any filtering for instance)?

4) Can Kwag optimal MA script be used with Boulder's above script?

5) Sometime ago, in another post Boulder was suggesting the following script for interlaced videos
Quote:

nf=0

MPEG2Source("path\video.d2v")

Crop(enter your values here, crop height mod 4, width mod 2!)

SeparateFields()
UnDot()
BicubicResize(enter your values here, height/2!)
MergeChroma(Blur(1.5))
MergeLuma(Blur(0.1)) # use only if the video won't get too blurry!
STMedianFilter(4,32,0,0)

SwitchThreshold = (Width<=352) ? 4 : (Width<=480) ? 3 : 2
even=SelectEven().ScriptClip("nf=YDifferenceToNext ()"+chr(13)+"nf>=SwitchThreshold?unfilter(-(fmin(round(nf)*2,100)),-(fmin(round(nf)*2,100))):TemporalSoften(fmin(round (2/nf),6),round(1/nf),round(3/nf),0,2)")
odd=SelectOdd().ScriptClip("nf=YDifferenceToNext() "+chr(13)+"nf>=SwitchThreshold?unfilter(-(fmin(round(nf)*2,100)),-(fmin(round(nf)*2,100))):TemporalSoften(fmin(round (2/nf),6),round(1/nf),round(3/nf),0,2)")
Interleave(even,odd)
Weave()

AddBorders here
Limiter()

function fmin( int f1, int f2) {
return ( f1<f2 ) ? f1 : f2
}
There seems to be 2 different approaches. What is best:
a) Bob-deinterlace - apply usual Script - Interlace
or
b) SeparteFields - apply usual Script separately to even and odd - Interleave(even,odd) - Weave

Which is the best of the 2 methods for Kwag's MA script?


6) Lastly a small technical issue. In its initial post, Boulder says

Quote:

That's it! Now you just have to encode the material correctly, i.e. encode as interlaced and with a correct field order set.
In TMPGEnc there is an option to encode the video as interlaced but I don't see that a field order can be set. Is this an issue? Does the field order need to be set the same way as in the original video?


Sorry :oops: for asking so many (stupid) questions and thanks for your help

Surfinette
A suggestion if I may, it would be worht having a Sticky post on Interlaced video script with the final (?!) conclusions of the experts

the viking 11-16-2004 07:16 AM

Ill try to answer you as far as I can: :wink:

1.Yes,its no need to deinterlace for Tv viewing,the encoded
video looks better when its interlaced(my opinion!)




4.Im not sure I never use it,I use Boulders.

5.someone else must answer to this

6.Goto "MPEG Setting"-"Advanced"-"Video Source Setting"-"Field Order" and yes it has to be set as it was in the original video,if not you
get a shaky picture on your tv.

----------------------
viking

EDIT:Read this about interlace/progressive stuff http://www.kvcd.net/forum/viewtopic.php?t=9808
it explains a lot

Boulder 11-16-2004 07:34 AM

Quote:

Originally Posted by Surfinette
I just started to work on my own personal videos (captured with a PAL DV camcorder) hence I'm new to the subject of interlaced video. After hours of reading (through this forum notably), I discovered that this is tricky and most confusing for dumb newbies as myself (I'm trying hard to learn though).

I agree that the concept can be very confusing. That was one factor why I decided to write the initial guide, which is far from perfect but which hopefully will cause some discussion - and fortunately it has :wink:

Quote:

1) Is it right to assume that I do not need to deinterlace the video, since I will not watch it on a computer, but on TV only?
True. If you have the bitrate to spare, encode as interlaced.

Quote:

2) Or is there any reasons why I should still deinterlace it?
The only case would be when doing a CVD or SVCD. The bitrate would probably get too low and you would get a blocky picture if you encoded as interlaced - unless the length of the video is rather short.

Quote:

3) I'm not sure to understand the purpose of Boulder's sript:

If I understand correctly, you deinterlace the video first, before applying your usual script (crop, filter, resize...) then interlace the video again. Why deinterlace-interlace and not simply applying the usual script?
Are there cases where you don't need to go through all this deinterlace-interlace process while encoding to KVCD (if you do not apply any filtering for instance)?
You cannot deinterlace and then re-interlace. The field information would be lost forever. See the Avisynth documentation and the Bob() section there. It will explain you bobbing much better than I ever could. I use KernelBob because it doesn't affect the non-moving parts, only the ones that are in motion (hence the term a smart bob). But as Inc already mentioned, for denoising a stupid bob might be better. For resizing, a smart bob is recommended.

Quote:

4) Can Kwag optimal MA script be used with Boulder's above script?
Yes it can.

Code:

Mpeg2Source("Your_D2V_Source_Here")
#

KernelBob(order=0,sharp=true,threshold=7)
AssumeFrameBased()

undot()
asharp(1, 4)
GripCrop(Your_GripCrop_Parameters_Here)
GripSize(resizer="BicubicResize")
STMedianFilter(3, 3, 1, 1 )
MergeChroma(blur(1.5))
MergeLuma(blur(0.1))
#
#

## Linear Motion Adaptive Filtering ##
#
# ( Portions from AviSynth's manual )
# This will apply variable temporalsoften
# and variable blur.
# Both filters are active at all times, and work inversely proportional to the
# activity, measured from current frame to next frame.

ScriptClip(" nf = YDifferenceToNext()" +chr(13)+ "unfilter( -(fmin(round(nf)*2, 100)), -(fmin(round(nf)*2, 100)) ).TemporalSoften( fmin( round(2/nf), 6), round(1/nf) , round(3/nf) , 1, 2)  ")

#
#
#

GripBorders()
#LetterBox( Your_Values_Here ) # Depends on situation. Use MovieStacker!

ConverttoRGB24()
AssumeBFF()
SeparateFields()
SelectEvery(4,0,3)
Weave()

function fmin( int f1, int f2) {
  return ( f1<f2 ) ? f1 : f2
}

This script is for a BFF video and TMPGEnc (the ConverttoRGB24() line was added because of that).

Quote:

5) Sometime ago, in another post Boulder was suggesting the following script for interlaced videos
Quote:

nf=0

MPEG2Source("path\video.d2v")

Crop(enter your values here, crop height mod 4, width mod 2!)

SeparateFields()
UnDot()
BicubicResize(enter your values here, height/2!)
MergeChroma(Blur(1.5))
MergeLuma(Blur(0.1)) # use only if the video won't get too blurry!
STMedianFilter(4,32,0,0)

SwitchThreshold = (Width<=352) ? 4 : (Width<=480) ? 3 : 2
even=SelectEven().ScriptClip("nf=YDifferenceToNext ()"+chr(13)+"nf>=SwitchThreshold?unfilter(-(fmin(round(nf)*2,100)),-(fmin(round(nf)*2,100))):TemporalSoften(fmin(round (2/nf),6),round(1/nf),round(3/nf),0,2)")
odd=SelectOdd().ScriptClip("nf=YDifferenceToNext() "+chr(13)+"nf>=SwitchThreshold?unfilter(-(fmin(round(nf)*2,100)),-(fmin(round(nf)*2,100))):TemporalSoften(fmin(round (2/nf),6),round(1/nf),round(3/nf),0,2)")
Interleave(even,odd)
Weave()

AddBorders here
Limiter()

function fmin( int f1, int f2) {
return ( f1<f2 ) ? f1 : f2
}

This is not a good method as the spatial arrangement of the fields will be incorrect when reinterlacing. As you can see, I've learned some things along the way :wink: The Bob() section of the AVS docs will explain this as well.

the viking 11-16-2004 08:41 AM

Boulder wrote:
Quote:

You cannot deinterlace and then re-interlace. The field information would be lost forever.
But isnt that what we are doing using this lines:

KernelBob(order=0,sharp=true,threshold=7)
AssumeFrameBased()
#
#
AssumeBFF()
SeparateFields()
SelectEvery(4,0,3)
Weave()

:?: :?:

The bob documentation on AviSynth page told me this:

Bob takes a clip and bob-deinterlaces it. This means that it enlarges each field into its own frame by interpolating between the lines. The top fields are nudged up a little bit compared with the bottom fields, so the picture will not actually appear to bob up and down. However, it will appear to "shimmer" in stationary scenes because the interpolation doesn't really reconstruct the other field very accurately.

Or does bob(),kernelbob() and others the deinterlacing job
another way than fielddeinterlace() and smoothdeinterlace() :?:

And yes I know that in interlace video the topfield-lines and
bottomfield-lines are "brodcasted" at different times,and thats
the reason why its hard to get the same quality when we deinterlace?
Deinterlaceing is a "compromise" between lines as the lines where
broadcasted at different times :?:

In other words,its not possible to deinterlace and get the same
quality as a film thats progressive originally??

Or am I totally lost(again) :?: :lol:

-----------------------
viking

Boulder 11-16-2004 08:54 AM

Quote:

Originally Posted by the viking
But isnt that what we are doing using this lines:

KernelBob(order=0,sharp=true,threshold=7)
AssumeFrameBased()
#
#
AssumeBFF()
SeparateFields()
SelectEvery(4,0,3)
Weave()

:?: :?:

The bob documentation on AviSynth page told me this:

Bob takes a clip and bob-deinterlaces it. This means that it enlarges each field into its own frame by interpolating between the lines. The top fields are nudged up a little bit compared with the bottom fields, so the picture will not actually appear to bob up and down. However, it will appear to "shimmer" in stationary scenes because the interpolation doesn't really reconstruct the other field very accurately.

Or does bob(),kernelbob() and others the deinterlacing job
another way than fielddeinterlace() and smoothdeinterlace() :?:

Like I said, I suck at explaining things :lol:

Bobbing only affects one field at a time, which means that it separates the fields and enlarges them to full height, that's why you get a doublerate output when using a bob filter. "Regular" deinterlacing either interpolates or blends information from the two different fields, "combining" them and that's why the field information is lost and cannot be restored.

Quote:

And yes I know that in interlace video the topfield-lines and
bottomfield-lines are "brodcasted" at different times,and thats
the reason why its hard to get the same quality when we deinterlace?
Deinterlaceing is a "compromise" between lines as the lines where
broadcasted at different times :?:
Exactly. That's why a deinterlaced stream looks jerky compared to a truly interlaced one. As I just wrote, the information is a combination of the two fields, which were originally broadcast at different times. If they are blended (FieldDeinterlace's default), the motion is smoother but ghosting may appear. If they are interpolated (KernelDeint, TDeint, FieldDeinterlace(blend=false) etc.), the motion will be jerkier but has far less ghosting.

Quote:

In other words,its not possible to deinterlace and get the same
quality as a film thats progressive originally??
True. You do not have the same amount of data (=detail) available anymore.

incredible 11-16-2004 08:56 AM

Quote:

Originally Posted by the viking
KernelBob(order=0,sharp=true,threshold=7)
AssumeFrameBased()
#
#
AssumeBFF()
SeparateFields()
SelectEvery(4,0,3)
Weave()

:?: :?:
...
...
...
Or does bob(),kernelbob() and others the deinterlacing job
another way than fielddeinterlace() and smoothdeinterlace() :?:

A bobber does unweave the fields! and brings them to full height by keepin the correct position! That "could" be seen also as deinterlacing but the result after bobbing is a full fieldrate (=twice the framerate)!
So after processing the filters the reinterlacer brings the fields back to their orig height and they will be weaved again.

If you just do denoising and/or a simple cropping like 720 to 704, I would just use a simple Bob(0,x) instead of an adaptive working Kerneldeint. If kerneldeint is used, then set it to th=0 and sharp=false. This keeps the fields in a best condition for denoising.
But if resizing is used, then kernelbob incl. ath and sharp is the choice.

Surfinette 11-16-2004 10:57 AM

Thanks, that were fast answers !

Boulder wrote
Quote:

The only case would be when doing a CVD or SVCD. The bitrate would probably get too low and you would get a blocky picture if you encoded as interlaced - unless the length of the video is rather short.
But isn't it the same for (S)KVCD, ie low bitrate?

I guess I was not too clear with my 3rd question:
Quote:

I'm not sure to understand the purpose of Boulder's sript:
I meant that I do not understand why, in some cases without any heavy filtering, an interlaced video can't be processed directly without playing around with Bob or any function that would allow a individual crop/resize/filter of each fields before weaving them again. In other words, if I wanted to simply resize my video, could I do it directly on interlaced fields/frames.
ie, just this very simple script:
LoadPlugin("D:\Video\AVISYN~1.5PL\Mpeg2dec\MPEG2D~ 1.DLL")
AVISource("E:\Video\MAGIX\MYAUDI~1\titi.avi",False )
BicubicResize(480,576,0.0,0.6)

Because as I move on on how to deal with my video to make a nice KVCD, I’m wondering whether I need any filtering at all since the source is very high quality (DV-AVI) and I don't necessarily need to fit a long video on 1 CD. Probably again a stupid thought, which doesn’t fit in this thread anyway!

Surfinette

Boulder 11-16-2004 12:03 PM

I'd do interlaced encodings with DVD target only so SKVCD would also be out of the question. Unless the average bitrate would be around 2000kbps or so. Note that only MPEG-2 supports interlaced encoding.

Processing an interlaced video as it is, is a big no-no. You can crop it but you'll have to be extra careful. You can probably even get away with resizing horizontally, but if you use any overscan (as you should), you must resize vertically as well. That's where you need the bobbing. You should also convert the colorspace in your script instead of blindly trusting any external codec, and the conversion is best done when the material is in progressive state, that is, bobbed and not yet re-interlaced.

the viking 11-16-2004 03:21 PM

Boulder wrote:
Quote:

Bobbing only affects one field at a time, which means that it separates the fields and enlarges them to full height, that's why you get a doublerate output when using a bob filter.
Inc. wrote:
Quote:

A bobber does unweave the fields! and brings them to full height by keepin the correct position! That "could" be seen also as deinterlacing but the result after bobbing is a full fieldrate (=twice the framerate)!
So I did this test,

AviSource()
Bob()
Info()


and got this result:

Frames per second: 50

then I added this to the script:

AssumeBFF()
SeparateFields()
SelectEvery(4,1,2)
Weave()


and got this result:

Frames per second:25

I did the same test with kernelbob() and the results were the same.
then I did test with Fielddeinterlace(),Smoothdeinterlace() and TomsMoComp(),and get this result:

Frames per second:25

So I think I (finally :wink: ) get the point. :!:

But a question,when I load the first script in TMPGEnc,it switches(of course) to 50 fps,should I change it to 25 or just encode as it is?
(im talking of bob-deinterlacing here)
if I encode with 50fps will that do anything "wrong" when playing the
clip on DVD-player?

And whats the best deinterlacing method,bob/kernelbob or field/smoothdeinterlace? (When we want to keep the video deinterlaced)

And finally when I want to encode interlaced(keep the video interlaced)
the bobs() is the only useful option as they dont destroy the fields?right?

Thanks
-------------
viking

Boulder 11-16-2004 03:43 PM

Quote:

Originally Posted by the viking
Boulder wrote:
But a question,when I load the first script in TMPGEnc,it switches(of course) to 50 fps,should I change it to 25 or just encode as it is?
(im talking of bob-deinterlacing here)
if I encode with 50fps will that do anything "wrong" when playing the
clip on DVD-player?

50fps is not DVD compliant, so you must weave the fields! Some people do 50fps encodes in XviD for playback on the PC but that's a different story :wink:

Quote:

And whats the best deinterlacing method,bob/kernelbob or field/smoothdeinterlace? (When we want to keep the video deinterlaced)
Depends on the needs of one. If you want playback to be as smooth as possible, try FieldDeinterlace(blend=true) (the default) or TomsMoComp(x,5,0) , where x=0=bff and x=1=tff. If you want to keep as much detail as possible, try KernelDeint(order=1,sharp=true,threshold=7) or TDeint() with kernel interpolation. The latter is quite a bit slower but it's generally considered the best deinterlacer at the moment.

Quote:

And finally when I want to encode interlaced(keep the video interlaced)
the bobs() is the only useful option as they dont destroy the fields?right?
I think that can be safely assumed.

Surfinette 11-16-2004 04:07 PM

Boulder wrote:
Quote:

I'd do interlaced encodings with DVD target only so SKVCD would also be out of the question. Unless the average bitrate would be around 2000kbps or so. Note that only MPEG-2 supports interlaced encoding.
I'm getting confused (again!) here:
1) SKVCD is MPEG-2, isn't it? SKVCD should therefore support intelaced encoding, assuming sufficiently high bitrates?
2) I intend to make short videos (I don't want to bore family and friends :wink: ): 30-40 min on one CD (maybe 50 min max). I assume therefore that I could reach close to 2000kbps bitrate. I guess it is still worthwile to use SKVCD at such bitrates... or should I do plain standard SVCD?

Boulder 11-16-2004 04:15 PM

1) yes and yes

2) the only difference between SVCD and SKVCD is the notch matrix and the GOP length - so you should go for SKVCD anyway since it offers better compression and better quality. Just make sure you use the CQ mode in TMPGEnc, and you should try whether the encode turns out to be good or bad when encoded as interlaced. It depends big time on the source material, if there's lots of motion, it demands a lot more bits too.

the viking 11-16-2004 04:20 PM

@Surfinette,

if your source is DV,and you don't
want any filters, try this script:(its for KSVCD).

Quote:

AVISource("path\clip.avi")
KernelBob(order=0,sharp=true,threshold=7)
AssumeFrameBased()
LanczosResize(480,576)
ConverttoRGB24() # if you use TMPGEnc
AssumeBFF()
SeparateFields()
SelectEvery(4,0,3)
Weave()
Make a test with min.bitrate 300, max.bitrate 2500 and watch
the result in high "action" scenes.
---------------------
viking


All times are GMT -5. The time now is 04:43 AM  —  vBulletin © Jelsoft Enterprises Ltd

Site design, images and content © 2002-2024 The Digital FAQ, www.digitalFAQ.com
Forum Software by vBulletin · Copyright © 2024 Jelsoft Enterprises Ltd.