View Full Version : Encoding Avisynth (.avs) sources with WME9

25th November 2003, 07:16
(I apologize for the re-post... I figured this might interest readers of this forum too.)

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.

25th November 2003, 10:11

(moved it to the right forum, though).

25th November 2003, 12:52
How about the ffvfw-lite AVISynth-in-AVI wrapper?

25th November 2003, 14:43
It would be very strange if it didn't work - i haven't experienced anywhere, where it didn't work when audio was written to the AVI. However one step less (ie. not having to create the fake AVI is always a good thing.

25th November 2003, 15:23
If you don't mind to use AVI as container, you can download the wmv9 codec (http://www.microsoft.com/windows/windowsmedia/format/codecdownload.aspx - see: "Codecs Installation Package for Windows Media Video 9 VCM")
After installing it, you can use wmv9 in VDub (like XviD or DivX).

26th November 2003, 00:59
Jonny: This is true, and it's certainly convenient to be able to use WMV9 in VDub, but in my opinion (and I try to keep it as unbiased as possible) ASF does have one big advantage over AVI: it supports non-square pixel encoding. If you're encoding anamorphic content it's a huge factor to be able to preserve the full resolution of the video source while still maintaining the proper aspect ratio and fully utilizing the bitrate.

Take as an example a case where you have an anamorphic DVD source that you're trying to convert to WMV9. If you use AVI as the container, you're stuck with square pixels. Your 720x480 source now needs to be resized to a square pixel resolution such as 864x480 or 640x360 to maintain the proper aspect ratio. In the former case you waste bitrate; in the latter you lose lines of resolution. Sure, you could keep the full resolution and encode the AVI as 720x480 and then use a 3rd party player such as BSPlayer or MPC which supports real-time resizing, but then you're increasing the level of complexity. Correct playback becomes a skill. Would your tech challenged friend know to use the right player or to set it to the right resizing mode?

With ASF, on the other hand, you can simply encode the 720x480 source "as is", without any resizing, and set the PAR to 23:19 (I calculated this on the fly just now so I could be a little off) to force the player to resize the rendered image to 870x480. WMP9 will do this and any other player which uses VMR-9 (such as MPC) should be able to do this automatically.

26th November 2003, 09:54
With ASF, on the other hand, you can simply encode the 720x480 source "as is", without any resizing, and set the PAR to 23:19 (I calculated this on the fly just now so I could be a little off)

First time i hear about this, thanks for the info.
Anyway, yep, i try to keep all the rows too (when is possible) :)
Usually i store the correct aspect ratio in the filename: test_2_347.avi (and i set something like this with BSPlayer: 2347:1000).
(i calculate the correct ar after cropping)
I know that while this looks really simple to my eyes, could look incomprensible to someone other ( expecially some friends :D )

26th November 2003, 13:08
Oh man, this is the first time you'll hear me recommend Matroska, but set against ASF I just can't help but do. Matroska has pixel aspect ratio setting too, and you can encode in it through VirtualDubMod, which works via the VfW API.
(how I'll regret having posted this later :D)

26th November 2003, 14:31
zambelli, now you have the complete solution :)

14th December 2003, 18:27
Actually there are two wm9 encoders. The command line encoder, which cannot encode videos frame served by avisynth and the encoder with a GUI, which can handle AVS scripts. It is quite buggy though and Microsoft has built in a very special user terror feature. If the system is overloaded and cannot give cpu cycles to the encoder for a while the encoder STOPS and you have to start from the beginning. Nevertheless I managed to encode quite a few videos frame served by avisynth.

5th February 2004, 07:37
Thank you for WMV+AVS info

27th February 2008, 19:26
... 4 years later

I had been using the Windows Media Encoder GUI "Source From: Both Device and File" trick to perform my WMV encodes from avs but this method suits me much better and worked great. Thanks for this information!

One issue I was wondering if anyone could help me with: When I tried to batch my encodes (rather than have just have a single encode per .bat file) the cmd console became unresponsive after outputting the details of the first encode and did not move onto the next. Actually, it happens after each encode, regardless, but it is only a problem when they are batched. Is anyone aware of this being a common problem or does anyone have a potential solution?

The only special filters loaded in the .avs are VobSub and DGdecode.

If not, is anyone aware of a way that I could force kill a command console after an encode is complete and load another bat file.

Like batching up a sequence of .bat files with a kill process in between each. So.. a bat file of launching other bats that launch processes that commit suicide when they are complete. Something like that. Or maybe the vbs could be modified further?
I am a moron.

ANYWAY, if anyone can help, that would be excellent.


Edit: I visited Zambelli's site (http://www.citizeninsomniac.com/WMV/#WMCmd) in the hope that there might be something there and there was an updated VBS which does everything I could ever ask for. My prayers are answered. Thank you!

28th February 2008, 07:00
You don't see to be the only one:

28th February 2008, 13:08
Thanks for the information, Shodan.

My problems have all been solved by Zambelli's most recent (October 11, 2007)modified vbs (http://www.citizeninsomniac.com/WMV/#WMCmd).

I don't know if the problems I've outlined here apply to that thread as this is the first time I've ever had a functioning command line batch encoder for Windows Media and it's been a while since the January hotfixes that those people suspect of causing the trouble were installed on this machine.

I do have experience of other WMencoder quirks though, hopefully it will be useful info to someone!

Edit: I get the feeling it's a Vista only problem, running XP here.