Wednesday, April 28, 2010

Experiments with Avisynth and VirtualDub pt.2


Writing the code for Avisynth


After you've installed Avisynth, then creating a text file with an .AVS extension will enable you to play a video in Windows Media Player (note: this uses a setting within Avisynth, and is particular to
Windows Media Player. No other media player like Quicktime or VLC will be able to play the file).

The easiest way to find out if it's all working is to put this line into a text file, save it, then right click on it and 'play' it in Windows Media Player. It should play a 10-second video with the text "Hello World"


BlankClip()
Subtitle("Hello, world!")


If it doesn't work then I'm not sure I can help you, try Googling for some help; it's what I'd do.
If it does work, then we can continue.

I'd already prepared my five sound files (WAV - 16 bit/48KHz) containing single notes and five image files (JPG) with the pictures to be used, so the only thing to do now was put them together. This took a bit of experimentation, but finally I ended up with an AVS file like this (explanation at the end):



# AVS – avisynth file for generating notes for Jordan sequence

# filename: T_Test_up_1.00s.avs T:12345 I:12345
# variables
# lenB is blank period before and after sequence of pictures, in frames
lenB=25
# lenP is length each picture is shown, in frames
lenP=25
#
# Blank intro
video = ImageSource("C:\Black.JPG", end=lenB, fps=25)
audio = WAVSource("C:\Blank-1s0.wav")
clip0 = AudioDub(video, audio)
# 1
video = ImageSource("C:\1.jpg", end=lenP, fps=25)
audio = WAVSource("C:\1.wav")
clip1 = AudioDub(video, audio)
#
# 2
video = ImageSource("C:\2.jpg", end=lenP, fps=25)
audio = WAVSource("C:\2.wav")
clip2 = AudioDub(video, audio)
#
# 3
video = ImageSource("C:\3.jpg", end=lenP, fps=25)
audio = WAVSource("C:\3.wav")
clip3 = AudioDub(video, audio)
#
# 4
video = ImageSource("C:\4.jpg", end=lenP, fps=25)
audio = WAVSource("C:\4.wav")
clip4 = AudioDub(video, audio)
#
#5
video = ImageSource("C:\5.jpg", end=lenP, fps=25)
audio = WAVSource("C:\5.wav")
clip5 = AudioDub(video, audio)
#
# blank Outro
video = ImageSource("C:\Black.JPG", end=lenB, fps=25)
audio = WAVSource("C:\Blank-1s0.wav")
clip6 = AudioDub(video, audio)
#
#
clip0 ++clip1 ++clip2 ++clip3 ++clip4 ++clip5 ++clip6
#
# end

So, what's going on here:

  • Everything after a hash ('#') is a comment
  • I've given a bit of explanation at the beginning, plus the sequence of notes and images (in T: and I:)
  • Then there are two variables to set the length of time (lenB) of the blank bits at the beginning and end of the whole sequence, and then the length of time (lenP) each image shows along with the sound. I've chosen 25 here, as in 25 frames-per-second to keep it nice and simple. I did some tests that said a second looked about right; any shorter made the video too jerky and any longer made it drag.
  • Then we're on to the first bit of video, which is a blank frame, just using a JPG formatted to 720 pixels wide by 576 pixels high. Why those sizes, you ask?
Well, that's the standard frame size for a PAL DV codec, and having played around with some of the testing software (E-Prime and SuperLab), I found that one of them (SuperLab) had problems with showing out-of-spec videos. So, I made them in-specification.

  • Avisynth has problems showing a video without audio, so I created a blank audio file 1 second long.
  • And the instruction 'AudioDub' puts them together, and then I assigned it the name 'clip0'
  • The same instructions are repeated for all the other clips, and another blank section added to the end, then the final instruction:
clip0 ++clip1 ++clip2 ++clip3 ++clip4 ++clip5 ++clip6

Is the one that concatanates all the clips together for the video.

  • And that's it! This .AVS video will happily play in Windows Media Player, so as to test it.

Having created the template for the AVS file, I then used Excel to generate all the different variables for which image (n.JPG) was to display with which sound (n.WAV), and simply copy'n'pasted all sixty results from Excel into text files. (I won't bore you with the
details of how to do the Excel file, just to say that it was very simply done by manually stepping through a list of the sequences).

Now to make them into real videos, and for that we need VirtualDub

Onto Part 3: Batch encoding AVS files into AVI files

No comments:

Post a Comment