AviSynth+ Documentation

repository·master·Indexed 22 days ago

https://github.com/avisynth/avisynthplus

AviSynth+ is a high-performance video processing engine and improved version of the AviSynth frameserver. This documentation covers installation via CMake, building HTML docs with Sphinx, and advanced video processing topics including interlaced vs field-based video, colorimetry standards (Rec.601 and Rec.709), Variable Framerate (VFR) and hybrid video handling, and media import methods.

Tokens
220.6K
Snippets
580
Records
943
Agent score
78%

What's inside AviSynth+

  1. Overview of AviSynth+ video and internal features

    master

    AviSynth+ is a high-performance video processing framework that supports advanced video formats and modern hardware architectures.

    Video Capabilities:

    • High bit depth support: 10, 12, 14, 16 bits, and 32-bit float.
    • Planar RGB support.
    • Planar Alpha-plane formats.
    • Frame properties access.

    Internal Architecture:

    • 64-bit support: Full 64-bit implementation.
    • Cross-platform: Supports various operating systems (not limited to Windows).
    • SIMD-focused: Uses SIMD intrinsics instead of internal assembler, making it compatible with non-Intel x86/x64 platforms via C++.
    • Multithreading: Features a rewritten multithreading support system.
    • Language Extensions: Supports new language elements including function objects and arrays.
    • CUDA Support: Provides a framework through IScriptEnvironment to host direct CUDA-plugins in specific builds, though the core itself does not use CUDA.
  2. Overview of the AviSynth Filter SDK

    master

    The AviSynth Filter SDK is a developer package used to create custom filters, including plugins and standalone console applications.

    The SDK includes:

    • Documentation (HTML/Wiki format).
    • avisynth.h: The primary header file containing declarations for plugin source code.
    • Sample source code for various plugins and console applications.
    • Extra utility files located in the Extra folder.
  3. Explore AviSynth+ Documentation Overview

    master

    The AviSynth+ documentation is organized into several key areas to help you master scripting and video processing:

    • Getting Started & Quick Reference: For initial setup and rapid lookup of common commands.
    • AviSynth Syntax: Detailed technical documentation on the language grammar, including statements, variables, operators, control structures, and the full suite of internal functions (Boolean, Numeric, String, Bit, etc.).
    • Scripting Reference: Explains the mental model of AviSynth+, including the script execution model, the implicit filter graph, frame fetching mechanics (bottom-to-top), and variable scope/lifetime.
    • Core Filters: Documentation for built-in filters categorized by function, such as Media file filters, Color conversion, Overlay/Mask, Geometric deformation, and Audio processing.
    • External Filters (Plugins): Guidance on using and managing third-party plugins.
    • Advanced Topics: Deep dives into complex video concepts like Interlaced/field-based video, Video Sampling, ColorSpace Conversions, and Hybrid Video.
    • Troubleshooting: A dedicated section for resolving common issues.
  4. New filters and features in AviSynth+ v3.7

    master

    AviSynth+ version 3.7 introduced several new filters and expanded support for various formats and bit depths:

    New Filters

    • AverageA: New averaging filter.
    • ShowCRC32: A debug filter with the same parameters as ShowFrameNumber.
    • Histogram("color2"): Supports 10+ bit depths. You can specify the bit depth using the bits=x parameter (where x is 8, 9, 10, 11, or 12).
    • Histogram("levels"): Now allows greyscale input.

    Format and Input Improvements

    • Average... filters: Now allow YUY2 and RGB24/32/48/64 inputs.
    • Overlay: Now allows 4:1:1 input.
    • RemoveAlphaPlane: Now performs no action on YUY2 instead of throwing an error.
    • AviSource:
      • Supports non-printing characters in fourCC codes using the [number] style (e.g., G3[0][16]).
      • Added native support for Y410 (YUVA444P10) format and Y410 pixel_type hints.
      • Native decoding for several fourCCs: b64a, b48r, v210, P210, P010, P016, P216, v410, Y416, r210, R10k, v308, v408, and Y410.
  5. Optimizations in AviSynth+ v3.7.6

    master

    Version 3.7.6 introduces significant performance improvements across several core filters and architectures:

    SIMD and CPU Acceleration

    • AVX2/AVX512/SSE Support: Added for TurnLeft, TurnRight, Turn180, Invert, Layer, Overlay, Merge, and Subtitle antialiasing.
    • ARM64 (aarch64) NEON: First implementation of NEON optimizations for TurnLeft, TurnRight, Turn180, and Overlay blend.
    • Resamplers: Significant speed gains via AVX512 and optimized SSE/AVX2 paths for 32-bit float and 8-16 bit integer resamplers.

    Filter-Specific Improvements

    • Layer/Overlay/Merge: Unified masked-merge kernels (masked_merge_{c,sse41,avx2,neon}) allow full SIMD throughput for non-444 chroma placements (4:2:0, 4:2:2, 4:1:1).
    • ExtractX (ExtractR/G/B/A/Y/U/V): Now handles packed RGB formats directly, avoiding unnecessary PlanarRGB(A) conversion round-trips.
    • ConvertBits: Restructured integer-to-integer depth reduction for better auto-vectorization.
    • Subtitle Antialiaser: Refactored internal mask buffer to a row-interleaved SoA layout for better chroma-placement-aware UV compositing.
  6. What is AviSynth and how does it work?

    master

    AviSynth is a frameserver that acts as a "middle man" between video files and video applications (like VirtualDub). Instead of producing a standalone output file, you create a text document called a script containing commands that reference video files and filters. When you open this script in a video application, AviSynth processes the video on the fly and feeds the result to the application.

    Key capabilities include:

    • Joining Videos: Combining multiple videos or specific portions of videos.
    • Filtering: Applying built-in or plugin-based filters (resizing, cropping, sharpening, etc.).
    • Handling Large Files: Bypassing the 2 GB file size limit in applications that do not natively support large files.
    • Format Support: Opening unsupported formats by presenting them to the application as standard AVI streams.
    • Disk Space Efficiency: Generating video on the fly, avoiding the need for intermediate temporary files.
  7. What is AviSynth?

    master

    AviSynth is a frameserver that acts as a 'middle man' between video files and video applications (like VirtualDub). Instead of producing output files directly, you create a text-based script (.avs) containing commands that reference video files and filters. When you open this script in a video application, AviSynth processes the video on the fly and feeds the result to the application as if it were a standard AVI file.

    Key capabilities include:

    • Joining Videos: Merging multiple videos or specific portions of videos.
    • Filtering: Applying built-in or plugin-based filters (resizing, cropping, sharpening, etc.).
    • Handling Large Files: Bypassing the 2 GB file size limit in applications that do not natively support large files.
    • Format Support: Opening unsupported formats (like MPEGs or Quicktime MOVs) by presenting them as standard AVI to the host application.
    • Disk Space Efficiency: Generating video on the fly without creating intermediate temporary files.
  8. What is frameserving and why use it?

    master

    Frameserving is the process of directly transferring video data from one program (the frameserver, e.g., AviSynth) to another (the receiver, e.g., an encoder or player) without creating intermediate or temporary files.

    Key Benefits:

    1. Save Disk Space: You can process, resize, or join videos without needing extra storage for large intermediate files.
    2. Increased Compatibility: The receiver sees the input as a standard uncompressed video stream. This allows you to feed highly compressed formats (like MPEG-1) into applications that do not natively support them. It also bypasses file size limits (e.g., a 2 GB limit) because the application only sees the stream one frame at a time.
  9. Target specific colors using hue and saturation ranges

    master

    You can apply Tweak adjustments only to specific colors by defining a range using startHue, endHue, minSat, and maxSat.

    Hue Range

    • If startHue < endHue, the range is [startHue, endHue].
    • If endHue < startHue, the range is [endHue, 360] and [0, startHue] (anti-clockwise).
    • To select a range like [350, 370], use startHue=350 and endHue=10.

    Saturation Range

    • Use minSat and maxSat to target specific saturation levels.
    • A saturation of 100% corresponds to approximately 119 units in chroma.
    • The default range minSat=0, maxSat=150 covers all pixels.
    // Example: Lowering saturation for a specific skin tone (hue 105-138) without affecting background
    Tweak(sat=0.75, startHue=105, endHue=138)
    
    // Example: Selecting by saturation range instead of hue
    Tweak(sat=0.75, maxSat=75, minSat=55)
  10. Breaking Change: 32-bit float YUV chroma centering

    master

    A major change in AviSynth+ affects how 32-bit float YUV formats are handled.

    New Behavior:

    • Zero-based Chroma: In 32-bit float YUV, the U and V chroma planes are now zero-centered. The neutral value (which is 128 in 8-bit) is now 0.0.
    • Impact on Expr: Built-in constants and operators are affected when used in the chroma plane of a 32-bit clip.
      • cmin, cmax return zero-based shifted versions of 16 and 240.
      • range_half results in 0.0 for U and V planes.
      • scaleb results in 0.0 for chroma planes (e.g., 128 scaleb becomes 0.0).
      • range_max is 0.5 for 32-bit float chroma.
      • range_min is a new constant, returning -0.5 for 32-bit float chroma.

    Migration/Workaround:

    • If you use CombinePlane to move a 32-bit float U or V plane to Y, the resulting Y plane will be zero-centered. If your filters expect a 0..1 range, you must convert it using Expr("x 0.5 +").
    • ExtractU and ExtractV will return the unaltered, zero-centered chroma planes.
  11. Manage clips and frames with PClip and PVideoFrame

    master

    Avisynth+ uses smart pointers to manage the lifecycle of clips and video frames, preventing memory leaks and ensuring proper reference counting.

    • PClip: A smart pointer to an IClip. It maintains a reference count and automatically deletes the clip when the last PClip referencing it is destroyed. Always use PClip instead of IClip* to refer to clips.
    • PVideoFrame: A smart pointer to a video frame. It manages the lifecycle of the frame buffer.

    Writability Rules: A buffer is writable if and only if there is exactly one PVideoFrame pointing to it.

    • Frames obtained via env->NewVideoFrame(vi) are guaranteed to be writable.
    • Frames obtained from other clips via GetFrame() may not be writable. Use IsWritable() to check or MakeWritable() to ensure writability before attempting to write to a buffer.
  12. Implement adaptive filtering with ConditionalFilter

    master

    ConditionalFilter can be used to create adaptive filter chains that apply different processing logic based on frame-specific variables (e.g., motion levels).

    To implement an adaptive system, you typically follow this pattern:

    1. Calculate a metric: Use FrameEvaluate to calculate a value (like motion difference) and store it in a global variable.
    2. Define processing branches: Create different functions or clips for different scenarios (e.g., Low_Motion_Filter, High_Motion_Filter).
    3. Apply conditional logic: Use ConditionalFilter to select which branch to use based on the calculated metric.

    Example Workflow (Quantified Motion Filter pattern):

    • Calculate diff using YDifferenceFromPrevious in a FrameEvaluate call.
    • Use FrameEvaluate to map diff to a motion_level (0, 1, or 2).
    • Use ConditionalFilter to pick between low, medium, or high motion processing functions based on **motion_level**.
    # 1. Calculate motion metric
    c = FrameEvaluate(c, "**global diff** = YDifferenceFromPrevious(clip)")
    
    # 2. Map metric to a level
    c = FrameEvaluate(c, "**global motion_level** = (**diff** < 4.0) ? 0 : 1")
    
    # 3. Apply conditional branches
    c = ConditionalFilter(c, Low_Motion_Filter(c), c, "**motion_level**", "=", "0")
    c = ConditionalFilter(c, High_Motion_Filter(c), c, "**motion_level**", "=", "1")