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 9th October 2002, 15:36   #1  |  Link
Xesdeeni
Registered User
 
Join Date: Aug 2002
Posts: 467
Standards Conversion Script (PAL<->NTSC)

Code:
######################################################################
#
# Poor man's video standards conversion (NTSC to PAL and PAL to NTSC)
#
# This script converts one INTERLACED video format to another
# INTERLACED video format.
#
# NOTE: This script is NOT meant to convert telecined films (that is,
# films that have been transferred to video).  There are much better
# ways to convert that type of content (see the guides at
# www.doom9.net and www.vcdhelp.com).  This script is best for
# INTERLACED content like HOME MOVIES shot with camcorders or live
# events.  It is also good for mixed content (film + video).
#
#---------------------------------------------------------------------
#
# >>> Tools <<<
#
# This script is for use with AVISynth version 2.0.6 or above,
# available from http://www.avisynth.org.
#
# This script uses my AVISynth port of Gunnar Thalin's smooth
# deinterlacer, which is available at
# http://home.bip.net/gunnart/video/AV...Deinterlacer/.
# Place the plugin in an AVISynth plugin directory, so it can be
# accessed below.
#
#---------------------------------------------------------------------
#
# For comments/suggestions email me (Xesdeeni2001) at Yahoo dot com.
#
######################################################################
#
# >>> How It Works <<<
#
# This script works by first converting the input video from
# interlaced fields to progressive frames using an adaptive
# deinterlacer.  Then the progressive frame rate is converted.
# Finally the progressive frames re-interlaced for output.  Scaling
# is also performed where appropriate.
#
######################################################################
#
# >>> To Use <<<
#
# To use this script, first modify the lines below as specified.
# Then save the script with any name ending in .AVS.
#
#---------------------------------------------------------------------
#
# Set PluginPath equal to the path for your AVISynth plugins. Be sure
# to end the path with a backslash.  Note that if you put the plugins
# in the system directory, you can leave this path completely empty.
# ex.:
#   PluginPath = "C:\AVISynth\PlugIns\"
#

PluginPath = ""

#---------------------------------------------------------------------
#
# Set Input equal to the load directive for the input file.  Also add
# any plugins necessary to load the video file.  Note that if the clip
# contains audio, it is fed straight through without being modified,
# because the output video will have the same length as the input
# video.
# ex.:
#   LoadPlugin(PluginPath + "MPEG2DEC.dll")
#   Input = MPEG2Source("Input.mpg")
#

Input = AVISource("E:\temp\LiveTest.avi")

#---------------------------------------------------------------------
#
# Set InputTopFieldFirst to either true or false, depending on the
# format of your input file.  DV files are normally bottom field
# first, so set this value to false.  DVDs and most other sources are
# normally top field first, so set this value to true.
#

InputTopFieldFirst = false

#---------------------------------------------------------------------
#
# Set OutputFrameRate to the desired frame rate of your output video.
# For PAL, this is normally 25.  For NTSC, this is normally 29.97.
# The input frame rate is derived directly from the input video.
#

OutputFrameRate = 25

#---------------------------------------------------------------------
#
# Set the OutputWidth and OutputHeight to the desired width and
# height of your output video.  In most cases, the width of the
# output should match the width of the input.  For PAL, the height
# is normally 576.  For NTSC, the height is normally 480.  The input
# width and height are derived from the input video.
#

OutputWidth = Input.width
OutputHeight = 576

#---------------------------------------------------------------------
#
# Set OutputTopFieldFirst to either true or false, depending on the
# desired format of your output file.  See InputTopFieldFirst above.
#

OutputTopFieldFirst = true

#---------------------------------------------------------------------
#
# Set ConversionType to your desired type of frame rate conversion.
# The choices are:
#   0 - Replication/Decimation: Frames are repeated to increase the
#       frame rate; frames are dropped to decrease the frame rate.
#       This type of conversion is the fastest, but may show visible
#       stuttering on motion when decreasing the frame rate (i.e.
#       NTSC to PAL).
#   1 - Temporally Interpolate: Output frames are created by
#       temporally interpolating between adjacent input frames.  This
#       type of conversion can show a "jutter" effect on motion, but
#       is best when decreasing the framerate to ensure every input
#       frame is at least partially shown in the output.
#   2 - Asynchronous:  The conversion is done by showing the
#       portions of the input frames that correspond to the time
#       during which the output frame is visible.  When decreasing
#       the frame rate, this can cause some areas of some frames to
#       never be seen, and can cause "broken" vertical edges on
#       horizontal pans.
#

ConversionType = (OutputFrameRate <= Input.framerate) ? 1 : 0

#
######################################################################

LoadPlugin(PluginPath + "SmoothDeinterlacer.dll")

vpro = Input.SmoothDeinterlace(tff=InputTopFieldFirst, \
                               doublerate=true)
