Skip to content

DirectShow filters that put AviSynth and VapourSynth into video playing

License

Notifications You must be signed in to change notification settings

CrendKing/avisynth_filter

Repository files navigation

DirectShow filters that put AviSynth or VapourSynth into video playing, by loading a script and feed the generated frames to video player.

Each filter takes video samples from upstream, feeds them to the frame server in compatible format, and delivers the transformed output frames to downstream.

If you used ffdshow's AviSynth plugin before, you may find these filters similar in many ways. On top of that, our filters are actively adding new features.

Features

  • Support wide range of input formats:
    • 4:2:0: NV12, YV12, P010, P016, etc
    • 4:2:2: YUY2, P210, P216
    • 4:4:4: YV24, Y410, Y416
    • RGB24, RGB32
  • High performance frame generation and delivery
  • HDR metadata passthrough
  • API and Remote Control
  • Portable mode

Requirement

  • CPU with SSE2 instruction set.
  • Windows 7 and above.
  • AviSynth+ 3.5.1 (interface version 7) and above, or
  • VapourSynth R55 (API version 4) and above.
    • In case you have to stay at VapourSynth version R43 (API version 3.5) through R55, use v1.2.1.
  • Note: It is highly recommended to use open sourced video demuxers and decoders such as LAV Filters in your player of choice.

Install

  • Before anything, install AviSynth+ or VapourSynth. Make sure the frame server's dll files are reachable either in the directory of the video player, system directories or directories from the PATH environment variable.
  • Unpack the archive.
  • Run install.cmd to register the filter .ax files.
  • Enable AviSynth Filter or VapourSynth Filter in video player.

Uninstall

Run uninstall.cmd to unregister the filters and clean up user data.

安装

  • 首先安装 AviSynth+ 或者 VapourSynth。确保它们动态链接库置于播放器的目录下,系统目录下,或者 PATH 环境变量中。
  • 解开下载的压缩包。
  • 运行 install.cmd 注册过滤器。
  • 在播放器中启用 AviSynth Filter 或者 VapourSynth Filter 过滤器。

卸载

运行 uninstall.cmd 删除注册信息和用户信息。

Usage

Common

By default, 10-bit and 16-bit input formats are enabled for best video quality. However, not all video renderers are capable of processing these data. If you do not have such a video renderer installed, leaving these options on might cause compatibility issues. In that case, you should open the settings page of the filter and untick the relevant checkboxes.

Examples of 10/16-bit capable video renderers: madVR, MPC Video Renderer.

Examples of video renderers having issues: Enhanced Video Renderer (related issue), PotPlayer "Built-in" video renderers (related issue).

The following Reserved Frame Properties are generated (AviSynth+ v3.6.0 and above, VapourSynth):

  • _Primaries
  • _Matrix
  • _Transfer
  • _FieldBased
  • _AbsoluteTime
  • _DurationNum
  • _DurationDen
  • _SARNum
  • _SARDen

AviSynth Filter

The filter exposes the following functions to the AviSynth script:

AvsFilterSource()

The source function which returns an IClip object. Similar to other source functions like AviSource().

This function takes no argument.

AvsFilterDisconnect()

This function serves as a heuristic to disconnect the filter itself from DirectShow filter graph. Put at the end of the script file.

It can be used to avoid unnecessary processing and improve performance if the script does not modify the source. Avoid to use it during live reloading.

A good example is if your script applies modifications based on video metadata (e.g. FPS < 30), without using this function, even if the condition does not hold the filter still needs to copy every frame. At best, it wastes both CPU and memory resource for nothing. At worst, it breaks hardware acceleration chain for certain filters. For instance, when LAV Filters connects directly to madVR in D3D11 mode, the GPU decoded frames are not copied to memory. If any filter goes between them, the frame needs to be copied.

This function takes no argument.

AvsFilterGetSourcePath()

Returns the path to the source video file.

This function takes no argument.

VapourSynth

The filter exposes the following variables to the VapourSynth Python script:

VpsFilterSource

This variable has the type of VideoNode. It serves as the source clip.

Note that the fps property of the video node is set to the average framerate instead of 0 / 1, regardless if frames have variable frame durations. It is equivalent to mpv's container_fps variable.

VpsFilterDisconnect

This variable does not exist at the entry of the script. Upon return, if this variable exists and has an non-zero value, it disconnects the filter itself from DirectShow filter graph.

VpsFilterSourcePath

Represents the path to the source video file.

API and Remote Control

Since version 0.6.0, these filters allow other programs to remotely control it via API. By default the functionality is disabled and can be activated from settings (requires restarting the video player after changing).

For details of the API, please refer to the comments in source file api.h.

Example scripts

Add a line of text to videos with less than 20 FPS. Otherwise disconnect the filter.

AviSynth

AvsFilterSource()

fps = Round(FrameRate())
if (fps < 20) {
    Subtitle("This video has low FPS")
    Prefetch(4)
} else {
    AvsFilterDisconnect()
}

VapourSynth

from vapoursynth import core
import math

fps = round(VpsFilterSource.fps)
if fps < 20:
    core.text.Text(VpsFilterSource, 'This video has low FPS').set_output()
else:
    VpsFilterDisconnect = True

Build

A script build.ps1 is included to automate the build process. It obtains dependencies and starts compilation. Before running build.ps1, make sure you have the latest Visual Studio and git installed. When running the script, pass the target configuration and platform as arguments, e.g. build.ps1 -configuration Debug -platform x64 or build.ps1 -configuration Release -platform x86.

Credit

Thanks to Milardo from Doom9's Forum for help initially testing the project.

Thanks to chainikdn from SVP team for contributing features.