Difference between revisions of "Avs"

From SDA Knowledge Base

Jump to: navigation, search
Line 361: Line 361:
  
 
[[Image:AviSynth_deinterlacing_framerate_loadvdub.png]]
 
[[Image:AviSynth_deinterlacing_framerate_loadvdub.png]]
 +
  
  
 
<b>Example of a game that runs at half framerate or 29.97 frames per second</b>
 
<b>Example of a game that runs at half framerate or 29.97 frames per second</b>
  
 +
[[Image:F2_animation.gif]]
  
  

Revision as of 20:20, 6 August 2009

quick link to old guide
quick link to wiki editing


Snow's new AviSynth guide. Yeah, I hope I actually finish this.


Ideas for layout

  • Custom table of contents, not so linear.
  • Use PNG! Lossless is cool.
  • Color headings.

Ideas for guide

  • No more follow-these-steps-blindly instructions this time.
  • Include more pictures. Use thumbnails when necessary.
  • At the start of each section, show a typical script in progress.
  • Include exercises with downloadable packages containing a video and a partial script.


Stuff to do:

The script

  • Loading the source files - capture card
  • Appending
  • Deinterlacing
  • Trimming
  • Resizing
  • Sharpening
  • Cropping / Adding borders
  • Color / Brightness
  • SDA StatID
  • QuickTime compatibility

Extras

  • Sample scripts
  • Script verification

Fixes

  • Fixing Constant audio desync
  • Fixing Progressive audio desync



Table of contents:

  1. Introduction
  2. Setting up your work environment
  3. Installation
  4. Walkthrough
  5. Loading the source files
  6. Deinterlacing



 Introduction

IMPORTANT NOTE: AviSynth scripting is an advanced topic. All beginners are recommended to use Anri-chan instead.

Glossary of terms



 Setting up your work environment

File extensions

You'll very likely need to rename file extensions but they may be hidden by the operating system.

  1. open Windows Explorer
  2. open the Tools menu
  3. select Folder Options
  4. select the View tab
  5. choose to Show hidden files and folders
  6. uncheck Hide extensions for known file types
  7. click OK to apply changes.


AviSynth showhidden.png



Association of avs file extension with text editor

Now that you can see file extensions, let's associate the avs file extension with Notepad or other text editor of your choice.

  1. open Windows Explorer
  2. open the File menu
  3. select New
  4. select Text Document
  5. rename the new text file to New Text Document.avs. It should show up as an unknown type.
  6. open the avs file or right-click and select Open With. Windows will ask which program you want to use.
  7. select Notepad in the list
  8. place a checkmark in the box that says Always use the selected program to open this kind of file
  9. click OK


AviSynth avsnotepad.png



 Installation

Download and install a stable release version of AviSynth

The picture below identifes a stable release.
AviSynth download.png



Download and install necessary AviSynth plugins

  1. Go to Start menu
  2. [All] Programs
  3. AviSynth
  4. Plugin Directory. (This is where AviSynth stores its plugins.)
  5. Copy the files from inside the AviSynth plugins zip file to the Avisynth plugins directory window you just opened.

The plugins directory should look similar to what's shown in the picture. AviSynth will automatically load dll and avsi files.
AviSynth pluginsdir.png



Special instructions for those working with DVD sources
If you followed the instructions on the DVD page properly you should already have DGMPGDec installed. You need to copy a dll file from this directory to the AviSynth plugins directory in order for AviSynth to be able to load DVD video.

  1. navigate to the DGMPGDec directory. Should be C:\Program Files\DGMPGDec
  2. copy DGDecode.dll to the AviSynth plugins directory.



Download and install VirtualDub

This program will be useful for testing your script as you go along.



Verify that everything is installed properly

Download the following package and unzip the contents anywhere you'd like. Run VirtualDub and drag and drop the avs file into the window. You should see a frame that says "So far so good..".




 Walkthrough of a typical AviSynth script

