RIFE在Linux下好像并没有什么现成的方案,除了付费的SVP可以使用RIFE简单地实时补帧,现有的教程好像也很少,正好我最近配置好了RIFE,写一篇教程送给还在思考要怎么配置RIFE的各位。内容是根据个人经验所写,如果有什么地方错误,请指正,谢谢。
我使用的是ArchLinux,其他Linux发行版的操作可能有所不同,但应该可以当作参考。
本教程只包含如何在Linux下配置RIFE,更多的其他的内容在本教程并不会看到。如果你想通过快捷键来控制RIFE的开启停止,又或者是修改mpv.conf来提升RIFE的性能,那么请参考其他的教程。
RIFE的后端有很多,选择一个合适的后端应该是很重要的,安装流程的不同也主要是因为安装的后端不同,可以通过下面的命令查看不同的版本,我简述下我对于它们区别的思考。(唯独Intel的OpenVINO好像未在AUR仓库里单独提供?)
paru -S vapoursynth-plugin-mlrt
ncnn-runtime
1、支持Vulkan。
2、观看视频时无须编译。
3、配置最为简单。
ort-runtime-git
1、支持CUDA、TensorRT、ROCm、OpenVINO、DirextML。(AUR目前无OpenVINO和DirextML)
2、后端为CUDA、DirextML时观看视频无须编译。
3、可以使用除Vulkan外几乎所有的后端,但性能不如专用N卡专用的trt-runtime-git和A卡专用的migx-runtime-git。
trt-runtime-git
1、支持TensorRT。(仅限20系及以上N卡)
2、可以提升50%左右的性能。
3、每次观看不同分辨率的视频时必须编译。
migx-runtime-git
1、支持MIGraphX。(仅限5600XT及以上A卡)
2、可以提升50%左右的性能。
3、每次观看不同分辨率的视频时必须编译。
4、仍处于实验性阶段。
如果你的显卡是N卡20系及以上,建议使用trt-runtime-git。
如果你的显卡是A卡5600XT及以上,可以考虑使用migx-runtime-git。(仍处于实验性阶段)
如果你的显卡是I卡A380及以上,可以考虑使用ort-runtime-git,并安装OpenVINO及相关依赖。(但AUR目前无OpenVINO)
由于我本人没有A卡和I卡,故只有ncnn-runtime和trt-runtime-git的教程,ort-runtime-git和migx-runtime-git的安装流程应该和这两个的安装流程差不多,只需要再改几个参数即可,请参考教程自行安装。
ncnn-runtime
1、安装所需软件
安装paru(若未安装)
sudo pacman -S paru
安装MPV(若未安装)
paru -S mpv
安装VS滤镜
paru -S vapoursynth
下载VS插件
paru -S vapoursynth-plugin-mlrt-ncnn-runtime
安装RIFE模型包
paru -S vapoursynth-plugin-mlrt-ext-models-rife
2、编辑配置文件
编辑RIFE的VS滤镜
sudo nano ~/.config/mpv/vs/rife.vpy
输入以下内容
import vapoursynth as vs
from vapoursynth import core
import vsmlrt
clip = video_in
#向上取整:1920*1080>===>1920*1088
w, h = clip.width, clip.height
w = ((w + 63) // 64) * 64
h = ((h + 63) // 64) * 64
#向下取整:1920*1080>===>1920*1024
#w, h = clip.width, clip.height
#w = (w // 64) * 64
#h = (h // 64) * 64
clip = core.resize.Bicubic(
clip,
width=w,
height=h,
format=vs.RGBS,
matrix_in_s="709"
)
clip = vsmlrt.RIFE(
clip,
model=46,
multi=2,
backend=vsmlrt.Backend.NCNN_VK(
device_id=0,
num_streams=1,
fp16=True,
tiles=None,
overlap=None,
)
)
clip = core.resize.Bicubic(clip, format=vs.YUV420P10, matrix_s="709")
clip.set_output()
#模型版本
#补帧倍速
#使用的后端
#使用的显卡序号:0=第一张显卡
#并行流处理数量:1~8
#是否使用fp16加速
#分块的大小:None=自动
#重叠像素的大小:None=自动
#查看模型列表
#python3 -c "import sys;sys.path.append('/usr/lib/vapoursynth');import vsmlrt;[print(f'{m.value:>4} = {m.name}') for m in vsmlrt.RIFEModel]"
#查看后端列表
#python3 -c "import sys; sys.path.append('/usr/lib/vapoursynth'); import vsmlrt; print(*[b for b in dir(vsmlrt.Backend) if not b.startswith('_')], sep='\n')"
编辑mpv.conf
sudo nano ~/.config/mpv/mpv.conf
输入以下内容
vf=vapoursynth="~~/vs/rife.vpy"
correct-pts=yes
hr-seek=yes
hr-seek-framedrop=no
#加载vf滤镜脚本
#是否修正时间戳
#是否开启高精度跳转
#是否在跳转时丢帧
trt-runtime-git
1、安装所需软件
安装paru(若未安装)
sudo pacman -S paru
安装MPV(若未安装)
paru -S mpv
安装TensorRT
paru -S tensorrt
安装VS滤镜
paru -S vapoursynth
下载VS插件
paru -S vapoursynth-plugin-mlrt-trt-runtime-git
安装RIFE模型包
paru -S vapoursynth-plugin-mlrt-ext-models-rife
2、编辑配置文件
编辑RIFE的VS滤镜
sudo nano ~/.config/mpv/vs/rife.vpy
输入以下内容
import vapoursynth as vs
from vapoursynth import core
import vsmlrt
clip = video_in
#向上取整:1920*1080>===>1920*1088
w, h = clip.width, clip.height
w = ((w + 63) // 64) * 64
h = ((h + 63) // 64) * 64
#向下取整:1920*1080>===>1920*1024
#w, h = clip.width, clip.height
#w = (w // 64) * 64
#h = (h // 64) * 64
clip = core.resize.Bicubic(
clip,
width=w,
height=h,
format=vs.RGBS,
matrix_in_s="709"
)
clip = vsmlrt.RIFE(
clip,
model=46,
multi=2,
backend=vsmlrt.Backend.TRT(
device_id=0,
workspace=None,
num_streams=4,
max_aux_streams=2,
fp16=True,
force_fp16=True,
use_cuda_graph=True,
#use_cublas=True,
#use_cudnn=True,
#use_edge_mask_convolutions=True,
#use_jit_convolutions=True,
#static_shape=True,
#heuristic=True,
#short_path=True,
#builder_optimization_level=5,
#tiling_optimization_level=2,
)
)
clip = core.resize.Bicubic(
clip,
format=vs.YUV420P10,
matrix_s="709"
)
clip.set_output()
#模型版本
#补帧倍速
#使用的后端
#使用的显卡序号:0=第一张显卡
#分配显存的大小:None=自动
#显卡线程数:1~8
#最大辅助流数:1~8
#是否使用fp16加速:提升性能但会轻微降低质量
#强制使用fp16精度
#是否使用cuda加速
#是否使用cuBLAS库:优化矩阵运算
#是否使用cuDNN库:优化卷积神经网络
#是否使用边缘掩码卷积:降低性能但减少模糊和重影
#是否使用即时编译卷积:提升性能但会增加编译时间
#是否使用静态形状:提升性能但会增加编译时间
#是否使用启发式算法:TRT自动选择最佳算法
#是否使用短路径优化:减少重复计算
#构建器优化等级:0~5
#平铺优化等级:0~2
#查看模型列表
#python3 -c "import sys;sys.path.append('/usr/lib/vapoursynth');import vsmlrt;[print(f'{m.value:>4} = {m.name}') for m in vsmlrt.RIFEModel]"
#查看后端列表
#python3 -c "import sys; sys.path.append('/usr/lib/vapoursynth'); import vsmlrt; print(*[b for b in dir(vsmlrt.Backend) if not b.startswith('_')], sep='\n')"
编辑mpv.conf
sudo nano ~/.config/mpv/mpv.conf
输入以下内容
vf=vapoursynth="~~/vs/rife.vpy"
correct-pts=yes
hr-seek=yes
hr-seek-framedrop=no
#加载vf滤镜脚本
#是否修正时间戳
#是否开启高精度跳转
#是否在跳转时丢帧


