If you ever tried using Avisynth scripts as sources in the Windows Media 9
Encoder, you probably discovered that it simply didn't work. In all likelyhood
you received an error message "No such interface supported".
This bothered me for the longest time. I always assumed the error message was
indicating that somehow .avs files weren't supported as sources in WME9. And
yet, I knew from Nic's practical implementation of the WM encoder object model
that it was possible to feed .avs files to WME9.
So I finally decided to explore the problem more closely. I analyzed the
VBScript-based encoder sample that shipped with WME9 - wmcmd.vbs - and found
nothing in the source code that would theoretically prevent WME9 from reading .avs
files. I then ran wmcmd.vbs under the Visual Studio script debugger and waited
for the script to error out. When it did, I was somewhat surprised to find out
that the error had nothing to do with the source reading method.
Apparently, the script-based WME9 was trying to read the duration property of
the source object - and it was finding that the duration property did not exist.
It errored out every time it attempted to print out the progress of the encoding
process. Doh! I assume the GUI-based encoder was doing a similar thing - trying
to access properties of the video source object that Avisynth simply wasn't
supplying - at least not in the way that WME9 expected it.
Well, with that figured out, the fix became easy. Considering source duration
was only being used for the trivial progress printout, I simply took out the few
lines of code out of wmcmd.vbs that dealt with source duration. The upside: WME9
(script-based only) now accepted Avisynth scripts as input. The downside?
Progress percentage disappeared from the printed output. Not a big loss, I think
you will agree.
So, what do you need to do to make WME9 work with Avisynth? It's quite simple,
really. First make a copy of the wmcmd.vbs file that shipped with WME9. Call it
something like WME9AVS.vbs, perhaps. Now open the file in Notepad or any
text/code editor and find the text "Compute file duration". Beginning
with that line, delete every line of code up until (but not including) "intSleepDuration
= 2000". The deleted section should count about 20 lines of code. Now
replace the deleted code with the line:
intDuration = 0
Save the file and you're done. You should now be able to use wmcmd.vbs with any
valid .avs file as source. As I said, the only downside is that you won't be
able to get the progress report about your encoding pass, including info about
the start of Pass2. Oh well. Don't forget that the .vbs version of WME9 is just
about as powerful as the full version of the encoder. If you run into a setting
that's not supported in the script-based encoder, just go and create a profile
in the full encoder and then use the script-based encoder with the "-wme"
switch. This is essentially how you get 6-channel mono WAV input and other nifty
tricks done.
Feel free to suggest better fixes for the duration bug, if you can think of any.
My solution is merely a workaround, I'll admit that, but for right now it gets
the job done.