### Multi-GPU Setup Example Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Demonstrates how to configure RIFE for multi-GPU processing. This is essential for scaling interpolation tasks across multiple graphics cards. ```python from rife.rife import RIFE rife = RIFE(gpu_ids=[0, 1]) ``` -------------------------------- ### Install PyTorch and Torch-TensorRT Source: https://github.com/holywu/vs-rife/blob/master/README.md Installs the latest stable versions of PyTorch and Torch-TensorRT. Ensure you have the correct CUDA version (cu130 in this example). ```bash pip install -U packaging setuptools wheel pip install -U torch torchvision torch_tensorrt --extra-index-url https://download.pytorch.org/whl/cu130 --extra-index-url https://pypi.nvidia.com ``` -------------------------------- ### 5x Interpolation Example Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/advanced-topics.md Shows the output frame timing for 5x interpolation using factor_num=5 and factor_den=1. ```text Output frames 0-4: t = 0.0, 0.2, 0.4, 0.6, 0.8 (five interpolation levels) Output frame 5: t = 0.0 (returns next input frame) ``` -------------------------------- ### 2x Interpolation Example Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/advanced-topics.md Demonstrates the output frame timing for 2x interpolation using factor_num=2 and factor_den=1. ```text Output frame 0: t = 0 / 2 = 0.0 (returns input frame 0) Output frame 1: t = 1 / 2 = 0.5 (interpolated 50% between frames) Output frame 2: t = 0 / 2 = 0.0 (returns input frame 1) Output frame 3: t = 1 / 2 = 0.5 (interpolated 50% between frames) ``` -------------------------------- ### Basic Frame Interpolation Example Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Demonstrates the fundamental usage of RIFE for interpolating frames. This is a starting point for understanding the core functionality. ```python from rife.rife import RIFE rife = RIFE() rife.interpolate_frame("input.png", "output.png") ``` -------------------------------- ### Padding Calculations Example (1080p) Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Illustrates padding calculations for 1080p resolution. This is relevant when dealing with input frames that require specific padding for model processing. ```python from rife.utils import calculate_padding padding = calculate_padding(1920, 1080) ``` -------------------------------- ### Padding Calculations Example (4K) Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Shows padding calculations for 4K resolution. This is important for ensuring compatibility with models that expect specific input dimensions. ```python from rife.utils import calculate_padding padding = calculate_padding(3840, 2160) ``` -------------------------------- ### TensorRT Acceleration Setup Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Demonstrates how to leverage TensorRT for accelerated inference with RIFE. This is crucial for achieving high performance on NVIDIA GPUs. ```python from rife.rife import RIFE rife = RIFE(use_tensorrt=True) ``` -------------------------------- ### Model Selection Example Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Illustrates how to select a specific RIFE model for interpolation. Different models offer trade-offs between speed and quality. ```python from rife.rife import RIFE rife = RIFE(model_name="rife-hd") ``` -------------------------------- ### Multi-GPU Setup Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Explains how to configure and utilize multiple GPUs for frame interpolation using the RIFE API to enhance processing speed. ```APIDOC ## Multi-GPU Setup ### Description This example demonstrates how to configure the RIFE API to utilize multiple GPUs for parallel processing, speeding up frame interpolation. ### Method Not applicable (SDK function call) ### Endpoint Not applicable (SDK function call) ### Parameters - **gpu_ids** (list of int) - Optional - A list of GPU IDs to use for processing. ### Request Example ```python # Assuming a function that accepts a list of GPU IDs interpolated_frames = rife_sdk.interpolate_frames(input_frames, gpu_ids=[0, 1]) ``` ### Response #### Success Response - `interpolated_frames` (list/tensor): The interpolated video frames, processed in parallel across the specified GPUs. #### Response Example ```json { "interpolated_frames": "[parallel processed interpolated frame data]" } ``` ``` -------------------------------- ### Python Model Loading Logic Example Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/models.md Demonstrates conditional model loading based on the 'model' parameter in Python. Requires importing specific IFNet versions. ```python # Example loading logic from rife() match model: case "4.0": from .IFNet_HDv3_v4_0 import IFNet Head = None case "4.25": from .IFNet_HDv3_v4_25 import Head, IFNet encode_channel = 4 modulo = 64 # ... other cases ``` -------------------------------- ### Install vsrife Package Source: https://github.com/holywu/vs-rife/blob/master/README.md Installs the vsrife Python package. This command installs the latest stable version. ```bash pip install -U vsrife ``` -------------------------------- ### Timestep Computation Example Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Demonstrates the computation of timesteps for frame interpolation. This is a core part of determining the intermediate frames. ```python from rife.utils import compute_timestep timestep = compute_timestep(num_frames=5) ``` -------------------------------- ### Rate Validation Example Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Shows an example of rate validation within RIFE. This ensures that specified frame rates or scales are within acceptable limits. ```python from rife.rife import RIFE try: rife = RIFE() rife.interpolate_frame("input.png", "output.png", target_fps=-10) except ValueError as e: print(f"Rate error: {e}") ``` -------------------------------- ### Basic rife() Usage Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/configuration.md Example of using the rife() function with essential parameters like input clip, model, and frame rate factor. ```python import vapoursynth as vs from vsrife import rife core = vs.core # Load your input clip clip = core.ffms2.Source(source='input.mp4') # Interpolate frames by a factor of 2 interpolated_clip = rife(clip, model='4.25', factor_num=2, factor_den=1) ``` -------------------------------- ### Basic Video Interpolation with Scene Detection Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/README.md Demonstrates how to load a video, prepare it for processing, and then interpolate frames using the rife function with scene detection enabled. Requires VapourSynth and vsrife to be installed. ```python import vapoursynth as vs from vsrife import rife # Load and prepare video clip = vs.core.ffms2.Source('input.mp4') clip = vs.core.resize.Bicubic(clip, format=vs.RGBS) # Interpolate to 60 fps with scene detection result = rife( clip, fps_num=60, fps_den=1, sc=True, sc_threshold=0.15 ) result.set_output() ``` -------------------------------- ### Automatic Model Download Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/configuration.md Enable automatic downloading of required models on first use by setting 'auto_download=True'. This simplifies setup for new users. ```python result = rife(clip, model="4.25", auto_download=True) ``` -------------------------------- ### Basic Frame Interpolation Workflow Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/INDEX.md Outlines the steps for basic frame interpolation using vsrife, starting with understanding the project overview and progressing through API reference, configuration, and error handling. ```markdown 1. Start: OVERVIEW.md (understand the project) 2. Read: api-reference/rife.md (basic usage) 3. Reference: configuration.md (parameter tuning) 4. Debug: errors.md (if issues) ``` -------------------------------- ### Basic Error Handling Example Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Shows a basic try-except block for handling potential errors during RIFE operations. This is fundamental for robust application development. ```python from rife.rife import RIFE try: rife = RIFE() rife.interpolate_frame("input.png", "output.png") except Exception as e: print(f"An error occurred: {e}") ``` -------------------------------- ### Format Validation Example Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Illustrates how RIFE performs format validation on input files. This helps prevent errors caused by unsupported image or video formats. ```python from rife.rife import RIFE try: rife = RIFE() rife.interpolate_frame("invalid_format.txt", "output.png") except ValueError as e: print(f"Format error: {e}") ``` -------------------------------- ### Scene Change Detection Example Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Illustrates how RIFE can detect scene changes, allowing for adaptive interpolation strategies. This is important for maintaining quality across different visual contexts. ```python from rife.rife import RIFE rife = RIFE() scene_change = rife.detect_scene_change("frame1.png", "frame2.png") ``` -------------------------------- ### Safe Wrapper Function Example Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Demonstrates the use of a safe wrapper function to encapsulate RIFE operations and handle errors gracefully. This promotes reliable integration into larger applications. ```python from rife.rife import RIFE def safe_interpolate(input_path, output_path): try: rife = RIFE() rife.interpolate_frame(input_path, output_path) return True except Exception as e: print(f"Safe interpolation failed: {e}") return False ``` -------------------------------- ### Scene Change Detection Property Usage Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/advanced-topics.md Example of how to use the '_SceneChangeNext' property during interpolation to conditionally skip interpolation for detected scene change frames. ```python # During interpolation: if sc and f[0].props.get("_SceneChangeNext"): return f[0] # Return original frame without interpolation ``` -------------------------------- ### High-Performance TensorRT Interpolation Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/OVERVIEW.md Use this snippet to enable high-performance interpolation with TensorRT. Ensure TensorRT is correctly installed and configured. ```python result = rife(clip, trt=True, trt_static_shape=True) ``` -------------------------------- ### Handling Errors Workflow Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/INDEX.md Provides a workflow for handling errors in vsrife, guiding users to check the errors.md file, understand trigger conditions, apply suggested resolutions, and consult advanced topics for troubleshooting. ```markdown 1. Check: errors.md (find your error) 2. Understand: Trigger condition and source 3. Fix: Suggested resolution 4. Prevent: Check advanced-topics.md troubleshooting ``` -------------------------------- ### Lightweight 4K Configuration Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Illustrates a configuration for lightweight 4K interpolation. This balances quality with resource usage for high-resolution content. ```python from rife.rife import RIFE rife = RIFE(model_name="rife-4k-light") ``` -------------------------------- ### High Quality with Scene Detection Configuration Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Demonstrates a configuration for high-quality interpolation that also incorporates scene detection. This aims to optimize quality across diverse video content. ```python from rife.rife import RIFE rife = RIFE(model_name="rife-hd", scene_detection=True) ``` -------------------------------- ### Multi-GPU Selection Configuration Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Demonstrates how to explicitly select specific GPUs for RIFE processing. This allows fine-grained control over hardware utilization. ```python from rife.rife import RIFE rife = RIFE(gpu_ids=[0]) ``` -------------------------------- ### Performance Optimization Checklist Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/advanced-topics.md A checklist of recommended settings and configurations for optimizing VSRife performance, including model selection, TensorRT usage, and input processing. ```text ✓ Use appropriate model version (v4.25 default is good) ✓ Match scale parameter to input resolution (0.5 for 4K, 1.0 for HD) ✓ Enable TensorRT (trt=True) for 2-3x speedup ✓ Use static TensorRT shapes (trt_static_shape=True) if resolution fixed ✓ Allocate sufficient workspace_size if using TensorRT ✓ Process clips without scene changes, or enable sc=True ✓ Ensure GPU has sufficient VRAM for model and working memory ✓ Use lightweight models (v4.25.lite) on memory-constrained systems ✓ Process clips sequentially (FrameEval handles ordering) ✓ Pre-download models (avoid auto_download overhead) ``` -------------------------------- ### Basic Error Handling with VapourSynth Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/errors.md Demonstrates how to catch and print VapourSynth errors, including those from the rife plugin, using a standard try-except block. This is useful for debugging and graceful failure. ```python import vapoursynth as vs from vsrife import rife try: clip = vs.core.ffms2.Source('input.mp4') clip = vs.core.resize.Bicubic(clip, format=vs.RGBS) result = rife(clip, model="4.25") result.set_output() except vs.Error as e: print(f"RIFE Error: {e}") # Handle error appropriately ``` -------------------------------- ### Interpolation Configuration (5x) Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Demonstrates how to configure RIFE for 5x interpolation. This allows for significant increases in frame rate. ```python from rife.rife import RIFE rife = RIFE() rife.interpolate_frame("input.png", "output.png", scale=5) ``` -------------------------------- ### File Organization Structure Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/README.md Illustrates the directory structure of the vsrife project, showing the location of README.md and other documentation files. ```tree output/ ├── README.md (this file) ├── INDEX.md (navigation & quick reference) ├── OVERVIEW.md (project overview) ├── configuration.md (parameters & config) ├── errors.md (error reference) ├── models.md (model details) ├── advanced-topics.md (implementation details) └── api-reference/ ├── rife.md (main API function) └── utilities.md (utility functions) ``` -------------------------------- ### Target FPS Configuration (25) Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Demonstrates setting a target FPS of 25 for RIFE interpolation. This is useful for matching broadcast standards. ```python from rife.rife import RIFE rife = RIFE() rife.interpolate_frame("input.png", "output.png", target_fps=25) ``` -------------------------------- ### Manual Model Download (Specific Model) Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/configuration.md Download a specific model file manually using the 'download_model' function. Provide the direct URL to the model's .pkl file. ```python from vsrife import download_model download_model("https://github.com/HolyWu/vs-rife/releases/download/model/flownet_v4.25.pkl") ``` -------------------------------- ### Correcting TRT Shape Dimensions Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/errors.md When using TensorRT (trt=True), ensure that the trt_min_shape dimensions are less than the trt_max_shape dimensions to avoid errors. This example shows the corrected shape configuration. ```python from vsrife import rife result = rife(clip, trt=True, trt_static_shape=False, trt_min_shape=[128, 128], trt_opt_shape=[1920, 1080], trt_max_shape=[2560, 1440]) ``` -------------------------------- ### Target FPS Configuration Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/configuration.md Set a specific target frames per second for the output clip, regardless of the source's original frame rate. Use 'fps_num' and 'fps_den' for precise control. ```python from vsrife import rife # Convert to 60 fps regardless of source fps result = rife(clip, fps_num=60, fps_den=1) # Convert to 25 fps result = rife(clip, fps_num=25, fps_den=1) # Convert to 29.97 fps result = rife(clip, fps_num=30000, fps_den=1001) ``` -------------------------------- ### Frame Doubling Configuration (2x) Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Shows how to configure RIFE for 2x frame doubling. This is a common use case for increasing video smoothness. ```python from rife.rife import RIFE rife = RIFE() rife.interpolate_frame("input.png", "output.png", scale=2) ``` -------------------------------- ### Target FPS Configuration (29.97) Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Shows how to set a target FPS of 29.97 for RIFE interpolation. This is commonly used in NTSC video formats. ```python from rife.rife import RIFE rife = RIFE() rife.interpolate_frame("input.png", "output.png", target_fps=29.97) ``` -------------------------------- ### Triggering CUDA Not Available Error Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/errors.md This snippet illustrates how to trigger a 'CUDA Not Available' error. This occurs when PyTorch cannot detect CUDA devices, typically on systems without a compatible NVIDIA GPU or proper CUDA driver installation. ```python from vsrife import rife # On a system without CUDA or without NVIDIA GPU result = rife(clip) # Raises error if CUDA unavailable ``` -------------------------------- ### State Dict Processing Steps Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/models.md Outlines the key processing steps for loading PyTorch state dictionaries, including prefix removal, Head module key extraction, and device/dtype loading. ```text # State dict keys are processed as follows: 1. Remove "module." prefix (handles DataParallel wrapped models) 2. Extract "encode." keys for Head module 3. Load strict=False to allow missing keys 4. Move to target device and dtype (FP16 or FP32) ``` -------------------------------- ### High Quality with Scene Detection Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/configuration.md Enhance output quality by using a heavier model and enabling scene change detection. Configure the scene change threshold for sensitivity. ```python from vsrife import rife # Use heavy model with scene change avoidance result = rife( clip, model="4.25.heavy", factor_num=2, factor_den=1, sc=True, sc_threshold=0.15 ) ``` -------------------------------- ### Lightweight Processing for 4K Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/configuration.md Optimize processing for high-resolution content like 4K by using a lightweight model and scaling down the resolution. Specify the model and scale factor. ```python from vsrife import rife # Use lightweight model with reduced resolution for 4K result = rife( clip, model="4.25.lite", scale=0.5, factor_num=2, factor_den=1 ) ``` -------------------------------- ### Optimizing for Performance Workflow Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/INDEX.md Details the workflow for optimizing vsrife performance, involving understanding model options, learning about advanced topics like TensorRT and caching, configuring parameters, and benchmarking. ```markdown 1. Understand: models.md (model options) 2. Learn: advanced-topics.md (TensorRT, caching) 3. Configure: configuration.md (parameter settings) 4. Benchmark: advanced-topics.md (troubleshooting) ``` -------------------------------- ### GPU Selection for Multi-GPU Systems Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/configuration.md Specify which GPU to use for processing in a multi-GPU environment. Use 'device_index' to select the desired GPU (0-indexed). ```python from vsrife import rife # Use second GPU result = rife(clip, device_index=1, factor_num=2, factor_den=1) # Use third GPU result = rife(clip, device_index=2, factor_num=2, factor_den=1) ``` -------------------------------- ### Custom Cache Directory Configuration Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Illustrates how to specify a custom directory for caching RIFE models and intermediate data. This is useful for managing storage space. ```python from rife.rife import RIFE rife = RIFE(cache_dir="/path/to/custom/cache") ``` -------------------------------- ### Absolute Frame Rate Interpolation Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/configuration.md Demonstrates setting an absolute target frame rate using fps_num and fps_den, overriding the factor-based settings. ```python import vapoursynth as vs from vsrife import rife core = vs.core clip = core.ffms2.Source(source='input.mp4') # Interpolate to 60 FPS (60/1) interpolated_clip = rife(clip, model='4.25', fps_num=60, fps_den=1) ``` -------------------------------- ### Catching VapourSynth Errors Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/errors.md Illustrates the general approach to catching VapourSynth errors, which include errors from plugins like vsrife. This pattern allows for specific handling of VapourSynth-related issues. ```python import vapoursynth as vs try: # VapourSynth operation pass except vs.Error as e: # Handle VapourSynth errors (including vsrife errors) error_message = str(e) # Extract specific error information if "rife:" in error_message: # This is a vsrife-specific error pass ``` -------------------------------- ### Interpolation Configuration (2.5x) Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Shows how to configure RIFE for 2.5x interpolation. This provides a flexible option for frame rate adjustment. ```python from rife.rife import RIFE rife = RIFE() rife.interpolate_frame("input.png", "output.png", scale=2.5) ``` -------------------------------- ### Download all RIFE models Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/api-reference/utilities.md This script iterates through a predefined list of model names and downloads each one using the `download_model` function. It constructs the full URL for each model from a base URL. ```python from vsrife import download_model models = [ "flownet_v4.0", "flownet_v4.1", "flownet_v4.2", "flownet_v4.3", "flownet_v4.4", "flownet_v4.5", "flownet_v4.6", "flownet_v4.7", "flownet_v4.8", "flownet_v4.9", "flownet_v4.10", "flownet_v4.11", "flownet_v4.12", "flownet_v4.12.lite", "flownet_v4.13", "flownet_v4.13.lite", "flownet_v4.14", "flownet_v4.14.lite", "flownet_v4.15", "flownet_v4.15.lite", "flownet_v4.16.lite", "flownet_v4.17", "flownet_v4.17.lite", "flownet_v4.18", "flownet_v4.19", "flownet_v4.20", "flownet_v4.21", "flownet_v4.22", "flownet_v4.22.lite", "flownet_v4.23", "flownet_v4.24", "flownet_v4.25", "flownet_v4.25.lite", "flownet_v4.25.heavy", "flownet_v4.26", "flownet_v4.26.heavy", ] url_base = "https://github.com/HolyWu/vs-rife/releases/download/model/" for model in models: download_model(url_base + model + ".pkl") ``` -------------------------------- ### TensorRT Compilation Process Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/advanced-topics.md Steps to compile a PyTorch model with TensorRT, including exporting to TorchScript, compiling with specified parameters, and saving the resulting engine to disk. ```python # 1. Export PyTorch model to TorchScript flownet_program = torch.export.export(flownet, flownet_inputs, dynamic_shapes=flownet_dynamic_shapes) # 2. Compile with TensorRT flownet = torch_tensorrt.dynamo.compile( flownet_program, flownet_inputs, device=device, num_avg_timing_iters=4, workspace_size=trt_workspace_size, optimization_level=trt_optimization_level, use_explicit_typing=True, ) # 3. Save engine to disk torch_tensorrt.save(flownet, flownet_engine_path, output_format="torchscript") ``` -------------------------------- ### Model Flow Without Head (v4.0-v4.6) Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/models.md Illustrates the data flow for RIFE models without a Head module, focusing on coarse and progressive flow refinement. ```text Input: img0, img1, timestep, flow_divisor, backwarp_grid ↓ [Block 0] Coarse flow estimation at 16x downscaling ↓ [Block 1] Flow refinement at 8x downscaling ↓ [Block 2] Flow refinement at 4x downscaling ↓ [Block 3] Flow refinement at 2x downscaling ↓ [Block 4] Final refinement at 1x resolution ↓ Output: Interpolated frame (blended using confidence mask) ``` -------------------------------- ### Model Selection with Auto-Download Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/api-reference/rife.md Selects a specific RIFE model (e.g., '4.25.lite') and enables automatic downloading if the model is not found. Ensure the input clip is in RGBS format. ```python import vapoursynth as vs from vsrife import rife clip = vs.core.ffms2.Source('input.mp4') clip = vs.core.resize.Bicubic(clip, format=vs.RGBS) # Use a lighter model with automatic download interpolated = rife( clip, model="4.25.lite", auto_download=True ) clip.set_output() ``` -------------------------------- ### Troubleshooting Slow Inference Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/advanced-topics.md Tips for improving slow inference speeds in VSRife, focusing on enabling TensorRT, using static shapes, and selecting appropriate model variants. ```text - Enable TensorRT (trt=True) - Use static shapes (trt_static_shape=True) - Reduce scale parameter - Use lightweight model variant - Check for other GPU workload ``` -------------------------------- ### Download All Models Source: https://github.com/holywu/vs-rife/blob/master/README.md Downloads all available RIFE models. This is an alternative to the auto-download feature. ```python python -m vsrife ``` -------------------------------- ### TensorRT Engine Generation Configuration Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/models.md Lists the unique configuration parameters that determine the generated TensorRT engine filename. Each unique combination results in a separate cached engine file. ```text Model + Settings → TensorRT Engine ├── Model version ├── Precision (FP16 vs FP32) ├── Scale factor ├── Ensemble flag ├── Input dimensions ├── GPU hardware (device name) ├── TensorRT version └── Workspace size ↓ Unique Engine Filename: model_config_precision_gpu_trt-version.ts (cached in trt_cache_dir) ``` -------------------------------- ### Basic Frame Interpolation Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Demonstrates the fundamental usage of the RIFE API for interpolating frames between existing video frames. ```APIDOC ## Basic Frame Interpolation ### Description This example shows how to perform basic frame interpolation using the RIFE API. ### Method Not applicable (SDK function call) ### Endpoint Not applicable (SDK function call) ### Parameters (Details depend on specific SDK function signatures, not provided in source) ### Request Example ```python # Assuming a function like interpolate_frames exists interpolated_frames = rife_sdk.interpolate_frames(input_frames) ``` ### Response #### Success Response - `interpolated_frames` (list/tensor): The interpolated video frames. #### Response Example ```json { "interpolated_frames": "[frame data]" } ``` ``` -------------------------------- ### Main Dependencies for VSRife Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/advanced-topics.md Lists the primary Python libraries required for VSRife, including PyTorch, VapourSynth, and NumPy. ```python import torch # Deep learning framework import torch.nn as nn # Neural network modules import torch.nn.functional as F # Functional operations (pad, interpolate, grid_sample) import vapoursynth as vs # VapourSynth API import numpy as np # NumPy arrays ``` -------------------------------- ### Converting Clip to RGBS for rife Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/errors.md This snippet provides the resolution for the 'Unsupported Format' error by converting a clip to RGBS format using Bicubic resizing before passing it to the rife function. This ensures compatibility with the expected input formats. ```python import vapoursynth as vs from vsrife import rife clip = vs.core.ffms2.Source('input.mp4') # Convert to RGBS if necessary clip = vs.core.resize.Bicubic(clip, format=vs.RGBS) result = rife(clip) ``` -------------------------------- ### Troubleshooting Artifacts or Distortion Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/advanced-topics.md Guidance on resolving artifacts or distortion issues in VSRife, including using higher quality models, enabling scene change detection, and verifying input format. ```text - Increase model quality (use non-lite variant) - Enable scene change detection (sc=True) - Verify input clip is proper format and range [0,1] - Try different ensemble setting (if supported) ``` -------------------------------- ### Specific Frame Rate Targeting Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Illustrates how to configure the RIFE API to achieve a specific target frames per second (FPS) for the output video. ```APIDOC ## Specific Frame Rate Targeting ### Description This example demonstrates how to target a specific FPS when using the RIFE API for frame interpolation. ### Method Not applicable (SDK function call) ### Endpoint Not applicable (SDK function call) ### Parameters - **target_fps** (float/int) - Required - The desired frames per second for the output video. ### Request Example ```python # Assuming a function with a target_fps parameter interpolated_frames = rife_sdk.interpolate_frames(input_frames, target_fps=60) ``` ### Response #### Success Response - `interpolated_frames` (list/tensor): The interpolated video frames at the target FPS. #### Response Example ```json { "interpolated_frames": "[frame data at 60 FPS]" } ``` ``` -------------------------------- ### Model Management Workflow Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/INDEX.md Describes the workflow for managing models in vsrife, including reading configuration, referencing model characteristics, implementing model downloading, and handling potential errors. ```markdown 1. Read: configuration.md (available models) 2. Reference: models.md (model characteristics) 3. Implement: api-reference/utilities.md (download_model) 4. Verify: errors.md (handle missing models) ``` -------------------------------- ### TensorRT Engine Reloading Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/advanced-topics.md Loads a pre-compiled TensorRT engine from disk for subsequent runs, avoiding the need for recompilation and speeding up startup time. ```python # On subsequent runs with same settings: flownet = torch.jit.load(flownet_engine_path).eval() ``` -------------------------------- ### Ensemble Mode Operation Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/advanced-topics.md Illustrates the concept of ensemble mode in VSRife, where multiple flow estimates are averaged for improved results. This mode is approximately 2x slower. ```python # Model generates multiple flow estimates # Averages predictions for: # - Smoother temporal coherence # - Better handling of occlusion and disocclusion # - Reduced artifacts in ambiguous regions # Cost: ~2x slower inference ``` -------------------------------- ### High-Performance Inference with TensorRT (Static Shapes) Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/api-reference/rife.md Utilizes TensorRT for high-performance inference with static shapes enabled. This configuration is optimal for maximum performance when video resolution is consistent. ```python import vapoursynth as vs from vsrife import rife clip = vs.core.ffms2.Source('input.mp4') clip = vs.core.resize.Bicubic(clip, format=vs.RGBS) # Use TensorRT with static shapes for maximum performance interpolated = rife( clip, trt=True, trt_static_shape=True ) clip.set_output() ``` -------------------------------- ### Convert VapourSynth Frame to PyTorch Tensor Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/api-reference/rife.md Converts a VapourSynth VideoFrame to a PyTorch tensor. Stacks color planes and adds a batch dimension of 1. Uses non-blocking transfer to the target device. ```python def frame_to_tensor(frame: vs.VideoFrame, device: torch.device) -> torch.Tensor: """Internal function to convert a VapourSynth VideoFrame to a PyTorch tensor.""" # Stacks all color planes into a single tensor. tensor = torch.cat([ torch.from_numpy(np.stack([frame[p] for p in range(frame.format.numPlanes)])), ]).float() / 255.0 # Uses non-blocking transfer to device for efficiency. # Adds batch dimension of 1. return tensor.to(device, non_blocking=True).unsqueeze(0) ``` -------------------------------- ### Download a RIFE model Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/api-reference/utilities.md Use this function to download a specific RIFE model file from a given URL. The file is saved to the local models directory. A progress bar is displayed during the download. ```python from vsrife import download_model # Download RIFE model version 4.25 download_model("https://github.com/HolyWu/vs-rife/releases/download/model/flownet_v4.25.pkl") ``` -------------------------------- ### VapourSynth FrameEval Integration Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/OVERVIEW.md Integrate vsrife with VapourSynth using FrameEval for lazy frame processing. This is useful for complex VapourSynth filter chains. ```python result = clip.std.FrameEval(lambda n: ..., clip_src=...) ``` -------------------------------- ### TensorRT Acceleration Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Details how to use TensorRT for accelerating frame interpolation with the RIFE API, focusing on performance gains. ```APIDOC ## TensorRT Acceleration ### Description This example demonstrates how to configure and utilize TensorRT for significant performance acceleration when using the RIFE API. ### Method Not applicable (SDK function call) ### Endpoint Not applicable (SDK function call) ### Parameters - **use_tensorrt** (boolean) - Optional - Enables TensorRT acceleration. - **tensorrt_config** (object) - Optional - Configuration options for TensorRT (e.g., static/dynamic shapes). ### Request Example ```python # Assuming a function with TensorRT configuration options tensorrt_settings = { "static_shapes": True, "max_batch_size": 4 } interpolated_frames = rife_sdk.interpolate_frames(input_frames, use_tensorrt=True, tensorrt_config=tensorrt_settings) ``` ### Response #### Success Response - `interpolated_frames` (list/tensor): The interpolated video frames, processed with TensorRT acceleration. #### Response Example ```json { "interpolated_frames": "[accelerated interpolated frame data]" } ``` ``` -------------------------------- ### Model Flow With Head (v4.7+) Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/models.md Details the data flow for RIFE models with a Head module, including feature encoding and progressive refinement using concatenated inputs. ```text Input: img0, img1, timestep, flow_divisor, backwarp_grid, f0, f1 ↓ [Head] Encode frames to feature vectors (f0, f1) ↓ [Block 0] Coarse flow estimation using concatenated image and feature inputs ↓ [Block 1-4] Progressive refinement with feature warping ↓ Output: Interpolated frame ``` -------------------------------- ### Scene-Aware Interpolation Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/OVERVIEW.md Enable scene-aware interpolation to improve results in scenes with significant motion. Adjust the threshold based on scene complexity. ```python result = rife(clip, sc=True, sc_threshold=0.15) ``` -------------------------------- ### Target Specific Frame Rate Interpolation Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Shows how to configure RIFE to achieve a specific target frame rate during interpolation. Useful for matching desired playback speeds. ```python from rife.rife import RIFE rife = RIFE() rife.interpolate_frame("input.png", "output.png", target_fps=60) ``` -------------------------------- ### Frame and Encode Cache Structures Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/advanced-topics.md Initializes dictionaries to store cached frames and encoded features, keyed by frame number. This supports efficient reuse of previously processed data. ```python frame_cache = {} encode_cache = {} ``` -------------------------------- ### TensorRT Static Shapes Configuration Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Shows how to configure RIFE to use static shapes with TensorRT. This can improve performance when input dimensions are fixed. ```python from rife.rife import RIFE rife = RIFE(use_tensorrt=True, dynamic_shape=False) ``` -------------------------------- ### Dynamic Shape Engine with TensorRT Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/GENERATION_SUMMARY.txt Shows how to configure RIFE to use a dynamic shape engine with TensorRT, allowing for more flexible input resolutions. This is useful when dealing with varying input sizes. ```python from rife.rife import RIFE rife = RIFE(use_tensorrt=True, dynamic_shape=True) ``` -------------------------------- ### Cache Lookup for Frame Retrieval Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/advanced-topics.md Checks if a frame is already present in the frame cache. If found, it retrieves the cached frame; otherwise, it proceeds to load and convert the frame from disk. ```python if real_n in frame_cache: img0 = frame_cache[real_n] else: img0 = frame_to_tensor(f[0], device) ``` -------------------------------- ### IFNet Class Definition Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/models.md The main class for the Intermediate Flow Network. It initializes network blocks and parameters, and its forward method estimates optical flow, warps frames, and blends them to produce an interpolated frame. ```python class IFNet(nn.Module): def __init__(self, scale=1, ensemble=False): # Initialize network blocks and parameters pass def forward(self, img0, img1, timestep, tenFlow_div, backwarp_tenGrid, ...): # Estimate bidirectional optical flow # Warp frames using estimated flow # Blend warped frames using confidence masks # Return interpolated frame pass ``` -------------------------------- ### Cache Eviction for Memory Management Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/advanced-topics.md Implements a cache eviction strategy to remove older frames and encoded features, maintaining a sliding window of approximately 10 items. This balances memory usage with data reuse. ```python cache_to_delete = real_n - 10 if cache_to_delete >= 0: if cache_to_delete in frame_cache: del frame_cache[cache_to_delete] if cache_to_delete in encode_cache: del encode_cache[cache_to_delete] ``` -------------------------------- ### Model Quality Progression Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/models.md Visualizes the incremental quality improvements across RIFE model versions from v4.0 to v4.26. ```text v4.0 ├─→ v4.1 ├─→ v4.2-v4.6 ├─→ v4.7-v4.12 ├─→ v4.13-v4.24 ├─→ v4.25 → v4.26 │ │ │ │ │ └─────────┴──────────────┴──────────────┴──────────────┘ Incremental Quality Improvements ``` -------------------------------- ### Basic Frame Doubling Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/OVERVIEW.md Perform basic frame interpolation to double the frame rate of a video clip. Ensure the input clip is in RGBS format. ```python from vsrife import rife import vapoursynth as vs clip = vs.core.ffms2.Source('video.mp4') clip = vs.core.resize.Bicubic(clip, format=vs.RGBS) result = rife(clip) ``` -------------------------------- ### download_model Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/api-reference/utilities.md Downloads a RIFE model file from a remote URL and saves it to the local models directory. The filename is automatically extracted from the URL. ```APIDOC ## Function: download_model ### Description Download a RIFE model file from a remote URL and save it to the local models directory. ### Signature ```python def download_model(url: str) -> None ``` ### Parameters | Parameter | Type | Default | Required | Description | |-----------|------|---------|----------|-------------| | url | `str` | — | Yes | Full URL to the model file to download. The filename is extracted from the URL's last path segment. Example: "https://github.com/HolyWu/vs-rife/releases/download/model/flownet_v4.25.pkl" | ### Return Type `None` — Downloads the file and saves it to the local models directory. ### Usage Example ```python from vsrife import download_model # Download RIFE model version 4.25 download_model("https://github.com/HolyWu/vs-rife/releases/download/model/flownet_v4.25.pkl") ``` ### Notes - Files are saved to the `models` directory within the vsrife package installation directory. - Filename is automatically extracted from the URL's last path component. - Displays a progress bar using `tqdm` during download. - Progress bar shows: file size, download rate, and time elapsed. - Uses `requests.get()` with streaming enabled for memory-efficient downloads. - The recommended way to download all models is to run `python -m vsrife` directly. - Models are typically 10-100+ MB depending on the version. ``` -------------------------------- ### Target Specific FPS Source: https://github.com/holywu/vs-rife/blob/master/_autodocs/OVERVIEW.md Interpolate frames to achieve a target frames per second (FPS). Specify the desired FPS using fps_num and fps_den. ```python result = rife(clip, fps_num=60, fps_den=1) ```