vinfps = Input.framerate < OutputFrameRate              ? \
         vpro.BilinearResize(OutputWidth, OutputHeight) : \
         vpro
vfps = ConversionType == 2 ?                               \
       vinfps.ConvertFPS(OutputFrameRate * 2, zone = 80) : \
       ConversionType == 1 ?                               \
       vinfps.ConvertFPS(OutputFrameRate * 2) :            \
       vinfps.ChangeFPS(OutputFrameRate * 2)
voutfps = OutputFrameRate <= Input.framerate             ? \
          vfps.BilinearResize(OutputWidth, OutputHeight) : \
          vfps
vfields = voutfps.SeparateFields()
vlace = OutputTopFieldFirst          ? \
        vfields.SelectEvery(4, 1, 2) : \
        vfields.SelectEvery(4, 0, 3)
# The ConvertToRGB() below is to work around a problem with the YUV to
# RGB conversion caused by a bug in one of the Microsoft DLLs.  The
# bug makes the colors look bad.  Your destination may bypass this
# conversion, so you may be able to remove this conversion in some
# cases.
vout = vlace.Weave().ConvertToRGB()
return(vout)
Xesdeeni

[Edit: Modified to fix the audio.]

Last edited by Xesdeeni; 15th October 2002 at 13:31.
Xesdeeni is offline   Reply With Quote
Old 9th October 2002, 17:06   #2  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
Does Xesdeeni == Gunnar Thalin?
Guest is offline   Reply With Quote
Old 10th October 2002, 08:10   #3  |  Link
Si
Simply me
 
Si's Avatar
 
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
Quote:
Does Xesdeeni == Gunnar Thalin?
If it is then (looking at the Smooth Deinterlacer page) I think he/they have a serious split-personality problem

Simon
Si is offline   Reply With Quote
Old 10th October 2002, 08:28   #4  |  Link
Gribley
Registered User
 
Join Date: Aug 2002
Posts: 2
Xesdeeni,

I`ve been using the simple example from the Avisynth help files (under convertFPS syntax).... this is working fine for me NTSC->PAL and seems much simpler.
This sounds bad, (but it is not intended that way), but does you script offer anything that would make it worth me re-encoding for?

Cheers
Grib
Gribley is offline   Reply With Quote
Old 10th October 2002, 13:20   #5  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
Quote:
Originally posted by siwalters


If it is then (looking at the Smooth Deinterlacer page) I think he/they have a serious split-personality problem

Simon
Well, xesdeeni apparently does, based on the comments in the script.

When I posted that I was at work where my proxy denied me access to the page, so I couldn't look at that time. Really, I'm not an idiot.

Last edited by Guest; 10th October 2002 at 13:25.
Guest is offline   Reply With Quote
Old 10th October 2002, 14:41   #6  |  Link
Xesdeeni
Registered User
 
Join Date: Aug 2002
Posts: 467
Gribley--
If you are satisfied with the results using Bob(), then there is no reason to take the extra time to use the above method. However, you will note on still scenes or static graphics that the image will...well, bob up and down. The above technique will look better overall, and it more nearly matches the professional conversion devices.

Xesdeeni
Xesdeeni is offline   Reply With Quote
Old 10th October 2002, 17:39   #7  |  Link
Xesdeeni
Registered User
 
Join Date: Aug 2002
Posts: 467
Here is an example of what I mean. This is from a the first season of a BBC sitcom called Porridge. The show takes place in prison, and this is a piece of a scene showing the mugshot of one of the main characters. The top half was converted using the Bob() method from the AVISynth documentation. The bottom half is exactly the same part of the same frames using the method outlined above.

Xesdeeni

[edit] All right. What's the trick to posting an attachment!? It showed up when I posted, and as I'm editing, it shows up below as well ("Keep current attachment"). Oh, it's a zip file that is less than 200K.

Last edited by Xesdeeni; 10th October 2002 at 17:43.
Xesdeeni is offline   Reply With Quote
Old 10th October 2002, 18:33   #8  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
Your attachment has to be approved by a moderator, before it'll show up - relax - neuron will probably come back soon.
__________________
Regards, sh0dan // VoxPod
sh0dan is offline   Reply With Quote
Old 10th October 2002, 19:01   #9  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
Sweet! It looks like I can stop my work on my Avisynth Smart Bob.

Xesdeeni, you should make a thread announcing your port of the Deinterlace Smooth. Or have you done that already and I missed it?

Great work, you and Gunnar.

Last edited by Guest; 10th October 2002 at 19:07.
Guest is offline   Reply With Quote
Old 10th October 2002, 19:12   #10  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
Just tested.

You rock, Xesdeeni - what an excellent filter - really, really cool!

edit: Whoops - tested a bit more:
Code:
crop(16,16,-16,-16)
smoothdeinterlace(doublerate=true)
Does this result look familiar? (If not, just ask Donald )
__________________
Regards, sh0dan // VoxPod

Last edited by sh0dan; 10th October 2002 at 19:22.
sh0dan is offline   Reply With Quote
Old 10th October 2002, 20:03   #11  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
Another problem - when using "doublerate=true", my video is always jerky, regardless of using 'tff=true' or 'tff=false'. The source is 25fps PAL DV-source, so it should be ok using 'tff=false'.
I've uploaded a testclip - a pan, where the effect is very visible. Get it here.. I cropped the source, and it's XVID compressed (with latest interlace bug-fix), but the effect is still very visible. My script:
Code:
avisource("bob-prob.avi")
smoothdeinterlace(doublerate=true,tff=false)
Another thing is, that you can request default parity from Avisynth, by using clip.GetParity() - it will in most cases return the correct field order. Otherwise assumetff() or assumebff() can be used in the script.
__________________
Regards, sh0dan // VoxPod
sh0dan is offline   Reply With Quote
Old 10th October 2002, 20:36   #12  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
@sh0dan

The latest Xvid binary from Koepi's page won't play your file. It goes macroblock crazy and disintegrates into garbage. Please, where do I get the Xvid version that will play it? Thank you.
Guest is offline   Reply With Quote
Old 10th October 2002, 21:36   #13  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
I can see Interlacing still has problems in XVID (the I cannot get the latest filters to make a properly interlaced clip, or at least have them decompress them correctly again).

I put up a quant 2 interlaced clip, encoded as non-interlaced - just redownload. It still displays the artifacts very good. I almost think I'm doing something wrong?
__________________
Regards, sh0dan // VoxPod
sh0dan is offline   Reply With Quote
Old 11th October 2002, 08:54   #14  |  Link
Gribley
Registered User
 
Join Date: Aug 2002
Posts: 2
Xesdeeni,

Thanks for taking the time to explain it so well.... next standards conversion I try I`ll use your script and see the difference for myself

