Difference between revisions of "AviSynth"

From SDA Knowledge Base

Jump to: navigation, search
(Color / Brightness)
m (Part 10: Color / Brightness)
Line 224: Line 224:
 
===Part 10: Color / Brightness===
 
===Part 10: Color / Brightness===
  
Be very careful when playing around with color and brightness. If your video is too bright and looks greyish it will be rejected. Feel free to ask others in the [http://speeddemosarchive.com/yabb/YaBB.pl?board=other tech support forum] for their opinions about your video.
+
Be very careful when playing around with color and brightness. If your video is too bright and looks greyish it will be rejected. Feel free to ask others in the [http://speeddemosarchive.com/yabb/YaBB.pl?board=other Tech Support forum] for their opinions about your video.
  
 
http://www.avisynth.org/Tweak
 
http://www.avisynth.org/Tweak
  
 
http://www.avisynth.org/Levels
 
http://www.avisynth.org/Levels
 
  
 
===Part 11: SDA StatID===
 
===Part 11: SDA StatID===

Revision as of 10:55, 9 September 2006

Introduction

Avisynth rocks my socks.


Installation / plugins

Go to http://www.avisynth.org/ or http://sourceforge.net/project/showfiles.php?group_id=57023 and download the latest non-alpha version of Avisynth. It is currently at 2.5.6a. Install the program.

With Avisynth installed, go to Start menu -> [All] Programs -> Avisynth -> Plugin Directory. This will open the directory where Avisynth stores its plugins. Copy the files from inside the avisynth plugins zip file to the avisynth plugins directory window you just opened.


The avisynth script

The work folder for this guide is "C:\video processing\" where all source files are located.

Create a .txt document with a name of your choice. Rename the extension from .txt to .avs. If you can't see the extension and are running in Windows, open Windows Explorer, go to Tools -> Folder Options -> View and uncheck "Hide extensions for known filetypes".

Open the avs file in Notepad or any text editor.


Part 1: Loading the plugins

Depending on what kind of source material you have, there will be some plugins you don't use. It doesn't hurt to load them though. Mvbob's extension is .avsi so it will automatically be loaded. Copy the following code into the avs file. Change the file paths if needed.

Loadplugin("C:\Program Files\DGMPGDec\DGDecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\LeakKernelDeint.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\ac3source.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\mpasource.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\Warpsharp.dll")

Part 2: Loading the source files

There are different ways to load the source files and it all depends on what it is you're working with. Here is a list of available commands.

  • avisource(video.avi)
  • directshowsource(video)
  • MPEG2source(video.d2v)
  • Ac3source(video, sound.ac3)
  • Wavsource(sound.wav)
  • Mpasource(sound.mpa)
  • AudioDub(video, sound)


Tip: You don't need to include the whole file path, as long as you keep the avs file in the same folder as the source files.


If you used a capture card or screen capture software then it is quite simple to load the files. If avisource does not work, try directshowsource. Those using Camtasia will probably need to use the latter.

### Video and audio are already combined
avisource("C:\video processing\video.avi")

### Video and audio are split
#AudioDub(avisource("C:\video processing\video.avi"), wavsource("C:\video processing\audio.wav"))

Notice the # before AudioDub. This is telling avisynth to skip over the line. If you need to use this line, remove the # and add one before the first avisource command.

Tip: If your video is separated in multiple parts, which is usually the case when recording with Fraps, then be sure to look at part 4 since it is linked to part 2.


If you used a DVD recorder then your video and audio is most likely split. Make sure you've gone over the DVD page before continuing.

AC3source(MPEG2source("C:video processing\vob.d2v"),"C:\video processing\vob T01 2_0ch 192Kbps DELAY -66ms.ac3")
#AudioDub(MPEG2source("C:video processing\vob.d2v"),MPASource("C:\video processing\vob T01 2_0ch 192Kbps DELAY -66ms.mpa")) 

I hope you haven't removed the delay information from the sound files. Not that it's the end of the world if you did remove it, you'll just have to listen by ear until you get a close value with DelayAudio().


Part 3: Fixing audio delay

This will only work if the audio desync is constant and not progressive. Constant desync is when the desync at the beginning of the video is the same as the desync at the end of the video. You guessed right, it's easy to fix. Progressive desync, on the other hand, can be a huge pain and may require external tools to fix.

The DelayAudio command is straightforward, but there is an extra concept worth learning. Look at the following two scripts:

Ac3Source(MPEG2source("vob.d2v"),"vob DELAY -66ms.ac3")
DelayAudio(-0.066)
Ac3Source(MPEG2source("vob.d2v"),"vob DELAY -66ms.ac3").DelayAudio(-0.066)

Is there a difference between them? Yes and no. They both get the same result, however the script with one line makes it easier for projects where you append files together. I suggest using the format of the second script.


Part 4: Appending

One of the best features of avisynth is its ability to do an aligned splice when appending video. There is usually a mismatch between the length of the video and the length of the audio, typically ranging from -50 ms to +50 ms. This means that appending files in VirtualDub(Mod) will in almost all cases cause a desync because the audio of clip2 will be appended right after clip1. VirtualDub(Mod) is unable to do an aligned splice. Here is an illustration:

Append.png

You will probably never use UnalignedSplice. Here are different methods for using AlignedSplice:

### Method 1
AlignedSplice(avisource("clip1.avi"), avisource("clip2.avi"), avisource("clip3.avi"))

### Method 2
a = avisource("clip1.avi")
b = avisource("clip2.avi")
c = avisource("clip3.avi")
AlignedSplice(a,b,c)

### Method 3
avisource("clip1.avi")++avisource("clip2.avi")++avisource("clip3.avi"))

Ac3Source(MPEG2source("vob1.d2v"),"vob1 DELAY -66ms.ac3").DelayAudio(-0.066)++Ac3Source(MPEG2source("vob2.d2v"),"vob2 DELAY -30ms.ac3").DelayAudio(-0.030)

### Method 4
import("script1.avs")++import("script2.avs")++import("script3.avs")

Method 2 is good for when you're joining a lot of clips since it's easier to edit. Notice the double plus signs in method 3, this is the same as AlignedSplice. One plus sign would indicate UnalignedSplice. Method 4 is to join independent avisynth scripts.


Part 5: Deinterlacing / Full framerate video

You can skip this section if you used Fraps/Camtasia to record a computer game, or if your console game outputs in progressive mode and you captured in progressive mode as well. Otherwise, if your footage looks anything like this with the horizontal lines, then you definitely need to deinterlace.

Dmc3interlaced.jpg


Avisynth will help you restore the full range of motion to your video. Capturing at 320 x 240 without Avisynth, as most people do, would cause you to lose half of your motion information.

Tip: You should create separate avisynth scripts for each quality version that has differences between them. There's no sense in creating one avisynth script, encoding it, editing the script, encoding again, etc. With separate avisynth scripts you'll get less script errors, less headaches, and you'll be able to queue many encodes.

Half framerate - 25 fps (PAL), 29.97 fps (NTSC)

  • DivX - Low Quality
  • DivX - Medium Quality
  • H.264 - Low Quality

This is the easiest kind of deinterlacing. You barely even have to think about it. Looking at the picture above, notice all the individual horizontal lines. These show the fields. Every even numbered line is one field, while every odd numbered line is the other field. With half framerate we simply remove one of the fields. This reduces the height of the video by half, we'll take care of the width later on when resizing.

separatefields()
selecteven()

Full framerate - 50 fps (PAL), 59.94 fps (NTSC)

  • Everything else. Yes, SDA now allows full framerate for H.264 Medium Quality.

If the game you recorded outputs in low resolution then there's no reason to deinterlace with full resolution. The NES, SNES and Sega Genesis are examples of systems that output video in low resolution.

### Use complementparity if the motion of the video seems to go back and forth.
#ComplementParity()
separatefields()

For full resolution deinterlacing leakkerneldeint or mvbob come into play. Nate uses the following line to process runs that have been sent in to SDA. If you notice too many "lines" or interlacing artifacts as we like to call it, then lower the threshold value. The negative effect to lowering this is that you end up with more jaggedy edges, and loss of details. Use what you think is best.

### You may have to set order to 0. Try both to see which one works.
LeakKernelBob(order=1,threshold=10,sharp=true,twoway=true,map=false)

Those who want more quality at the cost of encoding speed can use mvbob instead of leakkernelbob. Beware, this thing is very, very slow. But it comes with a free Frogurt!

### Use complementparity if the motion of the video seems to go back and forth.
#ComplementParity()
mvbob()

Part 6: Trimming

Trim is used to cut out frames. The numbers inside the brackets represent the range of frames you want to keep. You should have the trim command somewhere after deinterlacing to avoid any confusion.

Trim(100,50000)

#Trim(100,35000)++Trim(36000,50000)

http://www.avisynth.org/Trim


Part 7: Resizing

You'll probably end up doing some form of resizing. Otherwise you captured at 320x240... booo..

lanczos4resize(720,576)
lanczos4resize(640,480)
lanczos4resize(320,240)

http://www.avisynth.org/Resize

http://www.avisynth.org/ReduceBy2


Part 8: Sharpening

Sharpening should only really be used by those who recorded their computer game with screen capture software.

Since XSharpen works in the YV12 colorspace, you will have to convert it first.

ConvertToYV12()
### Defaults are 30,40
XSharpen(30,40)


Part 9: Cropping / Adding borders

The following code corresponds to the illustration.

Crop(10,8,-14,-16)

Crop.jpg


You will probably not use the crop and add border commands. A good example of its combined use is if you want to get rid of some noise at the bottom of the video. You would crop it away, then add the border back. Only do this if the noise is along the black border of the video, we don't want to crop away gameplay footage...

Crop(0,0,0,-10)
Addborders(0,0,0,10)


Part 10: Color / Brightness

Be very careful when playing around with color and brightness. If your video is too bright and looks greyish it will be rejected. Feel free to ask others in the Tech Support forum for their opinions about your video.

http://www.avisynth.org/Tweak

http://www.avisynth.org/Levels

Part 11: SDA StatID

Sample scripts

DVD source, one segment, for HQ and IQ, deinterlacer: leakkerneldeint, gamma correction, no statid

Loadplugin("C:\Program Files\DGMPGDec\DGDecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\leakkerneldeint.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\ac3source.dll")

Ac3Source(MPEG2source("segment3.d2v"),"segment3 192Kbps DELAY -66ms.ac3").DelayAudio(-0.066)
LeakKernelBob(order=1,threshold=10,sharp=true,twoway=true,map=false)
Trim(588,37648)
Lanczos4Resize(640,480)
Levels(0, 1.2, 255, 16, 235)

ConvertToYV12()

DVD source, two segments, for LQ and MQ DivX/Xvid, no statid

Loadplugin("C:\Program Files\DGMPGDec\DGDecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\leakkerneldeint.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\ac3source.dll")

seg1 = Ac3Source(MPEG2source("segment1.d2v"),"segment1 192Kbps DELAY -66ms.ac3").DelayAudio(-0.066)
seg1.separatefields().selecteven()
seg1.Trim(76,109763)
seg1.lanczos4resize(320,240)

seg2 = Ac3Source(MPEG2source("segment2.d2v"),"segment2 192Kbps DELAY -32ms.ac3").DelayAudio(-0.032)
seg2.separatefields().selecteven()
seg2.Trim(143,76875)
seg2.lanczos4resize(320,240)

seg1++seg2

ConvertToYV12()

Fraps source, split parts, one segment, for LQ and MQ, no statid

LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\Warpsharp.dll")

avisource("seg7_part1.avi")++avisource("seg7_part2.avi")++avisource("seg7_part3.avi")
Trim(439,60938)
lanczos4resize(320,240)

ConvertToYV12()
XSharpen(35,40)  # A little sharper than default 30,40

Fraps source, split parts, segmented run, all appended into one video, for HQ and IQ, no statid

a = avisource("seg1_1.avi")++avisource("seg1_2.avi")++avisource("seg1_2.avi")
b = avisource("seg2_1.avi")++avisource("seg2_2.avi")
c = avisource("seg3_1.avi")++avisource("seg3_2.avi")

a.trim(100,20877)
b.trim(16,10988)
c.trim(875,13000)

AlignedSplice(a,b,c)  # Same as a++b++c

ConvertToYV12()
Personal tools