View Single Post
Old 13th May 2015, 07:08   #2115  |  Link
Zachs
Suptitle, MediaPlayer.NET
 
Join Date: Nov 2001
Posts: 1,721
Avisynth-like Scripting Language

Hi everyone,

I've added a new render script called "Scripted Render Chain" which allows you to write Avisynth-like scripts. It's based on JavaScript, so you can use any of JavaScript's built-in features (e.g. string processing).

The default script goes like this (it's does exactly everything Custom.MyRenderScript.cs does and it's a good starting point to write your own script).
PHP Code:
// Example render script

// Scale chroma first (this bypasses MPDN's chroma scaler)
BicubicChromaPreset Presets.MitchellNetravali )

// Apply some filtering pixel shaders
ImageProcessorShaderFileNames = ["SweetFX\\Bloom.hlsl""SweetFX\\LiftGammaGain.hlsl"] )

// Use NEDI once only.
// Note: To use NEDI as many times as required to get the image past target size,
//       change the following *if* to *while*
if (input.NeedsUpscaling)
{
    
NediAlwaysDoubleImage true )
}

if (
input.NeedsDownscaling)
{
    
// Use linear light for downscaling
    
ImageProcessorShaderFileNames = ["ConvertToLinearLight.hlsl"] )
    
ResizerResizerOption ResizerOption.TargetSize100Percent )
    
ImageProcessorShaderFileNames = ["ConvertToGammaLight.hlsl"] )
}

if (
input.SourceSize.Width 1920)
{
    
// Sharpen only if video isn't full HD
    // Or if you have FineSharp installed, replace the following line with it
    
ImageProcessorShaderFileNames = ["SweetFX\\LumaSharpen.hlsl"] )

This script is currently saved in %localappdata%\MediaPlayerDotNet\DefaultScript.rs (there's no need to know this - you can simply change the script in the config screen).

As you can see, it uses a very simple syntax to add filters to the chain. More importantly though, you can change the script and have MPDN use it on the fly without having to restart MPDN!

Note that if you edit the file externally, you'll need to manually resize the MPDN window for it to take effect. If you an error with your script, MPDN will display the error on the screen in place of the video.

All functions that the 'rs' script can access are available in the Clip and Host classes (see Mpdn.ScriptedRenderChain.ScriptHelpers.cs). 'Clip' is available via the 'input' object while 'Host' is 'host'. There's also a "Debug.Output" function that allows you to dump debug messages to the DbgView app.

For example,

PHP Code:
input.FileName // returns the full path and file name of the video file
input.FrameRateHz // returns the fps of your video
input.SourceSize.Width // returns video source width
host.ExePath // returns the folder name of which MPDN's executable file resides 
The render scripts you can use in the 'rs' script currently are,
PHP Code:
Lut3DColorCorrection    
ImageProcessor    
Preset
Resizer    
BicubicChroma    
Deband    
Nedi    
NNedi3    
OclNNedi3    
// OpenCL version of NNEDI3
SuperChromaRes    
SuperRes 
Have fun!

Last edited by Zachs; 13th May 2015 at 07:17.
Zachs is offline   Reply With Quote