View Full Version : HOWTO: Run an AVISYNTH script (imagewriter) without a player within a batch file??

22nd April 2004, 14:09
Hi folks,

Anyone got any ideas on this one..

I want to use a simple avisynth script to read in an avi file then using imagewriter output the frames to tga files..

This is all done and nice and easy.. the thing is i want to have it as part of a batch file and was wondering if there is some way i can execute the avisynth script without having to have it in a player.. I may try mplayer as this will run and block my batch file till it reaches the end of the file but it just seems strange that its not easy to make avisynth sit in with other scripts as its obviously a scripting language itself. Or is this something that you can do?

Ideally i'd like the script to write out the audio to a seperate wave as well but i couldn't find an equivelant wave writer function..

If anyone knows how to do this i'd really be grateful :) if anyone knows of a simple tool that will work maybe at the command line to do this splitting of images and audio then that'd be useful too but i really would like to stick with avisynth as i love the flexability :)



22nd April 2004, 14:37
You have to find a command line program to
"read" the AVS. I can't think of one at the moment.
I had a similar problem , I wanted to execute a AVS
as fast as possible ( faster than real time )
I finally got Vdub to scan for bad frames

Mug Funky
22nd April 2004, 14:38
hmm. you could do a batch job with virtualdub, but you'd end up with 2 files, and it wouldn't solve the audio saving thing.

media player classic has a commandline mode IIRC.

22nd April 2004, 14:56
Thanks for the help guys..

Its a shame avisynth doesnt come with a dummy avi/avs parser that simply "executes" the avisynth script..

I did wonder about using virtual dub to split the audio.. how do you mean i'd end up with 2 files? I've seen gordian knot etc do batch control of virtual dub but i've never tried it before..

I think i may have seen an avi tool to grab out the audio..

Ohh well i'll have a real look tonight at home but if i can't get something to fit in the command line chain then I guess writing one yourself is an option.. urgh..

22nd April 2004, 16:14
Download http://home.t-online.de/home/340044300675/rip.zip , you only need the avsutil.exe from the ZIP. Then to "play" your AVS, useavsutil "d:\somedir\some.avs" -play in a batch file. It's command line and won't pop up any windows.

22nd April 2004, 17:45
RB, you are a real hero!! Thanks a lot..

That all looks to be working.. really nice utility that one..

All i'm left with now is something that can write out a wave from the audio of the avi... is this even possible with avisynth??

I've spotted that virtualdub scripting language seems to offer this but have never done any with it.. I can't join their support forum right now either as i dont have access to the email they'll send the verify message to.. I will look later though

Thanks again..

Richard Berg
23rd April 2004, 03:01
A WAVwriter wouldn't really be practical since there is not a direct correspondence between frames and samples. Perhaps AVS2AVI could be expanded to provide this.

23rd April 2004, 03:11
Thanks to RB
I tried the avsutil and it worked.
I was somewhat disturbed to find that its run time was over 60%
of just playing the AVS in Vdub.
I thought it would be faster.
The test AVS used "compare" to write a file of differences
between adjacent frames. I suppose that's fairly compute intensive .

26th April 2004, 12:35
do you know where i can finde more details on this tool?
google doens't find anything

Richard Berg
26th April 2004, 15:02
Google found it for me:

27th April 2004, 08:39
Originally posted by E-Male
do you know where i can finde more details on this tool?
google doens't find anything
Well, I wrote it myself, maybe that's why :) Richard, has nothing to do with AVS2AVI actually :)

As for the speed issues, don't know why it should be so slow. It's really only a quick hack I put together for my private needs, actually I too needed it for the ImageWriter stuff in a batch file. The source code is just a few lines, here it is:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <vfw.h>

int main(int argc, char *argv[])
int i, frames = 0;
AVIFILEINFO avInfo = {0};

if (argc < 2)
return 0;


if (!AVIFileOpen(&pFile, argv[1], OF_READ, NULL))
if (!AVIFileInfo(pFile, &avInfo, sizeof(AVIFILEINFO)))
frames = avInfo.dwLength;

if ((argc > 2) && (!stricmp(argv[2], "-play")))
if (AVIFileGetStream(pFile, &pStream, streamtypeVIDEO, 0))
printf("AVIFileGetStream failed\n");

if (AVIStreamBeginStreaming(pStream, 0, frames, 1000))
printf("AVIStreamBeginStreaming failed\n");

if (NULL == (hGet = AVIStreamGetFrameOpen(pStream, NULL)))
printf("AVIStreamGetFrameOpen failed\n");

for (i = 0; i < frames; i++)
AVIStreamGetFrame(hGet, i);

if (hGet)
if (pStream)



printf("%d\n", frames);

return frames;


27th April 2004, 13:02
i'm sure the speed issues were due to Avisynth
in my case. I'll try it again with a script
that just copies it's input.

27th April 2004, 14:31
thx for the code and thx for this tool
will be very usefull for filters that need 2 (or more) passes

Richard Berg
27th April 2004, 21:43
Sorry. I'm used to people calling me "RB" on other forums.

28th April 2004, 09:29
my own solution was
avs2avi temp.avs -o n -c DIV3

note! don't forget add crop(0,0,8,8) to the end of your avs :)

12th March 2006, 11:27
The link for avsutil seems to be broken. Could anyone help me, by compiling RB's script above and upload it?


12th March 2006, 11:56

Utterly untested, good luck.

12th March 2006, 11:57
Wow that was fast - thanks!!

28th March 2006, 00:31
The default "Open" action for AVS file is "notepad" in my system. Does this program work? (It appears not to....)

28th March 2006, 07:59
Sorry for not reporting back earlier. It didn't work for me.

28th March 2006, 11:12
It's overkill for such a problem, but MeGUI has an 'analysis pass' feature which does exactly what you want; it simply requests each frame from the beginning to the end. Just open your avs in the main window, then press the Queue analysis pass button and voila! it's in the queue.

The way I did it before I added it to MeGUI was to use
mplayer -vo null -benchmark file.avs

28th March 2006, 13:11

Changed it slightly - added a progress display (outputs to stderr so it shouldn't upset redirection) and took the hyphen off -play.

>avsutil somescript.avs
... Will open somescript.avs and print the total number of frames.
>avsutil somescript.avs play
... Will open somescript.avs, read each frame then print the total number of frames.

If the total number of frames = 240, it probably means there's an error in the script. (240 frames is the length of error clips returned by avisynth.)

EDIT: I think I might have compiled it with unicode support. If so, it might not run on earlier versions of windows.