Before starting your own script you should have an idea of how AviSynth operates. The following script is typical for DVD video. AviSynth will execute each line of code sequentially; in this walkthrough you will see what the video looks like after each step.

Ac3Source(MPEG2source("VTS_01_1.d2v", upconv=1),"VTS_01_1 T80 2_0ch 192Kbps DELAY 0ms.ac3")
mvbob()
trim(13801,13900)
Lanczos4Resize(640,480)


A glance at the work folder

As you can see, the VOB has already been processed by DGIndex generating the files:

  • VTS_01_1.d2v
  • VTS_01_1 T80 2_0ch 192Kbps DELAY 0ms.ac3

AviSynth walkthrough workfolder.png


Load audio/video

I open my_AviSynth_script.avs in Notepad and add the line below to load the Ac3 audio and MPEG2 video. VirtualDub shows that both have loaded succesfully.

Ac3Source(MPEG2source("VTS_01_1.d2v", upconv=1),"VTS_01_1 T80 2_0ch 192Kbps DELAY 0ms.ac3")

AviSynth walkthrough loadsource.png


Deinterlace

I've identified that the video is D1 F1 3D (will go into this later) so the appropriate deinterlacing method is mvbob. Notice how the number of frames has doubled from approximately 10000 frames to 20000.

mvbob()

AviSynth walkthrough deinterlace.png


Trimming the fat

I've decided, for the sake of this walkthrough, to keep only 20 frames.

trim(17451,17470)

AviSynth walkthrough trim.png


Resize

My NTSC DVD has a resolution of 720x480. I need to resize to 640x480 resolution so that the aspect ratio is correct and everything doesn't look so wide.

Lanczos4Resize(640,480)

AviSynth walkthrough resize.png


There are more commands you will use in your script, but the above are the essentials.



 Loading the source files

Let's start with a new AviSynth script. Remember when you created an avs text file back in Setting up your work environment? That's all an AviSynth script really is, a text file with an avs file extension. We'll create the High Quality script first and move on to the other SDA qualities later. Open mygame_HQ.avs in Notepad.

  1. open Windows Explorer
  2. open the File menu
  3. select New
  4. select Text Document
  5. rename the new text file to mygame_HQ.avs.


This chapter will diverge into three sections. Depending on how you recorded your video, follow the appropriate link.


PC game recorded with Fraps / Camtasia / other screen capture software

Screen capture software typically creates an AVI file containing both video and audio. All we need is the AviSource() command with your AVI file as the argument.

avisource("clip1.avi")


Simple, isn't it? What if you have more than one file and want to append them together, as is usually the case when recording for longer periods of time? Let's bring in the AlignedSplice() command with AviSource as the arguments.

a = avisource("clip1.avi")
b = avisource("clip2.avi")
namedoesntmatter = avisource("clip3.avi")

AlignedSplice(a,b,namedoesntmatter)


An example of three videos that were split by Fraps being joined together in AviSynth. AviSynth loadsource pcgame.png



Console game recorded with DVD recorder / capture card using DVD settings

There are three main types of audio when working from a DVD source: AC3, MPA and sometimes even PCM (wav). When you indexed the VOB files with DGIndex as per the DVD guide it should have created the d2v file and an audio file. Notice how the d2v file is only 19 KB in size since it only contains data about the VOB MPEG2 video stream; you still need that VOB file!


The picture below shows that an AC3 audio file was extracted with an audio desync of 78 milliseconds. AviSynth loadsource DVDdir.png


Here are the different ways to load AC3 / MPA / PCM (WAV). The first example would work with the files in the picture above.


AC3 with a -78 ms desync.

Ac3Source(MPEG2source("VTS_01_1.d2v", upconv=1),"VTS_01_1 T80 2_0ch 192Kbps DELAY -78ms.ac3").DelayAudio(-0.078)

MPA with a +46 ms desync.

AudioDub(MPEG2source("VTS_01_1.d2v", upconv=1),MPASource("vob T01 2_0ch 192Kbps DELAY 46ms.mpa")).DelayAudio(0.046)