Thanks
Grib
Gribley is offline   Reply With Quote
Old 11th October 2002, 14:28   #15  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
Quote:
Originally posted by sh0dan
Another problem - when using "doublerate=true", my video is always jerky, regardless of using 'tff=true' or 'tff=false'. The source is 25fps PAL DV-source, so it should be ok using 'tff=false'.
I don't know why the tff option isn't working as described in the help file, but you can make it work by putting ComplementParity() before the call to the filter.
Guest is offline   Reply With Quote
Old 11th October 2002, 14:49   #16  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
ok - thanks - tried swapfields(), but that didn't help either.
__________________
Regards, sh0dan // VoxPod
sh0dan is offline   Reply With Quote
Old 14th October 2002, 14:59   #17  |  Link
Xesdeeni
Registered User
 
Join Date: Aug 2002
Posts: 467
Hmmm. That was an interesting one. The clip in question misreports its polarity (it says it's bottom field first, but it's actually top field first--notice that Bob() also has a problem with it that is fixed with AssumeTFF()). I wouldn't have thought that this would matter, since I had an explicit "tff" parameter. But unbeknownst to me, the internal DoubleWeave() filter uses the reported polarity. So regardless of what I did with the data, I was getting bad DoubleWeave()d frames.

It took me a while to figure that one out. And it took even longer to figure out how to smoothly fix it. But anyway, I've combined the fix with the suggestion from sh0dan, and now the filter can use the reported polarity instead of requiring it explicitly.

Of course, for the clip above, sh0dan would still have to explicitly give the tff=true argument.

[Since I'm relying on the kindness of Gunnar Thalin to host the filter, and I've sent the update to him literally seconds ago, it may be a bit before version 1.2 shows up. BTW, thank Gunnar!]

Xesdeeni
Xesdeeni is offline   Reply With Quote
Old 15th October 2002, 13:25   #18  |  Link
Xesdeeni
Registered User
 
Join Date: Aug 2002
Posts: 467
I've updated the script above to fix a problem with the audio.

Xesdeeni
Xesdeeni is offline   Reply With Quote
Old 15th October 2002, 14:17   #19  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
Did you fix the crop (pitch) problem?
__________________
Regards, sh0dan // VoxPod
sh0dan is offline   Reply With Quote
Old 15th October 2002, 14:55   #20  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
@Sh0dan,

About the audio ...

I saw that you added a new function called AssumeSampleRate. Isn't it possible to convert the audio in the following way:

# source: the wav-file (48 kHz):
# 48000*25/23.976 = 50050 (similar as SSRC.exe):
ResampleAudio(50500)

# "change the header back" (similar as Wavefix.exe ?):
AssumeSampleRate(48000)

Is that the "best" way for converting the audio (it should work, although I haven't tried it yet)?
Wilbert 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 11:46.


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