HOWTO: AviSynth video processing with WINE
This guide has been tested with Ubuntu 9.10, 10.04 and 10.10, and AviSynth 2.5.8 and 2.6.0 Alpha 2 (090927), but should work in any modern Linux distribution, with any 2.5+ version of AviSynth (and probably older ones too).
Unless otherwise noted, all Windows-like paths (e.g. c:\windows\system32) in this guide refer to the corresponding locations in your WINE virtual drive (by default, ~/.wine/drive_c).
This document is copyright 2009-2010 Firas Kraïem. It may be redistributed in any form, for any purpose, with or without modification, provided that this copyright notice appears in the distribution.
AviSynth is a very powerful video processing tool for Windows. Since it uses Windows-only interfaces like VfW (Video for Windows), AviSynth scripts cannot be used directly as input for Linux video encoding tools. However, a solution exists: avs2yuv is an utility designed specifically for WINE, which takes an AviSynth script as input, and dumps its output as a yuv4mpeg stream to stdout or to a file, thus allowing further processing using any encoding tool that supports yuv4mpeg input.
In order to use it, the AviSynth DLLs (avisynth.dll and devil.dll) must be present in your WINE library path. Just running the AviSynth installer in WINE will do the trick. I also recommend copying avs2yuv.exe to c:\windows\system32 so you can run it by typing just wine avs2yuv, instead of its full access path.
Finally, it is a good idea to have the latest x264 (see for example this guide about compiling it), since the build from the Karmic repositories is old and lacks some options that make our lives easier.
The avs2yuv homepage shows some usage examples. Another handy one, using x264 for encoding, would be:
The --stdin y4m parameter is important: it tells x264 that what it gets on stdin is a yuv4mpeg stream. By default, x264 expects raw YUV data, which is not what we have.
wine avs2yuv input.avs - | x264 --stdin y4m --output output.264 -
If you kept the x264 version from the repos, you can use:
Since the x264 version from the repos does not support y4m on standard input, you have to pass raw YUV data instead, which means that you also have to specify the framerate and resolution of your video stream.
wine avs2yuv -raw input.avs - | x264 --fps 24000/1001 --output output.264 - 848x480
If you have a lot of similar encodings to do, you can use shell scripts to automate that, for example:
% cat encoding.sh
# encoding.sh [input] [pass] [bitrate] [output]
# input: input .avs script
# pass: 1 for first pass, 2 for second pass
# bitrate: bitrate :D
# output: output file
if [ $2 = 1 ]; then
wine avs2yuv $1 - | x264 --preset slower --tune animation \
--pass $2 --bitrate $3 --stats "$4.pass" --bframes 4 --ref 8 \
--trellis 1 --colormatrix bt470bg --stdin y4m --output $output -
% ./encoding.sh input.avs 1 1500 output.264
% ./encoding.sh input.avs 2 1500 output.264
Bugs and caveats
- FFT3DGPU does not work in WINE 1.2 but works in WINE 1.3 (remember to install Direct3D first, it's d3dx9 in winetricks).
- VSFilter does not work correctly in WINE 1.0 (though hopefully no one uses it anymore). It works in WINE 1.2/1.3, but some fonts look very bad with it.
- RemoveGrain's dynamically linked builds (RemoveGrain.dll, RemoveGrainSSE2.dll, RemoveGrainSSE3.dll, et al.) require the Microsoft Visual C++ 2005 runtime libraries (vcrun2005 in winetricks). The statically linked builds (RemoveGrainS.dll, et al.) do not.
All other filters I've tested work out of the box. Of course, I can't test them all, so if you find one that doesn't, please report in this thread.