PCM with no desync.

AudioDub(MPEG2source("VTS_01_1.d2v", upconv=1),WAVSource("vob T01 2_0ch 192Kbps DELAY 0ms.wav"))


DVD MPEG2 in all its interlaced glory... AviSynth loadsource DVD.png


Console game recorded with capture card to AVI file

Write me!



 Deinterlacing

Outline

  • Intro, with image of interlaced / deinterlaced frame.
  • What is an interlaced frame?
  • Make new image with concept of the ABCD split but say "Field 1", "Field 2", etc.
  • Above idea but actual game footage screens (thumbnail link to massive 3600 width pic)
  • Go through each method of deinterlacing for all the qualities. Show images!!!



If you recorded a PC game with screen capture software such as Fraps or Camtasia, there is a 99.9% chance that your video does not need to be deinterlaced and you can skip this entire section. For just about everyone else, your video probably needs to be deinterlaced.

The animated picture below shows the difference between interlaced and progressive/deinterlaced.

AviSynth deinterlacing ipanim.gif


What is an interlaced frame?

An interlaced frame has two fields. Think of it as a single frame with two smaller frames inside. Those two fields (the smaller frames) represent two different moments in time. Take the picture as an example, with four different fields numbered 1 to 4:

AviSynth deinterlacing fields1234 i.png


The fields have been separated.

AviSynth deinterlacing fields1234 i2.png


Demonstrating how the top field (fields 1 and 3) is on even numbered lines, while the bottom field (fields 2,4) is on odd numbered lines.

AviSynth deinterlacing fields1234 izoom.png


The sequence of frames is now deinterlaced and is progressive.

AviSynth deinterlacing fields1234 p.png


Here is an example from a game.

(a more complete version is available: jpg, 1.18 MB / png, 5.75 MB - 3600×2047)

AviSynth deinterlacing fields game thumb.jpg


You'll notice that the height has been cut in half and Dante looks too short (or too wide). Not to worry, we'll be fixing that later on.


Determining the framerate of the game

Right now your AviSynth script is one measly line of code, e.g.:

Ac3Source(MPEG2source("segment1.d2v",upConv=1),"segment1 192Kbps DELAY -48ms.ac3").DelayAudio(-0.048)

I'm going to temporarily add SeparateFields at the end of the script solely for the purpose of determining the framerate of the game. This will do exactly what is shown in the previous section "What is an interlaced frame?".

Ac3Source(MPEG2source("segment1.d2v",upConv=1),"segment1 192Kbps DELAY -48ms.ac3").DelayAudio(-0.048)
SeparateFields

The script is saved and loaded into VirtualDub(Mod). The amount of frames and the framerate have both doubled.

AviSynth deinterlacing framerate loadvdub.png


Example of a game that runs at half framerate or 29.97 frames per second

F2 animation.gif


Example of a game that runs at full framerate or 59.94 frames per second



Example of a game that runs at one third framerate or 19.98 frames per second




By this point in the guide, you should have a script similar to this:


To make it easier for you, move to a part of your video that has a lot of motion. Also make sure you're looking at actual gameplay, not a cutscene, since gameplay is much more important for speed runs. Use the buttons at the bottom of VirtualDub(Mod) to step through your video frame by frame. What you're looking for is difference in motion. If you see unique motion every single frame, then your game is full framerate. If you see unique motion every two frames, the game is half framerate. If it's every three frames, you've got one-third framerate.

For example, if U=unique and D=duplicate, you can write full framerate as a sequence of frames U,U,U,U,etc, and you can write half framerate as a sequence of frames U,D,U,D,etc.

There are some games that have a strange sequence of frames. We recently saw one in Tech Support for a PAL game that had a sequence of frames U,D,U,U,D,etc. If you get something strange like that, make a topic in Tech Support about it so we can look at it.

Before leaving this section, make sure you've determined whether your game is F1 (full framerate), F2 (half framerate) or F3 (third framerate).

Remove SeparateFields() from the script.

Personal tools