Wednesday, April 28, 2010

Experiments with Avisynth and VirtualDub pt.1

I was given the task of creating a number of videos to use as stimuli for a psychological experiment, so decided to use the programs AviSynth for initially scripting the basic parameters, then using the resulting script file in VirtualDub to turn them into real-live, playable videos.

This blog entry details the difficulties encountered and what resulted.

First off, a warning: these programs are not for the faint-of-heart.

All 32-bit MS Windows (95/98/NT/2000/XP

Avisynth is a script-driven video frame-server with its own particular syntax, so you're effectively writing a program; if you don't like writing code then leave well alone!

'Frame serving' is a way of getting around the built-in restrictions occurring in many video editing programs and means you can use Avisynth (along with its comprehensive built-in filters) to wrap media (audio, video, pictures) into a file format that can be recognised by other programs.

There's no graphic front-end, so it's just you and a text editor:
  • write the code
  • test it
  • find out why it didn't work
  • test it again.
It has loads of parameters, but also has a good online reference with code examples and instructions.

While researching how to create my videos I discovered that a number of people have created front-ends for generating scripts with Avisynth, but after having a go with one of them (AVSGenie) I found you really had to know Avisynth beforehand so it seemed simpler to just wade in and have a go.
Luckily there is an active user-base so for most queries there's normally some useful help already on-line.


Windows 32-bit and 64-bit platforms (98/ME/NT4/2000/XP/Vista/7)

VirtualDub is an open-source video editor, but not in the Final Cut Pro, Vegas, Premier type-of-way.

It will not open MPEG files so no editing of your ripped DVD's (but there are ways around this, see VirtualDubMod and VirtualDub-MPEG, both now quite old), nor will it open many other file formats (that's why we have to use AviSynth), but it's usable, robust, has a number of very decent filters and applications built-in, an enthusiastic user-base, plus it's free.

As a long-term user of Sony Vegas, I have to say it lacks the immediacy of a commercial video editor, but makes up for that with the number of features it includes. As it can also frame-serve, like Avisynth, I have occasionally used it to frameserve video to Vegas. It makes the editing a big laggy, but works well!


The Stimuli

The experiment was to find out peoples' perceptions of music and movement, comprising of five ascending notes (in fourths) and five images of a person rising from crouched to fully out-stretched. Each note - 1 to 5, with 1 being lowest - would play while showing one of the images.

In the first set of videos the notes directly corresponded to a body position, so assuming 1 is the lowest note, then it would correspond to the crouched body position, going up to note 5 playing with the fully outstretched body position.
Got it?

But, the order the notes play is not just straight up and down, oh no, but runs through a regular sequence, such as:

Notes Images
13452 13452
14532 14532
15324 15324
14352 14352

then ..
25431 25431
24531 24531
23415 23415
24351 24351

a
nd so on.

Then there are the variations.

Instead of each note corresponding to a body position, the note would correspond to its inverse within the list, so:
note 1: body position 5; note 2: body position 4; 3:3; 4:2; 5:1; etc.

With me so far?

And the third variation would be a random series of notes and body positions.

There were twenty videos for each variation, so sixty videos in all, and the timing had to be accurate for each one.

Now, I could have just put them together using Sony Vegas, editing together each picture and note for the sixty videos, but it would have taken a lot of time, would have need a lot of checking, and would not be very adaptable.

Using Avisynth was ... well, more elegant. And, in the end, was very usable. Plus it got me out of problems that I could later sort out by just using a 'search and replace text' tool and that would have been impossible to easily correct with a normal video editing program without having to re-edit all the videos.

As in the way of experimenting, various things conspired to make me trash the first batch of videos, so in the end I was glad that I'd chosen this way of producing them right from the very start.

Onto Part 2: Writing the code for Avisynth

No comments:

Post a Comment