PDA

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


zambelli
25th November 2003, 07:12
The information relating to wmcmd.vbs in this post is now out of date. See http://forum.doom9.org/showthread.php?t=111633 for an updated wmcmd.vbs that fixes the Avisynth input issue.

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.

dattrax
25th November 2003, 10:05
Have you posted this to the AVS forum, as the developers may be able too add in the missing property?

Jim

zambelli
25th November 2003, 12:31
Yep, I did. I'm sure careful debugging of the wmcmd.vbs script would pinpoint the miscommunication that's occuring between Avisynth and WME.
http://msdn.microsoft.com/library/en-us/wmencode/htm/windowsmediaencoderautomation.asp is the programming reference for WME9, if anyone is interested.

Beastie Boy
25th November 2003, 12:54
Funny. I've never had a problem encoding via Avisynth in WME9 (in fact I'm doing it at the moment).
However, there is no Time Remaining or Percent Complete info displayed.
Have you selected YV12 as the input format?

Cheers, Beastie.

Sagittaire
25th November 2003, 13:02
WME9 work directly with AviSynth Script ...

bleo
25th November 2003, 14:19
WME9 works with avs scripts if you load them at "Source from: Both device and file".

But thanks for that anyway zambelli :D

nFury8
25th November 2003, 15:43
As with Beastie Boy, Sagittaire and bleo, ditto here. I can always load avs input into WME9 with no problems. Although info on Time Remaining and Percent Complete would have been useful in some way if it were properly displayed in the General tab under the Monitor window. In any case its a pretty good effort on zambelli's part.

zambelli
26th November 2003, 00:26
Bleo: Thanks for that tip! That does indeed work! It never occured to me that "Both device and file" might work when "File" doesn't. If you use "File", you'll see that you'll run into the "Interface not supported" error that I was talking about. I suppose this means that a slightly different code path is used in WME9 for encoding from those different sources. Perhaps because a device might be used as input WME9 simply ignores the duration property of the source altogether, thus avoiding the error.

If you're wondering, "He works for MS, why the hell doesn't he just check the WME9 source code and make sure?", you're right, I could. But that wouldn't be much fun, would it now? :-)))


Beastie Boy: Although it's possible to explicitly specify color space of the source content, it's not necessary. WME9 should be able to detect the color space of the .avs source. And it does, from what I can tell.