This article is more than 1 year old

Getting Started with Avisynth

Turn your PC into a video powerhouse

Preparing the Source for Avisynth

OK, we're ready to go. I'll assume your starting point is some kind of MPEG 2 file recorded from Freeview using a TV tuner. If it's another format, Avisynth can almost certainly cope, but you might need help from the relevant forums. For the purpose of demonstration, I've created one from a public domain clip downloaded from The Internet Archive. There are two types of MPEG 2 file: transport stream (.ts), the raw data as streamed over the airwaves, and program stream (.ps) a cleaned-up version that's better for playing on computers and associated hardware. Our method can cope with either type, but if your TV tuner software gives you a choice, opt to record in .ps format.

Either MPEG 2 variant needs some help before Avisynth can do its stuff. This is where the DGMPGDec suite comes in. It includes a utility called DGIndex - once you've installed the suite this should offer itself in the "Open With..." menu when you right click on an MPEG 2 file. But before you open DGIndex, create a plain text file with the following content...

video = MPEG2Source("__vid__", cpu=0)
audio = NicMPG123Source("__aud__")
AudioDub(video, audio).DelayAudio(__del__)

...and save it inside the DGMPGDec directory with the name template.avs. You'll see in a moment what this amazing time-saver does for us. Hint: the values bracketed with underlines in the template are variables.

DGIndex opens the MPEG2 file into a viewer that allows you to choose the in and out points of the video you're going to edit. You can use this to trim off most of the fat at either end, but don't cut too fine at this stage, because you can only cut to the GOP, not frame-accurately (see GOPs and Frames).

Avisynth

Make sure the audio output options are set correctly - but if your recorder saves audio as AC3 you may want to use the AC3-to-WAV option instead.

Saving the project creates three new files: the index into the original MPEG 2 file, the extracted audio track, and - this is the point of template.avs - a barebones Avisynth script.

GOPs and Frames

Compressed video is stored in a series of 'groups of pictures' (GOPs). The first frame of each GOP, the 'key frame', contains enough compressed data for the decoder to recreate the whole frame. But the data for subsequent frames - and there may be as many as 300 of them in a single GOP - contains only delta information, a description of the extent to which these following frames differ from the key frame or - and there's very fancy maths at work here - from their immediate neighbour frames.

Simple editing software can cut compressed video only on the key frame. Any attempt to cut inside the GOP will destroy subsequent frames and also probably ruin the sound sync. More sophisticated video editing software, like VideoReDo, will re-encode that particular GOP, allowing you to cut on any frame. This is called 'frame-accurate' editing.

Avisynth is a 'frameserver', decoding every GOP on demand as the editing software calls it up. Effectively, our editing is being carried out on a stream of fully detailed frames, so we don't have to worry about GOPs. As it's also a scriptable frameserver we're not confined to straight cuts - we've seen from the example above that Avisynth can equally easily do dissolves (or virtually anything else) around the cut point.

Next page:
Converting Cuts to Dissolves

The author of AvsP, the mysterious Qwerpoi <qwerpoi.avsp@gmail.com> - alas he seems to be uncontactable these days - once wrote me a macro to speed up the conversion of cuts to dissolves:

entry = avsp.GetTextEntry('Select and copy the trim commands here:')
splitentry = entry.split('++')
if len(splitentry) == 2:
 newString = 'Dissolve(%s, %s, 25)' % (splitentry[0], splitentry[1])
 avsp.InsertText(newString, pos=None)

More about

TIP US OFF

Send us news


Other stories you might like