## How to use AviSynth with MediaCoder (Stanley posted on June 5th, 2008 )

MediaCoder is known to be fully standalone and not dependent on any splitters, decoders, and filters that have to be installed in the system. However, in some cases, we do need to make use of those stuffs to achieve some goals. AviSynth is the bridge between splitters/decoders/filters and multimedia applications. There are two ways for using AviSynth with MediaCoder. Of course, as a precondition, you need to install AviSynth and possibly a codecs pack (e.g. K-lite) which contains a bunch of splitters and decoders.

1. Adding an AviSynth script into Mediacoder

This is the simple way. Write your script and add it into MediaCoder to let it transcoded just like a normal media file. The media info sidebar will not show the information (e.g. resolution, fps, format) of the actual media file referred in the script, instead it will always show something like rawyv12 and pcm, because AviSynth is taking care of the decoding and post-processing, and MediaCoder will only see decoded yuv and pcm data.

As an example, we write our script named example.avs. The script is like following:

DirectShowSource(“F:\Video\Sample\tmnt-tlr1_h1080p.mov”)

# crop a 4:3 square from the original 16:9 screen
Crop(416, 0, 1088, 816)

# resize the dimensions of the video frame to 320×240
LanczosResize(320, 240)

# TemporalSoften is one of many noise-reducing filters
TemporalSoften(4, 4, 8, scenechange=15, mode=2)

# increase the gamma (relative brightness) of the video
Levels(0, 1.2, 255, 0, 255)

# fade-in the first 90 frames from black

# fade-out the last 15 frames to black

The resolution of actual file is 1920×816, but MediaCoder shows 320×240. This is normal because the script has performed cropping and resizing operations. The same thing happens to other information shown like duration as trimming is also performed.
After saved the script to a file, we add it into MediaCoder. The rest is just the same as working with a normal media file.

2. Using AviSynth script template

This is a new way and a simple way too, implemented since build 4115. Sometimes, we need to process a several files with the sample script and this is the case this new way is for. Since build 4115, a new AviSynth tab is added.

To use AviSynth script template feature, we need to activate the “Use AviSynth” option on the AviSynth tab. Then we need to create a template script. A template script is almost a normal script with some variables that MediaCoder recognized written in. At the moment, the useful variable is “SourceFile” which will be replaced with the name of the file that is being processed. The following is an example of teamplte script:

DirectShowSource(“$(SourceFile)”) # crop a 4:3 square from the original 16:9 screen Crop(416, 0, 1088, 816) # resize the dimensions of the video frame to 320×240 LanczosResize(320, 240) # TemporalSoften is one of many noise-reducing filters TemporalSoften(4, 4, 8, scenechange=15, mode=2) # increase the gamma (relative brightness) of the video Levels(0, 1.2, 255, 0, 255) # fade-in the first 90 frames from black FadeIn(90) # fade-out the last 15 frames to black FadeOut(15) As you can see, the only difference between the template and the script we wrote just now is the first line. The variable names are the same as the ones MediaCoder uses in the encoder command line. In the future, more useful variables for AviSynth scripting might be introduced in. After the script template is written, click “Use Script Template” and you will be able to choose a file as template. After that, We can just add media files into MediaCoder and start transcoding like we are used to. You can also use “Generate Script” option and MediaCoder will automatically generate a minimum script template with the source selected. Hope you can enjoy. ### 4 Responses 1. Rob says: Using the script template doesn’t work for me. In the generated avs-file (located in the temp directory) MediaCoder writes something like: DirectShowSource(”C:\temp\file.avs”) i. e. a circular self reference. I’d expect something like: DirectShowSource(”Z:\path\to\my\videos\file.mov”) Am I missing a point? Rob 2. stanley says: This looks like caused by a bug. I will fix this soon. 3. Peter Fritz says: Still buggy.. AVISource(”$(SourceFile)”)
results the destination file in the (temp) script, not the sourcefile.

4. Peter Fritz says:

When I tried the simple template
AVISource(”\$(SourceFile)”)
resulting output (in temp)
is AviSource(”U:\Video-Archiv\Sansa\test.mpg”)
This is the destination, not the sourcefile.

Peter